Skip to content

Commit

Permalink
fix(color): 'SWITCH' widget option logic, enable for Lua widgets (Edg…
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored and MRC3742 committed Dec 22, 2023
1 parent 61f8850 commit ba50b74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
11 changes: 5 additions & 6 deletions radio/src/gui/colorlcd/widget_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions radio/src/lua/api_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,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
Expand Down
13 changes: 9 additions & 4 deletions radio/src/lua/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit ba50b74

Please sign in to comment.