fix(color): Logical switches monitor fix (#2410)
* fix(color): Logical switches monitor fix * Direct button style modification. * Using a custom state * Using the default CHECKED style. Adaptation to portrait mode.
This commit is contained in:
@@ -25,6 +25,12 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#if LCD_W > LCD_H // Landscape
|
||||
#define BTN_MATRIX_COL 8
|
||||
#else // Portrait
|
||||
#define BTN_MATRIX_COL 4
|
||||
#endif
|
||||
|
||||
class LogicalSwitchDisplayButton : public TextButton
|
||||
{
|
||||
public:
|
||||
@@ -32,10 +38,6 @@ class LogicalSwitchDisplayButton : public TextButton
|
||||
std::string text, unsigned index) :
|
||||
TextButton(parent, rect, std::move(text), nullptr, OPAQUE), index(index)
|
||||
{
|
||||
setBgColorHandler([=]() -> LcdFlags {
|
||||
if (getSwitch(SWSRC_SW1 + index)) return COLOR_THEME_ACTIVE;
|
||||
return COLOR_THEME_PRIMARY2;
|
||||
});
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
@@ -43,9 +45,9 @@ class LogicalSwitchDisplayButton : public TextButton
|
||||
bool newvalue = getSwitch(SWSRC_SW1 + index);
|
||||
if (value != newvalue) {
|
||||
if (newvalue) {
|
||||
setTextFlags(FONT(BOLD) | COLOR_THEME_SECONDARY1);
|
||||
lv_obj_add_state(lvobj, LV_STATE_CHECKED);
|
||||
} else {
|
||||
setTextFlags(FONT(STD) | COLOR_THEME_SECONDARY1);
|
||||
lv_obj_clear_state(lvobj, LV_STATE_CHECKED);
|
||||
}
|
||||
value = newvalue;
|
||||
invalidate();
|
||||
@@ -63,7 +65,7 @@ void LogicalSwitchesViewPage::build(FormWindow * window)
|
||||
constexpr coord_t LSW_VIEW_FOOTER_HEIGHT = 20;
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
grid.setLabelWidth(8);
|
||||
grid.setLabelWidth(BTN_MATRIX_COL);
|
||||
window->padAll(0);
|
||||
|
||||
// Footer
|
||||
@@ -79,7 +81,7 @@ void LogicalSwitchesViewPage::build(FormWindow * window)
|
||||
strAppendSigned(&lsString[1], i + 1, 2);
|
||||
|
||||
auto button = new LogicalSwitchDisplayButton(
|
||||
window, grid.getFieldSlot(8, i % 8), lsString, i);
|
||||
window, grid.getFieldSlot(BTN_MATRIX_COL, i % BTN_MATRIX_COL), lsString, i);
|
||||
|
||||
button->setFocusHandler([=](bool focus) {
|
||||
if (focus) {
|
||||
@@ -88,6 +90,6 @@ void LogicalSwitchesViewPage::build(FormWindow * window)
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
if ((i + 1) % 8 == 0) grid.nextLine();
|
||||
if ((i + 1) % BTN_MATRIX_COL == 0) grid.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user