fix(color): 'SWITCH' widget option logic, enable for Lua widgets (#4190)
This commit is contained in:
@@ -154,14 +154,13 @@ WidgetSettings::WidgetSettings(Window* parent, Widget* widget) :
|
|||||||
case ZoneOption::Switch:
|
case ZoneOption::Switch:
|
||||||
new SwitchChoice(
|
new SwitchChoice(
|
||||||
line, rect_t{},
|
line, rect_t{},
|
||||||
option.min.unsignedValue, // min
|
option.min.signedValue, // min
|
||||||
option.max.unsignedValue, // max
|
option.max.signedValue, // max
|
||||||
[=]() -> int16_t { // getValue
|
[=]() -> int16_t { // getValue
|
||||||
return (uint8_t)widget->getOptionValue(optIdx)->unsignedValue;
|
return widget->getOptionValue(optIdx)->signedValue;
|
||||||
},
|
},
|
||||||
[=](int16_t newValue) { // setValue
|
[=](int16_t newValue) { // setValue
|
||||||
widget->getOptionValue(optIdx)->unsignedValue =
|
widget->getOptionValue(optIdx)->signedValue = newValue;
|
||||||
(uint32_t)newValue;
|
|
||||||
SET_DIRTY();
|
SET_DIRTY();
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -3085,6 +3085,7 @@ LROT_BEGIN(etxcst, NULL, 0)
|
|||||||
LROT_NUMENTRY( TIMER, ZoneOption::Timer )
|
LROT_NUMENTRY( TIMER, ZoneOption::Timer )
|
||||||
LROT_NUMENTRY( TEXT_SIZE, ZoneOption::TextSize )
|
LROT_NUMENTRY( TEXT_SIZE, ZoneOption::TextSize )
|
||||||
LROT_NUMENTRY( ALIGNMENT, ZoneOption::Align )
|
LROT_NUMENTRY( ALIGNMENT, ZoneOption::Align )
|
||||||
|
LROT_NUMENTRY( SWITCH, ZoneOption::Switch )
|
||||||
LROT_NUMENTRY( MENU_HEADER_HEIGHT, COLOR2FLAGS(MENU_HEADER_HEIGHT) )
|
LROT_NUMENTRY( MENU_HEADER_HEIGHT, COLOR2FLAGS(MENU_HEADER_HEIGHT) )
|
||||||
|
|
||||||
// Colors gui/colorlcd/colors.h
|
// Colors gui/colorlcd/colors.h
|
||||||
|
|||||||
@@ -149,15 +149,20 @@ ZoneOption *createOptionsArray(int reference, uint8_t maxOptions)
|
|||||||
option->type = ZoneOption::Integer;
|
option->type = ZoneOption::Integer;
|
||||||
}
|
}
|
||||||
if (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->deflt.signedValue = 0;
|
||||||
option->min.signedValue = -100;
|
option->min.signedValue = -100;
|
||||||
option->max.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;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
luaL_checktype(lsWidgets, -2, LUA_TNUMBER); // key is number
|
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
|
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||||
option->deflt.signedValue = lua_tointeger(lsWidgets, -1);
|
option->deflt.signedValue = lua_tointeger(lsWidgets, -1);
|
||||||
// TRACE("default signed = %d", option->deflt.signedValue);
|
// TRACE("default signed = %d", option->deflt.signedValue);
|
||||||
@@ -183,14 +188,14 @@ ZoneOption *createOptionsArray(int reference, uint8_t maxOptions)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
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, -2, LUA_TNUMBER); // key is number
|
||||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||||
option->min.signedValue = lua_tointeger(lsWidgets, -1);
|
option->min.signedValue = lua_tointeger(lsWidgets, -1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
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, -2, LUA_TNUMBER); // key is number
|
||||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||||
option->max.signedValue = lua_tointeger(lsWidgets, -1);
|
option->max.signedValue = lua_tointeger(lsWidgets, -1);
|
||||||
|
|||||||
Reference in New Issue
Block a user