feat(color): add 'menu' popup control to Lua API (#6212)
This commit is contained in:
@@ -369,6 +369,7 @@ LROT_BEGIN(lvgllib, NULL, 0)
|
|||||||
// Dialogs
|
// Dialogs
|
||||||
LROT_FUNCENTRY(confirm, [](lua_State* L) { return luaLvglPopup(L, []() { return new LvglWidgetConfirmDialog(); }); })
|
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(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
|
// Object manipulation functions
|
||||||
LROT_FUNCENTRY(set, luaLvglSet)
|
LROT_FUNCENTRY(set, luaLvglSet)
|
||||||
LROT_FUNCENTRY(show, luaLvglShow)
|
LROT_FUNCENTRY(show, luaLvglShow)
|
||||||
|
|||||||
@@ -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)
|
void LvglWidgetFontPicker::build(lua_State *L)
|
||||||
{
|
{
|
||||||
if (h == LV_SIZE_CONTENT) h = 0;
|
if (h == LV_SIZE_CONTENT) h = 0;
|
||||||
|
|||||||
@@ -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
|
class LvglWidgetFontPicker : public LvglWidgetPicker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user