}
QAction *action = menu->addAction(QString::fromStdString(entry->text));
+ if (entry->entry.flags == Theme::MenuEntry::CHECKABLE) {
+ action->setCheckable(true);
+ } else if (entry->entry.flags == Theme::MenuEntry::CHECKED) {
+ action->setCheckable(true);
+ action->setChecked(true);
+ }
connect(action, &QAction::triggered, [lua_ref = entry->entry.lua_ref] {
global_mixer->theme_menu_entry_clicked(lua_ref);
});
const vector<pair<string, int>> num_constants = {
{ "VIDEO_FORMAT_BGRA", bmusb::PixelFormat_8BitBGRA },
{ "VIDEO_FORMAT_YCBCR", bmusb::PixelFormat_8BitYCbCrPlanar },
+ { "CHECKABLE", MenuEntry::CHECKABLE },
+ { "CHECKED", MenuEntry::CHECKED },
};
const vector<pair<string, string>> str_constants = {
{ "THEME_PATH", theme_path },
const string text = checkstdstring(L, -1);
lua_pop(L, 1);
+ unsigned flags = 0;
+ if (lua_objlen(L, -1) > 2) {
+ lua_rawgeti(L, -1, 3);
+ flags = luaL_checknumber(L, -1);
+ lua_pop(L, 1);
+ }
+
lua_rawgeti(L, index, 2);
if (lua_istable(L, -1)) {
vector<unique_ptr<Theme::MenuEntry>> submenu = create_recursive_theme_menu(L);
} else {
luaL_checktype(L, -1, LUA_TFUNCTION);
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
- entry.reset(new Theme::MenuEntry{ text, L, ref });
+ entry.reset(new Theme::MenuEntry{ text, L, ref, flags });
}
return entry;
}
#endif
struct MenuEntry {
- MenuEntry(const std::string &text, lua_State *L, int lua_ref)
- : text(text), is_submenu(false), entry{L, lua_ref} {}
+ MenuEntry(const std::string &text, lua_State *L, int lua_ref, unsigned flags)
+ : text(text), is_submenu(false), entry{L, lua_ref, flags} {}
MenuEntry(const std::string &text, std::vector<std::unique_ptr<MenuEntry>> submenu)
: text(text), is_submenu(true), submenu(std::move(submenu)) {}
~MenuEntry();
+ static constexpr unsigned CHECKABLE = 1;
+ static constexpr unsigned CHECKED = 2;
+
std::string text;
bool is_submenu;
struct {
lua_State *L;
int lua_ref;
+ unsigned flags;
} entry;
// is_submenu = true.