From 1e3f919146411f6b622d342ad965733757293978 Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 17 Oct 2023 08:22:25 +1100 Subject: [PATCH] fix(color): 'SWITCH' widget option logic, enable for Lua widgets (#4190) --- radio/src/gui/colorlcd/widget_settings.cpp | 11 +++++------ radio/src/lua/api_general.cpp | 1 + radio/src/lua/widgets.cpp | 13 +++++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/radio/src/gui/colorlcd/widget_settings.cpp b/radio/src/gui/colorlcd/widget_settings.cpp index d2fbdca28..22d4234da 100644 --- a/radio/src/gui/colorlcd/widget_settings.cpp +++ b/radio/src/gui/colorlcd/widget_settings.cpp @@ -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; diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index c6b72a5a5..83cec454c 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -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 diff --git a/radio/src/lua/widgets.cpp b/radio/src/lua/widgets.cpp index 0a773a570..c5b9eb3f5 100644 --- a/radio/src/lua/widgets.cpp +++ b/radio/src/lua/widgets.cpp @@ -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);