fix(color): 'SWITCH' widget option logic, enable for Lua widgets (#4190)

This commit is contained in:
philmoz
2023-10-17 07:22:25 +10:00
committed by GitHub
parent 4128b762dd
commit 1e3f919146
3 changed files with 15 additions and 10 deletions
+5 -6
View File
@@ -154,14 +154,13 @@ WidgetSettings::WidgetSettings(Window* parent, Widget* widget) :
case ZoneOption::Switch:
new SwitchChoice(
line, rect_t{},
option.min.unsignedValue, // min
option.max.unsignedValue, // max
[=]() -> int16_t { // getValue
return (uint8_t)widget->getOptionValue(optIdx)->unsignedValue;
option.min.signedValue, // min
option.max.signedValue, // max
[=]() -> int16_t { // getValue
return widget->getOptionValue(optIdx)->signedValue;
},
[=](int16_t newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
widget->getOptionValue(optIdx)->signedValue = newValue;
SET_DIRTY();
});
break;
+1
View File
@@ -3085,6 +3085,7 @@ LROT_BEGIN(etxcst, NULL, 0)
LROT_NUMENTRY( TIMER, ZoneOption::Timer )
LROT_NUMENTRY( TEXT_SIZE, ZoneOption::TextSize )
LROT_NUMENTRY( ALIGNMENT, ZoneOption::Align )
LROT_NUMENTRY( SWITCH, ZoneOption::Switch )
LROT_NUMENTRY( MENU_HEADER_HEIGHT, COLOR2FLAGS(MENU_HEADER_HEIGHT) )
// Colors gui/colorlcd/colors.h
+9 -4
View File
@@ -149,15 +149,20 @@ ZoneOption *createOptionsArray(int reference, uint8_t maxOptions)
option->type = ZoneOption::Integer;
}
if (option->type == ZoneOption::Integer) {
// set some sensible defaults (only Integer actually uses them)
// set some sensible defaults
option->deflt.signedValue = 0;
option->min.signedValue = -100;
option->max.signedValue = 100;
} else if (option->type == ZoneOption::Switch) {
// set some sensible defaults
option->deflt.signedValue = SWSRC_NONE;
option->min.signedValue = SWSRC_FIRST;
option->max.signedValue = SWSRC_LAST;
}
break;
case 2:
luaL_checktype(lsWidgets, -2, LUA_TNUMBER); // key is number
if (option->type == ZoneOption::Integer) {
if (option->type == ZoneOption::Integer || option->type == ZoneOption::Switch) {
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
option->deflt.signedValue = lua_tointeger(lsWidgets, -1);
// TRACE("default signed = %d", option->deflt.signedValue);
@@ -183,14 +188,14 @@ ZoneOption *createOptionsArray(int reference, uint8_t maxOptions)
}
break;
case 3:
if (option->type == ZoneOption::Integer) {
if (option->type == ZoneOption::Integer || option->type == ZoneOption::Switch) {
luaL_checktype(lsWidgets, -2, LUA_TNUMBER); // key is number
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
option->min.signedValue = lua_tointeger(lsWidgets, -1);
}
break;
case 4:
if (option->type == ZoneOption::Integer) {
if (option->type == ZoneOption::Integer || option->type == ZoneOption::Switch) {
luaL_checktype(lsWidgets, -2, LUA_TNUMBER); // key is number
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
option->max.signedValue = lua_tointeger(lsWidgets, -1);