feat(color): add 'menu' popup control to Lua API (#6212)

This commit is contained in:
philmoz
2025-05-07 11:45:38 +10:00
committed by GitHub
parent 8f36592936
commit 609110a257
3 changed files with 51 additions and 0 deletions
+1
View File
@@ -369,6 +369,7 @@ LROT_BEGIN(lvgllib, NULL, 0)
// Dialogs
LROT_FUNCENTRY(confirm, [](lua_State* L) { return luaLvglPopup(L, []() { return new LvglWidgetConfirmDialog(); }); })
LROT_FUNCENTRY(message, [](lua_State* L) { return luaLvglPopup(L, []() { return new LvglWidgetMessageDialog(); }); })
LROT_FUNCENTRY(menu, [](lua_State* L) { return luaLvglPopup(L, []() { return new LvglWidgetMenu(); }); })
// Object manipulation functions
LROT_FUNCENTRY(set, luaLvglSet)
LROT_FUNCENTRY(show, luaLvglShow)
+35
View File
@@ -2174,6 +2174,41 @@ void LvglWidgetChoice::build(lua_State *L)
//-----------------------------------------------------------------------------
void LvglWidgetMenu::parseParam(lua_State *L, const char *key)
{
if (!strcmp(key, "title")) {
title = luaL_checkstring(L, -1);
} else if (!strcmp(key, "values")) {
luaL_checktype(L, -1, LUA_TTABLE);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
values.push_back(lua_tostring(L, -1));
}
} else {
LvglWidgetPicker::parseParam(L, key);
}
}
void LvglWidgetMenu::build(lua_State *L)
{
auto menu = new Menu();
if (!title.empty()) menu->setTitle(title);
for (int i = 0; i < values.size(); i += 1) {
menu->addLine(values[i], [=]() {
pcallSetIntVal(L, setFunction, i + 1);
});
}
int selected = pcallGetIntVal(L, getFunction) - 1;
if (selected >= 0) {
menu->select(selected);
}
window = menu;
}
//-----------------------------------------------------------------------------
void LvglWidgetFontPicker::build(lua_State *L)
{
if (h == LV_SIZE_CONTENT) h = 0;
+15
View File
@@ -774,6 +774,21 @@ class LvglWidgetChoice : public LvglWidgetPicker
//-----------------------------------------------------------------------------
class LvglWidgetMenu : public LvglWidgetPicker
{
public:
LvglWidgetMenu() : LvglWidgetPicker() {}
protected:
std::string title;
std::vector<std::string> values;
void build(lua_State *L) override;
void parseParam(lua_State *L, const char *key) override;
};
//-----------------------------------------------------------------------------
class LvglWidgetFontPicker : public LvglWidgetPicker
{
public: