From 0ac2a814a1c676e71ab606ed0d59cdc57f9ac941 Mon Sep 17 00:00:00 2001 From: 3djc Date: Mon, 5 Apr 2021 09:02:36 +0200 Subject: [PATCH] Cosmetcis + add colorchoice --- radio/src/gui/colorlcd/widget_settings.cpp | 175 +++++++++++---------- 1 file changed, 91 insertions(+), 84 deletions(-) diff --git a/radio/src/gui/colorlcd/widget_settings.cpp b/radio/src/gui/colorlcd/widget_settings.cpp index 6659fe915..caf862712 100644 --- a/radio/src/gui/colorlcd/widget_settings.cpp +++ b/radio/src/gui/colorlcd/widget_settings.cpp @@ -22,108 +22,115 @@ #include "widget_settings.h" static const rect_t widgetSettingsDialogRect = { - LCD_W / 10, // x - LCD_H / 4, // y - LCD_W - 2 * LCD_W / 10, // width - LCD_H - 2 * LCD_H / 4 // height + LCD_W / 10, // x + LCD_H / 4, // y + LCD_W - 2 * LCD_W / 10, // width + LCD_H - 2 * LCD_H / 4 // height }; WidgetSettings::WidgetSettings(Window * parent, Widget * widget, std::function confirmHandler) : - Dialog(parent, TR_WIDGET_SETTINGS, widgetSettingsDialogRect), - confirmHandler(std::move(confirmHandler)) + Dialog(parent, TR_WIDGET_SETTINGS, widgetSettingsDialogRect), + confirmHandler(std::move(confirmHandler)) { - auto form = &content->form; - FormGridLayout grid(content->form.width()); - form->clear(); + auto form = &content->form; + FormGridLayout grid(content->form.width()); + grid.setLabelWidth(width() / 5); + form->clear(); - uint8_t optIdx = 0; - auto optPtr = widget->getOptions(); + uint8_t optIdx = 0; + auto optPtr = widget->getOptions(); - while (optPtr->name != nullptr) { + while (optPtr->name != nullptr) { - auto option = *optPtr; - new StaticText(form, grid.getLabelSlot(), option.name); + auto option = *optPtr; + new StaticText(form, grid.getLabelSlot(), option.name); - switch (option.type) { + switch (option.type) { - case ZoneOption::Integer: - new NumberEdit(form, grid.getFieldSlot(), - option.min.signedValue, // Minimum - option.max.signedValue, // Maximum - [=]() -> int { // getValue - return widget->getOptionValue(optIdx)->signedValue; - }, - [=](int32_t newValue) { // setValue - widget->setOptionValue(optIdx, OPTION_VALUE_SIGNED(newValue)); - }); - break; + case ZoneOption::Integer: + new NumberEdit(form, grid.getFieldSlot(), + option.min.signedValue, // Minimum + option.max.signedValue, // Maximum + [=]() -> int { // getValue + return widget->getOptionValue(optIdx)->signedValue; + }, + [=](int32_t newValue) { // setValue + widget->setOptionValue(optIdx, OPTION_VALUE_SIGNED(newValue)); + }); + break; - case ZoneOption::Source: - new SourceChoice(form, grid.getFieldSlot(), - option.min.unsignedValue, // min - option.max.unsignedValue, // max - [=]() -> int16_t { // getValue - return (int16_t)widget->getOptionValue(optIdx)->unsignedValue; - }, - [=](int16_t newValue) { // setValue - widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t)newValue)); - }); - break; - - case ZoneOption::Bool: - new CheckBox(form, grid.getFieldSlot(), - [=]() -> uint8_t { // getValue - return (uint8_t)widget->getOptionValue(optIdx)->boolValue; + case ZoneOption::Source: + new SourceChoice(form, grid.getFieldSlot(), + option.min.unsignedValue, // min + option.max.unsignedValue, // max + [=]() -> int16_t { // getValue + return (int16_t) widget->getOptionValue(optIdx)->unsignedValue; }, - [=](int8_t newValue) { // setValue - widget->setOptionValue(optIdx, OPTION_VALUE_BOOL((uint32_t)newValue)); + [=](int16_t newValue) { // setValue + widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t) newValue)); }); - break; + break; - case ZoneOption::String: - break; + case ZoneOption::Bool: + new CheckBox(form, grid.getFieldSlot(), + [=]() -> uint8_t { // getValue + return (uint8_t) widget->getOptionValue(optIdx)->boolValue; + }, + [=](int8_t newValue) { // setValue + widget->setOptionValue(optIdx, OPTION_VALUE_BOOL((uint32_t) newValue)); + }); + break; - case ZoneOption::File: - break; + case ZoneOption::String: + break; - case ZoneOption::TextSize: - break; + case ZoneOption::File: + break; - case ZoneOption::Timer: // Unsigned - { - auto tmChoice = new Choice(form, grid.getFieldSlot(), - 0, TIMERS - 1, - [=]() -> int { // getValue - return (int)widget->getOptionValue(optIdx)->unsignedValue; - }, - [=](int newValue) { // setValue - widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t)newValue)); - }); + case ZoneOption::TextSize: + break; - tmChoice->setTextHandler([](int value) { - return std::string(STR_TIMER) + std::to_string(value + 1); - }); - } - break; + case ZoneOption::Timer: // Unsigned + { + auto tmChoice = new Choice(form, grid.getFieldSlot(), + 0, TIMERS - 1, + [=]() -> int { // getValue + return (int) widget->getOptionValue(optIdx)->unsignedValue; + }, + [=](int newValue) { // setValue + widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t) newValue)); + }); - case ZoneOption::Switch: - new SwitchChoice(form, grid.getFieldSlot(), - option.min.unsignedValue, // min - option.max.unsignedValue, // max - [=]() -> int16_t { // getValue - return (uint8_t)widget->getOptionValue(optIdx)->unsignedValue; - }, - [=](int16_t newValue) { // setValue - widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t)newValue)); - }); - break; + tmChoice->setTextHandler([](int value) { + return std::string(STR_TIMER) + std::to_string(value + 1); + }); + } + break; - case ZoneOption::Color: - break; - } + case ZoneOption::Switch: + new SwitchChoice(form, grid.getFieldSlot(), + option.min.unsignedValue, // min + option.max.unsignedValue, // max + [=]() -> int16_t { // getValue + return (uint8_t) widget->getOptionValue(optIdx)->unsignedValue; + }, + [=](int16_t newValue) { // setValue + widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t) newValue)); + }); + break; - optIdx++; - optPtr++; - grid.nextLine(); - } + case ZoneOption::Color: + new ColorEdit(form, grid.getFieldSlot(), [=]() -> int { // getValue + return (int) widget->getOptionValue(optIdx)->unsignedValue; + }, + [=](int newValue) { // setValue + widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t) newValue)); + }); + break; + } + + optIdx++; + optPtr++; + grid.nextLine(); + } }