Cosmetcis + add colorchoice

This commit is contained in:
3djc
2021-04-05 09:02:36 +02:00
parent 8ccf3c0437
commit 0ac2a814a1
+91 -84
View File
@@ -22,108 +22,115 @@
#include "widget_settings.h" #include "widget_settings.h"
static const rect_t widgetSettingsDialogRect = { static const rect_t widgetSettingsDialogRect = {
LCD_W / 10, // x LCD_W / 10, // x
LCD_H / 4, // y LCD_H / 4, // y
LCD_W - 2 * LCD_W / 10, // width LCD_W - 2 * LCD_W / 10, // width
LCD_H - 2 * LCD_H / 4 // height LCD_H - 2 * LCD_H / 4 // height
}; };
WidgetSettings::WidgetSettings(Window * parent, Widget * widget, std::function<void(void)> confirmHandler) : WidgetSettings::WidgetSettings(Window * parent, Widget * widget, std::function<void(void)> confirmHandler) :
Dialog(parent, TR_WIDGET_SETTINGS, widgetSettingsDialogRect), Dialog(parent, TR_WIDGET_SETTINGS, widgetSettingsDialogRect),
confirmHandler(std::move(confirmHandler)) confirmHandler(std::move(confirmHandler))
{ {
auto form = &content->form; auto form = &content->form;
FormGridLayout grid(content->form.width()); FormGridLayout grid(content->form.width());
form->clear(); grid.setLabelWidth(width() / 5);
form->clear();
uint8_t optIdx = 0; uint8_t optIdx = 0;
auto optPtr = widget->getOptions(); auto optPtr = widget->getOptions();
while (optPtr->name != nullptr) { while (optPtr->name != nullptr) {
auto option = *optPtr; auto option = *optPtr;
new StaticText(form, grid.getLabelSlot(), option.name); new StaticText(form, grid.getLabelSlot(), option.name);
switch (option.type) { switch (option.type) {
case ZoneOption::Integer: case ZoneOption::Integer:
new NumberEdit(form, grid.getFieldSlot(), new NumberEdit(form, grid.getFieldSlot(),
option.min.signedValue, // Minimum option.min.signedValue, // Minimum
option.max.signedValue, // Maximum option.max.signedValue, // Maximum
[=]() -> int { // getValue [=]() -> int { // getValue
return widget->getOptionValue(optIdx)->signedValue; return widget->getOptionValue(optIdx)->signedValue;
}, },
[=](int32_t newValue) { // setValue [=](int32_t newValue) { // setValue
widget->setOptionValue(optIdx, OPTION_VALUE_SIGNED(newValue)); widget->setOptionValue(optIdx, OPTION_VALUE_SIGNED(newValue));
}); });
break; break;
case ZoneOption::Source: case ZoneOption::Source:
new SourceChoice(form, grid.getFieldSlot(), new SourceChoice(form, grid.getFieldSlot(),
option.min.unsignedValue, // min option.min.unsignedValue, // min
option.max.unsignedValue, // max option.max.unsignedValue, // max
[=]() -> int16_t { // getValue [=]() -> int16_t { // getValue
return (int16_t)widget->getOptionValue(optIdx)->unsignedValue; 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;
}, },
[=](int8_t newValue) { // setValue [=](int16_t newValue) { // setValue
widget->setOptionValue(optIdx, OPTION_VALUE_BOOL((uint32_t)newValue)); widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t) newValue));
}); });
break; break;
case ZoneOption::String: case ZoneOption::Bool:
break; 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: case ZoneOption::String:
break; break;
case ZoneOption::TextSize: case ZoneOption::File:
break; break;
case ZoneOption::Timer: // Unsigned case ZoneOption::TextSize:
{ break;
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));
});
tmChoice->setTextHandler([](int value) { case ZoneOption::Timer: // Unsigned
return std::string(STR_TIMER) + std::to_string(value + 1); {
}); auto tmChoice = new Choice(form, grid.getFieldSlot(),
} 0, TIMERS - 1,
break; [=]() -> int { // getValue
return (int) widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int newValue) { // setValue
widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t) newValue));
});
case ZoneOption::Switch: tmChoice->setTextHandler([](int value) {
new SwitchChoice(form, grid.getFieldSlot(), return std::string(STR_TIMER) + std::to_string(value + 1);
option.min.unsignedValue, // min });
option.max.unsignedValue, // max }
[=]() -> int16_t { // getValue break;
return (uint8_t)widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int16_t newValue) { // setValue
widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t)newValue));
});
break;
case ZoneOption::Color: case ZoneOption::Switch:
break; 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++; case ZoneOption::Color:
optPtr++; new ColorEdit(form, grid.getFieldSlot(), [=]() -> int { // getValue
grid.nextLine(); return (int) widget->getOptionValue(optIdx)->unsignedValue;
} },
[=](int newValue) { // setValue
widget->setOptionValue(optIdx, OPTION_VALUE_UNSIGNED((uint32_t) newValue));
});
break;
}
optIdx++;
optPtr++;
grid.nextLine();
}
} }