feat(color): add Slider & Choice widget option types (#5518)
This commit is contained in:
@@ -219,9 +219,9 @@ void LuaWidget::redraw_cb(lv_event_t* e)
|
||||
|
||||
LuaWidget::LuaWidget(const WidgetFactory* factory, Window* parent,
|
||||
const rect_t& rect, WidgetPersistentData* persistentData,
|
||||
int luaWidgetDataRef, int zoneRectDataRef) :
|
||||
int luaWidgetDataRef, int zoneRectDataRef, int optionsDataRef) :
|
||||
Widget(factory, parent, rect, persistentData),
|
||||
zoneRectDataRef(zoneRectDataRef),
|
||||
zoneRectDataRef(zoneRectDataRef), optionsDataRef(optionsDataRef),
|
||||
errorMessage(nullptr)
|
||||
{
|
||||
this->luaWidgetDataRef = luaWidgetDataRef;
|
||||
@@ -304,13 +304,6 @@ void LuaWidget::checkEvents()
|
||||
#endif
|
||||
}
|
||||
|
||||
static void l_pushtableint(const char* key, int value)
|
||||
{
|
||||
lua_pushstring(lsWidgets, key);
|
||||
lua_pushinteger(lsWidgets, value);
|
||||
lua_settable(lsWidgets, -3);
|
||||
}
|
||||
|
||||
void LuaWidget::update()
|
||||
{
|
||||
Widget::update();
|
||||
@@ -321,24 +314,28 @@ void LuaWidget::update()
|
||||
lua_rawgeti(lsWidgets, LUA_REGISTRYINDEX, luaFactory()->updateFunction);
|
||||
lua_rawgeti(lsWidgets, LUA_REGISTRYINDEX, luaWidgetDataRef);
|
||||
|
||||
lua_newtable(lsWidgets);
|
||||
// Get options table and update values
|
||||
lua_rawgeti(lsWidgets, LUA_REGISTRYINDEX, optionsDataRef);
|
||||
int i = 0;
|
||||
for (const ZoneOption* option = getOptions(); option->name; option++, i++) {
|
||||
if (option->type == ZoneOption::String) {
|
||||
lua_pushstring(lsWidgets, option->name);
|
||||
char str[LEN_ZONE_OPTION_STRING + 1] = {
|
||||
0}; // Zero-terminated string for Lua
|
||||
strncpy(str, persistentData->options[i].value.stringValue,
|
||||
LEN_ZONE_OPTION_STRING);
|
||||
lua_pushstring(lsWidgets, &str[0]);
|
||||
lua_settable(lsWidgets, -3);
|
||||
} else if (option->type == ZoneOption::Color) {
|
||||
int32_t value = persistentData->options[i].value.unsignedValue;
|
||||
l_pushtableint(option->name, value);
|
||||
} else {
|
||||
int32_t value = persistentData->options[i].value.signedValue;
|
||||
l_pushtableint(option->name, value);
|
||||
auto optVal = getOptionValue(i);
|
||||
switch (option->type) {
|
||||
case ZoneOption::String:
|
||||
{
|
||||
char str[LEN_ZONE_OPTION_STRING + 1] = {0};
|
||||
strncpy(str, optVal->stringValue, LEN_ZONE_OPTION_STRING);
|
||||
lua_pushstring(lsWidgets, str);
|
||||
}
|
||||
break;
|
||||
case ZoneOption::Integer:
|
||||
case ZoneOption::Switch:
|
||||
lua_pushinteger(lsWidgets, optVal->signedValue);
|
||||
break;
|
||||
default:
|
||||
lua_pushinteger(lsWidgets, optVal->unsignedValue);
|
||||
break;
|
||||
}
|
||||
lua_setfield(lsWidgets, -2, option->name);
|
||||
}
|
||||
|
||||
if (useLvglLayout()) luaLvglManager = this;
|
||||
|
||||
Reference in New Issue
Block a user