From da83e6b210fd4c7b9243b96e7bb28638d048d456 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 5 Apr 2021 18:04:12 +0200 Subject: [PATCH 01/16] getMainZone() moved to Layout --- radio/src/gui/colorlcd/layout.cpp | 32 ++++++++++++++++++++ radio/src/gui/colorlcd/layout.h | 13 ++++++++ radio/src/gui/colorlcd/layouts/layout1x1.cpp | 27 ----------------- radio/src/thirdparty/libopenui | 2 +- 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index 1480db327..a375689c5 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -245,3 +245,35 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) ); } } + +rect_t Layout::getMainZone(rect_t zone) const +{ + bool hasTopbar = getOptionValue(OPTION_TOPBAR)->boolValue; + bool hasFM = getOptionValue(OPTION_FM)->boolValue; + bool hasSliders = getOptionValue(OPTION_SLIDERS)->boolValue; + bool hasTrims = getOptionValue(OPTION_TRIMS)->boolValue; + + if (hasTopbar) { + zone.y += MENU_HEADER_HEIGHT; + zone.h -= MENU_HEADER_HEIGHT; + } + + if (hasFM || hasTrims) { + zone.h -= TRIM_SQUARE_SIZE; + } + + if (hasSliders) { +#if NUM_SLIDERS + NUM_POTS > 2 + zone.h -= TRIM_SQUARE_SIZE; +#endif + zone.w -= 2 * TRIM_SQUARE_SIZE; + zone.x += TRIM_SQUARE_SIZE; + } + + if (hasTrims) { + zone.w -= 2 * TRIM_SQUARE_SIZE; + zone.x += TRIM_SQUARE_SIZE; + } + + return zone; +} diff --git a/radio/src/gui/colorlcd/layout.h b/radio/src/gui/colorlcd/layout.h index 1be0b623a..402468d48 100644 --- a/radio/src/gui/colorlcd/layout.h +++ b/radio/src/gui/colorlcd/layout.h @@ -37,6 +37,16 @@ class Layout: public WidgetsContainer friend class LayoutFactory; public: + + // Common 'ZoneOptionValue's among all layouts + enum { + OPTION_TOPBAR = 0, + OPTION_FM, + OPTION_SLIDERS, + OPTION_TRIMS, + OPTION_MIRRORED + }; + Layout(const LayoutFactory * factory, PersistentData * persistentData): WidgetsContainer({0, 0, LCD_W, LCD_H}, persistentData), factory(factory) @@ -55,6 +65,9 @@ class Layout: public WidgetsContainer TopBar * topBar = nullptr; uint8_t decorationSettings = 0; std::list decorations; + + // get the Zone rect without decoration + rect_t getMainZone(rect_t zone) const; }; void registerLayout(const LayoutFactory * factory); diff --git a/radio/src/gui/colorlcd/layouts/layout1x1.cpp b/radio/src/gui/colorlcd/layouts/layout1x1.cpp index efa3372d8..74ebf1c82 100644 --- a/radio/src/gui/colorlcd/layouts/layout1x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout1x1.cpp @@ -74,33 +74,6 @@ class Layout1x1: public Layout return 1; } - rect_t getMainZone(rect_t zone) const - { - if (HAS_TOPBAR()) { - zone.y += MENU_HEADER_HEIGHT; - zone.h -= MENU_HEADER_HEIGHT; - } - - if (HAS_FM() || HAS_TRIMS()) { - zone.h -= TRIM_SQUARE_SIZE; - } - - if (HAS_SLIDERS()) { -#if NUM_SLIDERS + NUM_POTS > 2 - zone.h -= TRIM_SQUARE_SIZE; -#endif - zone.w -= 2 * TRIM_SQUARE_SIZE; - zone.x += TRIM_SQUARE_SIZE; - } - - if (HAS_TRIMS()) { - zone.w -= 2 * TRIM_SQUARE_SIZE; - zone.x += TRIM_SQUARE_SIZE; - } - - return zone; - } - rect_t getZone(unsigned int index) const override { rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index a106ff4ff..2d57320ce 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit a106ff4ff7b0437fbd9b43c24546df93049f3e57 +Subproject commit 2d57320ce37e1e749357baa278300db776132d41 From 179b86635cab5d5c7c079a015e27486ac9492990 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 5 Apr 2021 18:32:28 +0200 Subject: [PATCH 02/16] unify common layout settings --- radio/src/gui/colorlcd/layout.cpp | 61 +++++++++----------- radio/src/gui/colorlcd/layout.h | 46 ++++++++++++++- radio/src/gui/colorlcd/layouts/layout1x1.cpp | 26 ++------- radio/src/gui/colorlcd/layouts/layout2+1.cpp | 23 +------- radio/src/gui/colorlcd/layouts/layout2x1.cpp | 23 +------- radio/src/gui/colorlcd/layouts/layout2x2.cpp | 23 +------- radio/src/gui/colorlcd/layouts/layout2x4.cpp | 7 +-- 7 files changed, 84 insertions(+), 125 deletions(-) diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index a375689c5..f48d025eb 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -97,14 +97,14 @@ void loadCustomScreens() } } -void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) +void Layout::decorate() { // check if deco setting are still up-to-date uint8_t checkSettings = - (topbar ? 1 << 0 : 0) | - (sliders ? 1 << 1 : 0) | - (trims ? 1 << 2 : 0) | - (flightMode ? 1 << 3 : 0); + (hasTopbar() ? 1 << 0 : 0) | + (hasSliders() ? 1 << 1 : 0) | + (hasTrims() ? 1 << 2 : 0) | + (hasFlightMode() ? 1 << 3 : 0); if (checkSettings == decorationSettings) { // everything ok, exit! @@ -123,16 +123,16 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) // save settings decorationSettings = checkSettings; - - if (topbar) { + + if (hasTopbar()) { topBar = new TopBar(this); topBar->load(); decorations.push_back(topBar); } - if (sliders) { + if (hasSliders()) { #if defined(HARDWARE_EXT1) || defined(HARDWARE_EXT2) - coord_t yOffset = (trims ? - TRIM_SQUARE_SIZE : 0) + (topbar ? TOPBAR_HEIGHT / 2 : 0); + coord_t yOffset = (hasTrims() ? - TRIM_SQUARE_SIZE : 0) + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0); #endif decorations.push_back( @@ -163,17 +163,17 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) #if defined(HARDWARE_EXT1) if (IS_POT_SLIDER_AVAILABLE(EXT1)) { decorations.push_back( - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2}, [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }) ); decorations.push_back( - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2}, [=] { return calibratedAnalogs[CALIBRATED_POT_EXT1]; }) ); } else { decorations.push_back( - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())}, [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }) ); } @@ -182,33 +182,33 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) #if defined(HARDWARE_EXT2) if (IS_POT_SLIDER_AVAILABLE(EXT2)) { decorations.push_back( - new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, - VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, + VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2}, [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }) ); decorations.push_back( new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, - VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2}, [=] { return calibratedAnalogs[CALIBRATED_POT_EXT2]; }) ); } else { decorations.push_back( - new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, - VERTICAL_SLIDERS_HEIGHT(topbar)}, + new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, + VERTICAL_SLIDERS_HEIGHT(hasTopbar())}, [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }) ); } #endif } - if (trims) { + if (hasTrims()) { #if defined(HARDWARE_POT3) || defined(HARDWARE_EXT1) - coord_t xOffset = sliders? TRIM_SQUARE_SIZE : 0; + coord_t xOffset = hasSliders() ? TRIM_SQUARE_SIZE : 0; #else coord_t xOffset = 0; #endif - coord_t yOffset = (trims ? - TRIM_SQUARE_SIZE : 0); + coord_t yOffset = (hasTrims() ? - TRIM_SQUARE_SIZE : 0); // Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH @@ -226,20 +226,20 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) // Left decorations.push_back( - new MainViewVerticalTrim(this, {HMARGIN + xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + new MainViewVerticalTrim(this, {HMARGIN + xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())}, [=] { return getTrimValue(mixerCurrentFlightMode, 1); }) ); // Right decorations.push_back( - new MainViewVerticalTrim(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE - xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + new MainViewVerticalTrim(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE - xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())}, [=] { return getTrimValue(mixerCurrentFlightMode, 2); }) ); } - if (flightMode) { + if (hasFlightMode()) { decorations.push_back( - new DynamicText(this, {50, LCD_H - 4 - (sliders? 2 * TRIM_SQUARE_SIZE: TRIM_SQUARE_SIZE), LCD_W - 100, 20}, [=] { + new DynamicText(this, {50, LCD_H - 4 - (hasSliders() ? 2 * TRIM_SQUARE_SIZE: TRIM_SQUARE_SIZE), LCD_W - 100, 20}, [=] { return g_model.flightModeData[mixerCurrentFlightMode].name; }, CENTERED) ); @@ -248,21 +248,16 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) rect_t Layout::getMainZone(rect_t zone) const { - bool hasTopbar = getOptionValue(OPTION_TOPBAR)->boolValue; - bool hasFM = getOptionValue(OPTION_FM)->boolValue; - bool hasSliders = getOptionValue(OPTION_SLIDERS)->boolValue; - bool hasTrims = getOptionValue(OPTION_TRIMS)->boolValue; - - if (hasTopbar) { + if (hasTopbar()) { zone.y += MENU_HEADER_HEIGHT; zone.h -= MENU_HEADER_HEIGHT; } - if (hasFM || hasTrims) { + if (hasFlightMode() || hasTrims()) { zone.h -= TRIM_SQUARE_SIZE; } - if (hasSliders) { + if (hasSliders()) { #if NUM_SLIDERS + NUM_POTS > 2 zone.h -= TRIM_SQUARE_SIZE; #endif @@ -270,7 +265,7 @@ rect_t Layout::getMainZone(rect_t zone) const zone.x += TRIM_SQUARE_SIZE; } - if (hasTrims) { + if (hasTrims()) { zone.w -= 2 * TRIM_SQUARE_SIZE; zone.x += TRIM_SQUARE_SIZE; } diff --git a/radio/src/gui/colorlcd/layout.h b/radio/src/gui/colorlcd/layout.h index 402468d48..b387c2fb6 100644 --- a/radio/src/gui/colorlcd/layout.h +++ b/radio/src/gui/colorlcd/layout.h @@ -32,7 +32,19 @@ constexpr coord_t TRIM_SQUARE_SIZE = 17; class LayoutFactory; -class Layout: public WidgetsContainer +#define LAYOUT_COMMON_OPTIONS \ + { STR_TOP_BAR, ZoneOption::Bool }, \ + { STR_FLIGHT_MODE, ZoneOption::Bool }, \ + { STR_SLIDERS, ZoneOption::Bool }, \ + { STR_TRIMS, ZoneOption::Bool }, \ + { STR_MIRROR, ZoneOption::Bool } + +#define LAYOUT_OPTIONS_END \ + { nullptr, ZoneOption::Bool } + +typedef WidgetsContainer LayoutBase; + +class Layout: public LayoutBase { friend class LayoutFactory; @@ -48,9 +60,10 @@ class Layout: public WidgetsContainer }; Layout(const LayoutFactory * factory, PersistentData * persistentData): - WidgetsContainer({0, 0, LCD_W, LCD_H}, persistentData), + LayoutBase({0, 0, LCD_W, LCD_H}, persistentData), factory(factory) { + decorate(); } inline const LayoutFactory * getFactory() const @@ -58,7 +71,31 @@ class Layout: public WidgetsContainer return factory; } - void decorate(bool topbar, bool sliders, bool trims, bool flightMode); + void checkEvents() override + { + LayoutBase::checkEvents(); + decorate(); + } + + bool hasTopbar() const { + return getOptionValue(OPTION_TOPBAR)->boolValue; + } + + bool hasFlightMode() const { + return getOptionValue(OPTION_FM)->boolValue; + } + + bool hasSliders() const { + return getOptionValue(OPTION_SLIDERS)->boolValue; + } + + bool hasTrims() const { + return getOptionValue(OPTION_TRIMS)->boolValue; + } + + bool isMirrored() const { + return getOptionValue(OPTION_MIRRORED)->boolValue; + } protected: const LayoutFactory * factory; @@ -66,6 +103,9 @@ class Layout: public WidgetsContainer uint8_t decorationSettings = 0; std::list decorations; + // adds trims, sliders, pots, etc... + void decorate(); + // get the Zone rect without decoration rect_t getMainZone(rect_t zone) const; }; diff --git a/radio/src/gui/colorlcd/layouts/layout1x1.cpp b/radio/src/gui/colorlcd/layouts/layout1x1.cpp index 74ebf1c82..13dcf0cd1 100644 --- a/radio/src/gui/colorlcd/layouts/layout1x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout1x1.cpp @@ -34,12 +34,8 @@ const uint8_t LBM_LAYOUT_1x1[] = { }; const ZoneOption OPTIONS_LAYOUT_1x1[] = { - { STR_TOP_BAR, ZoneOption::Bool }, - { STR_FLIGHT_MODE, ZoneOption::Bool }, - { STR_SLIDERS, ZoneOption::Bool }, - { STR_TRIMS, ZoneOption::Bool }, - { STR_MIRROR, ZoneOption::Bool }, - { nullptr, ZoneOption::Bool } + LAYOUT_COMMON_OPTIONS, + LAYOUT_OPTIONS_END }; class Layout1x1: public Layout @@ -48,27 +44,23 @@ class Layout1x1: public Layout Layout1x1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { - decorate(); } void create() override { Layout::create(); + // TODO: make this common to all layouts as well persistentData->options[0].value.boolValue = true; persistentData->options[1].value.boolValue = true; persistentData->options[2].value.boolValue = true; persistentData->options[3].value.boolValue = true; persistentData->options[4].value.boolValue = false; persistentData->options[5].value.boolValue = false; + + // TODO: really needed? decorate(); } - void decorate() - { - Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM()); - } - - unsigned int getZonesCount() const override { return 1; @@ -80,14 +72,6 @@ class Layout1x1: public Layout return zone; } - - void checkEvents() override - { - Layout::checkEvents(); - decorate(); - } - protected: - uint8_t value = 0; }; BaseLayoutFactory layout1x1("Layout1x1", "Fullscreen", LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1); diff --git a/radio/src/gui/colorlcd/layouts/layout2+1.cpp b/radio/src/gui/colorlcd/layouts/layout2+1.cpp index ed40c6a7f..989775d71 100644 --- a/radio/src/gui/colorlcd/layouts/layout2+1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2+1.cpp @@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2P1[] = { }; const ZoneOption OPTIONS_LAYOUT_2P1[] = { - { STR_TOP_BAR, ZoneOption::Bool }, - { STR_FLIGHT_MODE, ZoneOption::Bool }, - { STR_SLIDERS, ZoneOption::Bool }, - { STR_TRIMS, ZoneOption::Bool }, - { STR_MIRROR, ZoneOption::Bool }, - { nullptr, ZoneOption::Bool } + LAYOUT_COMMON_OPTIONS, + LAYOUT_OPTIONS_END }; const rect_t ZONES_LAYOUT_2P1[3] = { @@ -53,7 +49,6 @@ class Layout2P1: public Layout Layout2P1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { - decorate(); } void create() override @@ -68,11 +63,6 @@ class Layout2P1: public Layout decorate(); } - void decorate() - { - Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM()); - } - unsigned int getZonesCount() const override { return DIM(ZONES_LAYOUT_2P1); @@ -82,15 +72,6 @@ class Layout2P1: public Layout { return ZONES_LAYOUT_2P1[index]; } - - void checkEvents() override - { - Layout::checkEvents(); - // TODO call this from the Layout config window - decorate(); - } - protected: - uint8_t value = 0; }; BaseLayoutFactory layout2P1("Layout2P1", "2 + 1", LBM_LAYOUT_2P1, OPTIONS_LAYOUT_2P1); diff --git a/radio/src/gui/colorlcd/layouts/layout2x1.cpp b/radio/src/gui/colorlcd/layouts/layout2x1.cpp index 67610c614..2e9f1f875 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x1.cpp @@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2x1[] = { }; const ZoneOption OPTIONS_LAYOUT_2x1[] = { - { STR_TOP_BAR, ZoneOption::Bool }, - { STR_FLIGHT_MODE, ZoneOption::Bool }, - { STR_SLIDERS, ZoneOption::Bool }, - { STR_TRIMS, ZoneOption::Bool }, - { STR_MIRROR, ZoneOption::Bool }, - { nullptr, ZoneOption::Bool } + LAYOUT_COMMON_OPTIONS, + LAYOUT_OPTIONS_END }; class Layout2x1: public Layout @@ -47,7 +43,6 @@ class Layout2x1: public Layout Layout2x1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { - decorate(); } void create() override @@ -62,12 +57,6 @@ class Layout2x1: public Layout decorate(); } - void decorate() - { - Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM()); - } - - unsigned int getZonesCount() const override { return 2; @@ -88,14 +77,6 @@ class Layout2x1: public Layout } return zone; } - - void checkEvents() override - { - Layout::checkEvents(); - decorate(); - } - protected: - uint8_t value = 0; }; BaseLayoutFactory Layout2x1("Layout2x1", "2 x 1", LBM_LAYOUT_2x1, OPTIONS_LAYOUT_2x1); diff --git a/radio/src/gui/colorlcd/layouts/layout2x2.cpp b/radio/src/gui/colorlcd/layouts/layout2x2.cpp index 37bf4515b..59c346c8e 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x2.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x2.cpp @@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2x2[] = { }; const ZoneOption OPTIONS_LAYOUT_2x2[] = { - { STR_TOP_BAR, ZoneOption::Bool }, - { STR_FLIGHT_MODE, ZoneOption::Bool }, - { STR_SLIDERS, ZoneOption::Bool }, - { STR_TRIMS, ZoneOption::Bool }, - { STR_MIRROR, ZoneOption::Bool }, - { nullptr, ZoneOption::Bool } + LAYOUT_COMMON_OPTIONS, + LAYOUT_OPTIONS_END }; class Layout2x2: public Layout @@ -47,7 +43,6 @@ class Layout2x2: public Layout Layout2x2(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { - decorate(); } void create() override @@ -62,11 +57,6 @@ class Layout2x2: public Layout decorate(); } - void decorate() - { - Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM()); - } - unsigned int getZonesCount() const override { return 4; @@ -90,15 +80,6 @@ class Layout2x2: public Layout } return zone; } - - void checkEvents() override - { - Layout::checkEvents(); - decorate(); - } - - protected: - uint8_t value = 0; }; BaseLayoutFactory layout2x2("Layout2x2", "2 x 2", LBM_LAYOUT_2x2, OPTIONS_LAYOUT_2x2); diff --git a/radio/src/gui/colorlcd/layouts/layout2x4.cpp b/radio/src/gui/colorlcd/layouts/layout2x4.cpp index a9bf78e76..5a5d183ed 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x4.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x4.cpp @@ -25,15 +25,12 @@ const uint8_t LBM_LAYOUT_2x4[] = { }; const ZoneOption OPTIONS_LAYOUT_2x4[] = { - { "Top bar", ZoneOption::Bool }, - { "Flight mode", ZoneOption::Bool }, - { "Sliders", ZoneOption::Bool }, - { "Trims", ZoneOption::Bool }, + LAYOUT_COMMON_OPTIONS, { "Panel1 background", ZoneOption::Bool }, { " Color", ZoneOption::Color }, { "Panel2 background", ZoneOption::Bool }, { " Color", ZoneOption::Color }, - { nullptr, ZoneOption::Bool } + LAYOUT_OPTIONS_END }; class Layout2x4: public Layout From 680a7162191cbaef83b7bb508a6defc6640bbd2c Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 08:45:01 +0200 Subject: [PATCH 03/16] Cosmetics --- radio/src/gui/colorlcd/widgets/modelbmp.cpp | 1 + radio/src/gui/colorlcd/widgets/outputs.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/radio/src/gui/colorlcd/widgets/modelbmp.cpp b/radio/src/gui/colorlcd/widgets/modelbmp.cpp index 529c17a9e..fbcffd95c 100644 --- a/radio/src/gui/colorlcd/widgets/modelbmp.cpp +++ b/radio/src/gui/colorlcd/widgets/modelbmp.cpp @@ -19,6 +19,7 @@ */ #include "opentx.h" +#include class ModelBitmapWidget: public Widget { diff --git a/radio/src/gui/colorlcd/widgets/outputs.cpp b/radio/src/gui/colorlcd/widgets/outputs.cpp index 97efed9b2..38c6d240a 100644 --- a/radio/src/gui/colorlcd/widgets/outputs.cpp +++ b/radio/src/gui/colorlcd/widgets/outputs.cpp @@ -79,12 +79,12 @@ class OutputsWidget: public Widget void twoColumns(BitmapBuffer * dc) { - uint8_t endColumn = drawChannels(dc, 0, 0, width() / 2, height(), + uint8_t endColumn = drawChannels(dc, 0, 0, (width() / 2) - 1, height(), persistentData->options[0].value.unsignedValue, persistentData->options[1].value.boolValue, persistentData->options[2].value.unsignedValue); - drawChannels(dc, width() / 2 + 2, 0, width() / 2, height(), endColumn + 1, + drawChannels(dc, width() / 2, 0, (width() / 2) - 1, height(), endColumn + 1, persistentData->options[1].value.boolValue, persistentData->options[2].value.unsignedValue); } From 5c8448a696014ccd7670ea3a82e6b849ecb43035 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 5 Apr 2021 18:04:12 +0200 Subject: [PATCH 04/16] getMainZone() moved to Layout --- radio/src/gui/colorlcd/layout.cpp | 32 ++++++++++++++++++++ radio/src/gui/colorlcd/layout.h | 13 ++++++++ radio/src/gui/colorlcd/layouts/layout1x1.cpp | 27 ----------------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index 1480db327..a375689c5 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -245,3 +245,35 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) ); } } + +rect_t Layout::getMainZone(rect_t zone) const +{ + bool hasTopbar = getOptionValue(OPTION_TOPBAR)->boolValue; + bool hasFM = getOptionValue(OPTION_FM)->boolValue; + bool hasSliders = getOptionValue(OPTION_SLIDERS)->boolValue; + bool hasTrims = getOptionValue(OPTION_TRIMS)->boolValue; + + if (hasTopbar) { + zone.y += MENU_HEADER_HEIGHT; + zone.h -= MENU_HEADER_HEIGHT; + } + + if (hasFM || hasTrims) { + zone.h -= TRIM_SQUARE_SIZE; + } + + if (hasSliders) { +#if NUM_SLIDERS + NUM_POTS > 2 + zone.h -= TRIM_SQUARE_SIZE; +#endif + zone.w -= 2 * TRIM_SQUARE_SIZE; + zone.x += TRIM_SQUARE_SIZE; + } + + if (hasTrims) { + zone.w -= 2 * TRIM_SQUARE_SIZE; + zone.x += TRIM_SQUARE_SIZE; + } + + return zone; +} diff --git a/radio/src/gui/colorlcd/layout.h b/radio/src/gui/colorlcd/layout.h index 1be0b623a..402468d48 100644 --- a/radio/src/gui/colorlcd/layout.h +++ b/radio/src/gui/colorlcd/layout.h @@ -37,6 +37,16 @@ class Layout: public WidgetsContainer friend class LayoutFactory; public: + + // Common 'ZoneOptionValue's among all layouts + enum { + OPTION_TOPBAR = 0, + OPTION_FM, + OPTION_SLIDERS, + OPTION_TRIMS, + OPTION_MIRRORED + }; + Layout(const LayoutFactory * factory, PersistentData * persistentData): WidgetsContainer({0, 0, LCD_W, LCD_H}, persistentData), factory(factory) @@ -55,6 +65,9 @@ class Layout: public WidgetsContainer TopBar * topBar = nullptr; uint8_t decorationSettings = 0; std::list decorations; + + // get the Zone rect without decoration + rect_t getMainZone(rect_t zone) const; }; void registerLayout(const LayoutFactory * factory); diff --git a/radio/src/gui/colorlcd/layouts/layout1x1.cpp b/radio/src/gui/colorlcd/layouts/layout1x1.cpp index efa3372d8..74ebf1c82 100644 --- a/radio/src/gui/colorlcd/layouts/layout1x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout1x1.cpp @@ -74,33 +74,6 @@ class Layout1x1: public Layout return 1; } - rect_t getMainZone(rect_t zone) const - { - if (HAS_TOPBAR()) { - zone.y += MENU_HEADER_HEIGHT; - zone.h -= MENU_HEADER_HEIGHT; - } - - if (HAS_FM() || HAS_TRIMS()) { - zone.h -= TRIM_SQUARE_SIZE; - } - - if (HAS_SLIDERS()) { -#if NUM_SLIDERS + NUM_POTS > 2 - zone.h -= TRIM_SQUARE_SIZE; -#endif - zone.w -= 2 * TRIM_SQUARE_SIZE; - zone.x += TRIM_SQUARE_SIZE; - } - - if (HAS_TRIMS()) { - zone.w -= 2 * TRIM_SQUARE_SIZE; - zone.x += TRIM_SQUARE_SIZE; - } - - return zone; - } - rect_t getZone(unsigned int index) const override { rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); From 8ff01377088ff2b3e80a7667b6c97638a859e60a Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 5 Apr 2021 18:32:28 +0200 Subject: [PATCH 05/16] unify common layout settings --- radio/src/gui/colorlcd/layout.cpp | 61 +++++++++----------- radio/src/gui/colorlcd/layout.h | 46 ++++++++++++++- radio/src/gui/colorlcd/layouts/layout1x1.cpp | 26 ++------- radio/src/gui/colorlcd/layouts/layout2+1.cpp | 23 +------- radio/src/gui/colorlcd/layouts/layout2x1.cpp | 23 +------- radio/src/gui/colorlcd/layouts/layout2x2.cpp | 23 +------- radio/src/gui/colorlcd/layouts/layout2x4.cpp | 7 +-- 7 files changed, 84 insertions(+), 125 deletions(-) diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index a375689c5..f48d025eb 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -97,14 +97,14 @@ void loadCustomScreens() } } -void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) +void Layout::decorate() { // check if deco setting are still up-to-date uint8_t checkSettings = - (topbar ? 1 << 0 : 0) | - (sliders ? 1 << 1 : 0) | - (trims ? 1 << 2 : 0) | - (flightMode ? 1 << 3 : 0); + (hasTopbar() ? 1 << 0 : 0) | + (hasSliders() ? 1 << 1 : 0) | + (hasTrims() ? 1 << 2 : 0) | + (hasFlightMode() ? 1 << 3 : 0); if (checkSettings == decorationSettings) { // everything ok, exit! @@ -123,16 +123,16 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) // save settings decorationSettings = checkSettings; - - if (topbar) { + + if (hasTopbar()) { topBar = new TopBar(this); topBar->load(); decorations.push_back(topBar); } - if (sliders) { + if (hasSliders()) { #if defined(HARDWARE_EXT1) || defined(HARDWARE_EXT2) - coord_t yOffset = (trims ? - TRIM_SQUARE_SIZE : 0) + (topbar ? TOPBAR_HEIGHT / 2 : 0); + coord_t yOffset = (hasTrims() ? - TRIM_SQUARE_SIZE : 0) + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0); #endif decorations.push_back( @@ -163,17 +163,17 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) #if defined(HARDWARE_EXT1) if (IS_POT_SLIDER_AVAILABLE(EXT1)) { decorations.push_back( - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2}, [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }) ); decorations.push_back( - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2}, [=] { return calibratedAnalogs[CALIBRATED_POT_EXT1]; }) ); } else { decorations.push_back( - new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + new MainViewVerticalSlider(this, {HMARGIN, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())}, [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT]; }) ); } @@ -182,33 +182,33 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) #if defined(HARDWARE_EXT2) if (IS_POT_SLIDER_AVAILABLE(EXT2)) { decorations.push_back( - new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, - VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, + VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2}, [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }) ); decorations.push_back( new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 + yOffset, TRIM_SQUARE_SIZE, - VERTICAL_SLIDERS_HEIGHT(topbar) / 2}, + VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2}, [=] { return calibratedAnalogs[CALIBRATED_POT_EXT2]; }) ); } else { decorations.push_back( - new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset, TRIM_SQUARE_SIZE, - VERTICAL_SLIDERS_HEIGHT(topbar)}, + new MainViewVerticalSlider(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE, LCD_H / 2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset, TRIM_SQUARE_SIZE, + VERTICAL_SLIDERS_HEIGHT(hasTopbar())}, [=] { return calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT]; }) ); } #endif } - if (trims) { + if (hasTrims()) { #if defined(HARDWARE_POT3) || defined(HARDWARE_EXT1) - coord_t xOffset = sliders? TRIM_SQUARE_SIZE : 0; + coord_t xOffset = hasSliders() ? TRIM_SQUARE_SIZE : 0; #else coord_t xOffset = 0; #endif - coord_t yOffset = (trims ? - TRIM_SQUARE_SIZE : 0); + coord_t yOffset = (hasTrims() ? - TRIM_SQUARE_SIZE : 0); // Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH @@ -226,20 +226,20 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) // Left decorations.push_back( - new MainViewVerticalTrim(this, {HMARGIN + xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + new MainViewVerticalTrim(this, {HMARGIN + xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())}, [=] { return getTrimValue(mixerCurrentFlightMode, 1); }) ); // Right decorations.push_back( - new MainViewVerticalTrim(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE - xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(topbar) / 2 + yOffset + (topbar ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(topbar)}, + new MainViewVerticalTrim(this, {LCD_W - HMARGIN - TRIM_SQUARE_SIZE - xOffset, LCD_H /2 - VERTICAL_SLIDERS_HEIGHT(hasTopbar()) / 2 + yOffset + (hasTopbar() ? TOPBAR_HEIGHT / 2 : 0), TRIM_SQUARE_SIZE, VERTICAL_SLIDERS_HEIGHT(hasTopbar())}, [=] { return getTrimValue(mixerCurrentFlightMode, 2); }) ); } - if (flightMode) { + if (hasFlightMode()) { decorations.push_back( - new DynamicText(this, {50, LCD_H - 4 - (sliders? 2 * TRIM_SQUARE_SIZE: TRIM_SQUARE_SIZE), LCD_W - 100, 20}, [=] { + new DynamicText(this, {50, LCD_H - 4 - (hasSliders() ? 2 * TRIM_SQUARE_SIZE: TRIM_SQUARE_SIZE), LCD_W - 100, 20}, [=] { return g_model.flightModeData[mixerCurrentFlightMode].name; }, CENTERED) ); @@ -248,21 +248,16 @@ void Layout::decorate(bool topbar, bool sliders, bool trims, bool flightMode) rect_t Layout::getMainZone(rect_t zone) const { - bool hasTopbar = getOptionValue(OPTION_TOPBAR)->boolValue; - bool hasFM = getOptionValue(OPTION_FM)->boolValue; - bool hasSliders = getOptionValue(OPTION_SLIDERS)->boolValue; - bool hasTrims = getOptionValue(OPTION_TRIMS)->boolValue; - - if (hasTopbar) { + if (hasTopbar()) { zone.y += MENU_HEADER_HEIGHT; zone.h -= MENU_HEADER_HEIGHT; } - if (hasFM || hasTrims) { + if (hasFlightMode() || hasTrims()) { zone.h -= TRIM_SQUARE_SIZE; } - if (hasSliders) { + if (hasSliders()) { #if NUM_SLIDERS + NUM_POTS > 2 zone.h -= TRIM_SQUARE_SIZE; #endif @@ -270,7 +265,7 @@ rect_t Layout::getMainZone(rect_t zone) const zone.x += TRIM_SQUARE_SIZE; } - if (hasTrims) { + if (hasTrims()) { zone.w -= 2 * TRIM_SQUARE_SIZE; zone.x += TRIM_SQUARE_SIZE; } diff --git a/radio/src/gui/colorlcd/layout.h b/radio/src/gui/colorlcd/layout.h index 402468d48..b387c2fb6 100644 --- a/radio/src/gui/colorlcd/layout.h +++ b/radio/src/gui/colorlcd/layout.h @@ -32,7 +32,19 @@ constexpr coord_t TRIM_SQUARE_SIZE = 17; class LayoutFactory; -class Layout: public WidgetsContainer +#define LAYOUT_COMMON_OPTIONS \ + { STR_TOP_BAR, ZoneOption::Bool }, \ + { STR_FLIGHT_MODE, ZoneOption::Bool }, \ + { STR_SLIDERS, ZoneOption::Bool }, \ + { STR_TRIMS, ZoneOption::Bool }, \ + { STR_MIRROR, ZoneOption::Bool } + +#define LAYOUT_OPTIONS_END \ + { nullptr, ZoneOption::Bool } + +typedef WidgetsContainer LayoutBase; + +class Layout: public LayoutBase { friend class LayoutFactory; @@ -48,9 +60,10 @@ class Layout: public WidgetsContainer }; Layout(const LayoutFactory * factory, PersistentData * persistentData): - WidgetsContainer({0, 0, LCD_W, LCD_H}, persistentData), + LayoutBase({0, 0, LCD_W, LCD_H}, persistentData), factory(factory) { + decorate(); } inline const LayoutFactory * getFactory() const @@ -58,7 +71,31 @@ class Layout: public WidgetsContainer return factory; } - void decorate(bool topbar, bool sliders, bool trims, bool flightMode); + void checkEvents() override + { + LayoutBase::checkEvents(); + decorate(); + } + + bool hasTopbar() const { + return getOptionValue(OPTION_TOPBAR)->boolValue; + } + + bool hasFlightMode() const { + return getOptionValue(OPTION_FM)->boolValue; + } + + bool hasSliders() const { + return getOptionValue(OPTION_SLIDERS)->boolValue; + } + + bool hasTrims() const { + return getOptionValue(OPTION_TRIMS)->boolValue; + } + + bool isMirrored() const { + return getOptionValue(OPTION_MIRRORED)->boolValue; + } protected: const LayoutFactory * factory; @@ -66,6 +103,9 @@ class Layout: public WidgetsContainer uint8_t decorationSettings = 0; std::list decorations; + // adds trims, sliders, pots, etc... + void decorate(); + // get the Zone rect without decoration rect_t getMainZone(rect_t zone) const; }; diff --git a/radio/src/gui/colorlcd/layouts/layout1x1.cpp b/radio/src/gui/colorlcd/layouts/layout1x1.cpp index 74ebf1c82..13dcf0cd1 100644 --- a/radio/src/gui/colorlcd/layouts/layout1x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout1x1.cpp @@ -34,12 +34,8 @@ const uint8_t LBM_LAYOUT_1x1[] = { }; const ZoneOption OPTIONS_LAYOUT_1x1[] = { - { STR_TOP_BAR, ZoneOption::Bool }, - { STR_FLIGHT_MODE, ZoneOption::Bool }, - { STR_SLIDERS, ZoneOption::Bool }, - { STR_TRIMS, ZoneOption::Bool }, - { STR_MIRROR, ZoneOption::Bool }, - { nullptr, ZoneOption::Bool } + LAYOUT_COMMON_OPTIONS, + LAYOUT_OPTIONS_END }; class Layout1x1: public Layout @@ -48,27 +44,23 @@ class Layout1x1: public Layout Layout1x1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { - decorate(); } void create() override { Layout::create(); + // TODO: make this common to all layouts as well persistentData->options[0].value.boolValue = true; persistentData->options[1].value.boolValue = true; persistentData->options[2].value.boolValue = true; persistentData->options[3].value.boolValue = true; persistentData->options[4].value.boolValue = false; persistentData->options[5].value.boolValue = false; + + // TODO: really needed? decorate(); } - void decorate() - { - Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM()); - } - - unsigned int getZonesCount() const override { return 1; @@ -80,14 +72,6 @@ class Layout1x1: public Layout return zone; } - - void checkEvents() override - { - Layout::checkEvents(); - decorate(); - } - protected: - uint8_t value = 0; }; BaseLayoutFactory layout1x1("Layout1x1", "Fullscreen", LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1); diff --git a/radio/src/gui/colorlcd/layouts/layout2+1.cpp b/radio/src/gui/colorlcd/layouts/layout2+1.cpp index ed40c6a7f..989775d71 100644 --- a/radio/src/gui/colorlcd/layouts/layout2+1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2+1.cpp @@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2P1[] = { }; const ZoneOption OPTIONS_LAYOUT_2P1[] = { - { STR_TOP_BAR, ZoneOption::Bool }, - { STR_FLIGHT_MODE, ZoneOption::Bool }, - { STR_SLIDERS, ZoneOption::Bool }, - { STR_TRIMS, ZoneOption::Bool }, - { STR_MIRROR, ZoneOption::Bool }, - { nullptr, ZoneOption::Bool } + LAYOUT_COMMON_OPTIONS, + LAYOUT_OPTIONS_END }; const rect_t ZONES_LAYOUT_2P1[3] = { @@ -53,7 +49,6 @@ class Layout2P1: public Layout Layout2P1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { - decorate(); } void create() override @@ -68,11 +63,6 @@ class Layout2P1: public Layout decorate(); } - void decorate() - { - Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM()); - } - unsigned int getZonesCount() const override { return DIM(ZONES_LAYOUT_2P1); @@ -82,15 +72,6 @@ class Layout2P1: public Layout { return ZONES_LAYOUT_2P1[index]; } - - void checkEvents() override - { - Layout::checkEvents(); - // TODO call this from the Layout config window - decorate(); - } - protected: - uint8_t value = 0; }; BaseLayoutFactory layout2P1("Layout2P1", "2 + 1", LBM_LAYOUT_2P1, OPTIONS_LAYOUT_2P1); diff --git a/radio/src/gui/colorlcd/layouts/layout2x1.cpp b/radio/src/gui/colorlcd/layouts/layout2x1.cpp index 67610c614..2e9f1f875 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x1.cpp @@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2x1[] = { }; const ZoneOption OPTIONS_LAYOUT_2x1[] = { - { STR_TOP_BAR, ZoneOption::Bool }, - { STR_FLIGHT_MODE, ZoneOption::Bool }, - { STR_SLIDERS, ZoneOption::Bool }, - { STR_TRIMS, ZoneOption::Bool }, - { STR_MIRROR, ZoneOption::Bool }, - { nullptr, ZoneOption::Bool } + LAYOUT_COMMON_OPTIONS, + LAYOUT_OPTIONS_END }; class Layout2x1: public Layout @@ -47,7 +43,6 @@ class Layout2x1: public Layout Layout2x1(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { - decorate(); } void create() override @@ -62,12 +57,6 @@ class Layout2x1: public Layout decorate(); } - void decorate() - { - Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM()); - } - - unsigned int getZonesCount() const override { return 2; @@ -88,14 +77,6 @@ class Layout2x1: public Layout } return zone; } - - void checkEvents() override - { - Layout::checkEvents(); - decorate(); - } - protected: - uint8_t value = 0; }; BaseLayoutFactory Layout2x1("Layout2x1", "2 x 1", LBM_LAYOUT_2x1, OPTIONS_LAYOUT_2x1); diff --git a/radio/src/gui/colorlcd/layouts/layout2x2.cpp b/radio/src/gui/colorlcd/layouts/layout2x2.cpp index 37bf4515b..59c346c8e 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x2.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x2.cpp @@ -33,12 +33,8 @@ const uint8_t LBM_LAYOUT_2x2[] = { }; const ZoneOption OPTIONS_LAYOUT_2x2[] = { - { STR_TOP_BAR, ZoneOption::Bool }, - { STR_FLIGHT_MODE, ZoneOption::Bool }, - { STR_SLIDERS, ZoneOption::Bool }, - { STR_TRIMS, ZoneOption::Bool }, - { STR_MIRROR, ZoneOption::Bool }, - { nullptr, ZoneOption::Bool } + LAYOUT_COMMON_OPTIONS, + LAYOUT_OPTIONS_END }; class Layout2x2: public Layout @@ -47,7 +43,6 @@ class Layout2x2: public Layout Layout2x2(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { - decorate(); } void create() override @@ -62,11 +57,6 @@ class Layout2x2: public Layout decorate(); } - void decorate() - { - Layout::decorate(HAS_TOPBAR(), HAS_SLIDERS(), HAS_TRIMS(), HAS_FM()); - } - unsigned int getZonesCount() const override { return 4; @@ -90,15 +80,6 @@ class Layout2x2: public Layout } return zone; } - - void checkEvents() override - { - Layout::checkEvents(); - decorate(); - } - - protected: - uint8_t value = 0; }; BaseLayoutFactory layout2x2("Layout2x2", "2 x 2", LBM_LAYOUT_2x2, OPTIONS_LAYOUT_2x2); diff --git a/radio/src/gui/colorlcd/layouts/layout2x4.cpp b/radio/src/gui/colorlcd/layouts/layout2x4.cpp index a9bf78e76..5a5d183ed 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x4.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x4.cpp @@ -25,15 +25,12 @@ const uint8_t LBM_LAYOUT_2x4[] = { }; const ZoneOption OPTIONS_LAYOUT_2x4[] = { - { "Top bar", ZoneOption::Bool }, - { "Flight mode", ZoneOption::Bool }, - { "Sliders", ZoneOption::Bool }, - { "Trims", ZoneOption::Bool }, + LAYOUT_COMMON_OPTIONS, { "Panel1 background", ZoneOption::Bool }, { " Color", ZoneOption::Color }, { "Panel2 background", ZoneOption::Bool }, { " Color", ZoneOption::Color }, - { nullptr, ZoneOption::Bool } + LAYOUT_OPTIONS_END }; class Layout2x4: public Layout From f6eca3cf2103c8f49938e519badcc94da9344422 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 08:45:01 +0200 Subject: [PATCH 06/16] Cosmetics --- radio/src/gui/colorlcd/widgets/modelbmp.cpp | 1 + radio/src/gui/colorlcd/widgets/outputs.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/radio/src/gui/colorlcd/widgets/modelbmp.cpp b/radio/src/gui/colorlcd/widgets/modelbmp.cpp index 529c17a9e..fbcffd95c 100644 --- a/radio/src/gui/colorlcd/widgets/modelbmp.cpp +++ b/radio/src/gui/colorlcd/widgets/modelbmp.cpp @@ -19,6 +19,7 @@ */ #include "opentx.h" +#include class ModelBitmapWidget: public Widget { diff --git a/radio/src/gui/colorlcd/widgets/outputs.cpp b/radio/src/gui/colorlcd/widgets/outputs.cpp index 97efed9b2..38c6d240a 100644 --- a/radio/src/gui/colorlcd/widgets/outputs.cpp +++ b/radio/src/gui/colorlcd/widgets/outputs.cpp @@ -79,12 +79,12 @@ class OutputsWidget: public Widget void twoColumns(BitmapBuffer * dc) { - uint8_t endColumn = drawChannels(dc, 0, 0, width() / 2, height(), + uint8_t endColumn = drawChannels(dc, 0, 0, (width() / 2) - 1, height(), persistentData->options[0].value.unsignedValue, persistentData->options[1].value.boolValue, persistentData->options[2].value.unsignedValue); - drawChannels(dc, width() / 2 + 2, 0, width() / 2, height(), endColumn + 1, + drawChannels(dc, width() / 2, 0, (width() / 2) - 1, height(), endColumn + 1, persistentData->options[1].value.boolValue, persistentData->options[2].value.unsignedValue); } From 3d19b03bc16c7078179b1cc2b63c1622a5867551 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 6 Apr 2021 08:54:18 +0200 Subject: [PATCH 07/16] Singleton ViewMain This requires https://github.com/opentx/libopenui/pull/10 --- radio/src/gui/colorlcd/layout.cpp | 4 +-- radio/src/gui/colorlcd/tabsgroup.cpp | 4 +-- radio/src/gui/colorlcd/view_main.cpp | 41 +++++++++++++--------------- radio/src/gui/colorlcd/view_main.h | 20 ++++++++++---- radio/src/opentx.cpp | 5 +--- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index f48d025eb..c0acde330 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -78,7 +78,7 @@ void loadDefaultLayout() strcpy(screenData.layoutName, defaultLayout->getName()); screen = defaultLayout->create(&screenData.layoutData); if (screen) { - screen->attach(ViewMain::instance); + screen->attach(ViewMain::instance()); } } } @@ -92,7 +92,7 @@ void loadCustomScreens() &g_model.screenData[i].layoutData); if (screen) { - screen->attach(ViewMain::instance); + screen->attach(ViewMain::instance()); } } } diff --git a/radio/src/gui/colorlcd/tabsgroup.cpp b/radio/src/gui/colorlcd/tabsgroup.cpp index 98134ca32..e4e29e7ea 100644 --- a/radio/src/gui/colorlcd/tabsgroup.cpp +++ b/radio/src/gui/colorlcd/tabsgroup.cpp @@ -33,7 +33,7 @@ TabsGroupHeader::TabsGroupHeader(TabsGroup * parent, uint8_t icon): back(this, { 0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH }, ICON_BACK, [=]() -> uint8_t { parent->deleteLater(); - ViewMain::instance->setFocus((SET_FOCUS_DEFAULT)); + ViewMain::instance()->setFocus((SET_FOCUS_DEFAULT)); return 1; }, NO_FOCUS), #endif @@ -160,7 +160,7 @@ void TabsGroup::onEvent(event_t event) } else if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) { killEvents(event); - ViewMain::instance->setFocus(SET_FOCUS_DEFAULT); + ViewMain::instance()->setFocus(SET_FOCUS_DEFAULT); deleteLater(); } else if (parent) { diff --git a/radio/src/gui/colorlcd/view_main.cpp b/radio/src/gui/colorlcd/view_main.cpp index eae31b07d..a8c817951 100644 --- a/radio/src/gui/colorlcd/view_main.cpp +++ b/radio/src/gui/colorlcd/view_main.cpp @@ -56,38 +56,35 @@ int getMainViewsCount() return MAX_CUSTOM_SCREENS; } -ViewMain * ViewMain::instance = nullptr; +ViewMain * ViewMain::_instance = nullptr; -ViewMain::ViewMain(bool icons): +ViewMain::ViewMain(): FormWindow(MainWindow::instance(), { 0, 0, LCD_W, LCD_H }) { - instance = this; #if defined(HARDWARE_TOUCH) && !defined(HARDWARE_KEYS) - if (icons) { - new FabButton(this, 50, 100, ICON_MODEL, - [=]() -> uint8_t { - new ModelMenu(); - return 0; - }); + new FabButton(this, 50, 100, ICON_MODEL, + [=]() -> uint8_t { + new ModelMenu(); + return 0; + }); - new FabButton(this, LCD_W / 2, 100, ICON_RADIO, - [=]() -> uint8_t { - new RadioMenu(); - return 0; - }); + new FabButton(this, LCD_W / 2, 100, ICON_RADIO, + [=]() -> uint8_t { + new RadioMenu(); + return 0; + }); - new FabButton(this, LCD_W - 50, 100, ICON_THEME, - [=]() -> uint8_t { - new ScreenMenu(); - return 0; - }); - } + new FabButton(this, LCD_W - 50, 100, ICON_THEME, + [=]() -> uint8_t { + new ScreenMenu(); + return 0; + }); new IconButton(this, {0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH}, ICON_BACK, [=]() -> uint8_t { - openMenu(); - return 0; + openMenu(); + return 0; }, NO_FOCUS); #endif diff --git a/radio/src/gui/colorlcd/view_main.h b/radio/src/gui/colorlcd/view_main.h index 90a55afe0..69243fa48 100644 --- a/radio/src/gui/colorlcd/view_main.h +++ b/radio/src/gui/colorlcd/view_main.h @@ -23,12 +23,22 @@ #include "form.h" -class ViewMain: public FormWindow { - public: - explicit ViewMain(bool icons = true); +class ViewMain: public FormWindow +{ + // singleton + explicit ViewMain(); + public: ~ViewMain() override; + static ViewMain * instance() + { + if (!_instance) + _instance = new ViewMain(); + + return _instance; + } + #if defined(DEBUG_WINDOWS) std::string getName() const override { @@ -36,9 +46,9 @@ class ViewMain: public FormWindow { } #endif - static ViewMain * instance; - protected: + static ViewMain * _instance; + #if defined(HARDWARE_KEYS) void onEvent(event_t event) override; #endif diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 93ff1d391..c7baa0e61 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1896,10 +1896,7 @@ void opentxInit() { TRACE("opentxInit"); -#if defined(LIBOPENUI) - new MainWindow(); - new ViewMain(); -#elif defined(GUI) +#if defined(GUI) && !defined(LIBOPENUI) // TODO add a function for this (duplicated) menuHandlers[0] = menuMainView; #if MENUS_LOCK != 2/*no menus*/ From d43242f686b27dc762be2a7d0865b41fe113674e Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 10:29:01 +0200 Subject: [PATCH 08/16] layout 2+1 --- radio/src/gui/colorlcd/layout.cpp | 6 +++++ radio/src/gui/colorlcd/layouts/layout2+1.cpp | 27 ++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index c0acde330..a84c397ca 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -270,5 +270,11 @@ rect_t Layout::getMainZone(rect_t zone) const zone.x += TRIM_SQUARE_SIZE; } + if (zone.w % 2 != 0) + zone.w -= 1; + + if (zone.h % 2 != 0) + zone.h -= 1; + return zone; } diff --git a/radio/src/gui/colorlcd/layouts/layout2+1.cpp b/radio/src/gui/colorlcd/layouts/layout2+1.cpp index 989775d71..e99b09291 100644 --- a/radio/src/gui/colorlcd/layouts/layout2+1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2+1.cpp @@ -28,6 +28,8 @@ #define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) #define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) +constexpr coord_t border = 10; + const uint8_t LBM_LAYOUT_2P1[] = { #include "mask_layout2+1.lbm" }; @@ -37,12 +39,6 @@ const ZoneOption OPTIONS_LAYOUT_2P1[] = { LAYOUT_OPTIONS_END }; -const rect_t ZONES_LAYOUT_2P1[3] = { - { 240, 60, 192, 152 }, - { 48, 60, 180, 70 }, - { 48, 142, 180, 70 } -}; - class Layout2P1: public Layout { public: @@ -65,12 +61,27 @@ class Layout2P1: public Layout unsigned int getZonesCount() const override { - return DIM(ZONES_LAYOUT_2P1); + return 3; } rect_t getZone(unsigned int index) const override { - return ZONES_LAYOUT_2P1[index]; + if (IS_MIRRORED()) + index = 2 - index; + + rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); + + if (index == 0) { + return {zone.x, zone.y,zone.w / 2, zone.h}; + } + else if (index == 1) { + return {zone.x + zone.w / 2, zone.y,zone.w / 2, zone.h / 2}; + } + else { + return {zone.x + zone.w / 2, zone.y + zone.h / 2,zone.w / 2, zone.h / 2}; + } + + return zone; } }; From a72f1491de5d7892aee7e29d07ebbfd4b9333728 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 10:47:46 +0200 Subject: [PATCH 09/16] more layouts --- radio/src/gui/colorlcd/layouts/layout2x1.cpp | 19 +++--- radio/src/gui/colorlcd/layouts/layout2x2.cpp | 30 +++++---- radio/src/gui/colorlcd/layouts/layout2x4.cpp | 69 ++++++-------------- 3 files changed, 48 insertions(+), 70 deletions(-) diff --git a/radio/src/gui/colorlcd/layouts/layout2x1.cpp b/radio/src/gui/colorlcd/layouts/layout2x1.cpp index 2e9f1f875..1e1e078ad 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x1.cpp @@ -28,6 +28,8 @@ #define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) #define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) +constexpr coord_t border = 10; + const uint8_t LBM_LAYOUT_2x1[] = { #include "mask_layout2x1.lbm" }; @@ -64,17 +66,18 @@ class Layout2x1: public Layout rect_t getZone(unsigned int index) const override { - rect_t zone; - zone.w = (LCD_W-3*10) / 2; - zone.x = (index & 1) ? 20 + zone.w : 10; - if (persistentData->options[0].value.boolValue) { - zone.h = (LCD_H-MENU_HEADER_HEIGHT-2*10); - zone.y = MENU_HEADER_HEIGHT + 10; + if (IS_MIRRORED()) + index = 1 - index; + + rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); + + if (index == 0) { + return {zone.x, zone.y, zone.w / 2, zone.h}; } else { - zone.h = (LCD_H-2*10); - zone.y = 10; + return {zone.x + zone.w / 2, zone.y, zone.w / 2, zone.h}; } + return zone; } }; diff --git a/radio/src/gui/colorlcd/layouts/layout2x2.cpp b/radio/src/gui/colorlcd/layouts/layout2x2.cpp index 59c346c8e..5ee745a43 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x2.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x2.cpp @@ -28,6 +28,8 @@ #define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) #define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) +constexpr coord_t border = 10; + const uint8_t LBM_LAYOUT_2x2[] = { #include "mask_layout2x2.lbm" }; @@ -64,20 +66,20 @@ class Layout2x2: public Layout rect_t getZone(unsigned int index) const override { - rect_t zone; - zone.w = (LCD_W-3*10) / 2; - zone.x = (index & 1) ? 20 + zone.w : 10; - if (persistentData->options[0].value.boolValue) { - zone.h = (LCD_H-MENU_HEADER_HEIGHT-3*10) / 2; - zone.y = MENU_HEADER_HEIGHT + 10; - } - else { - zone.h = (LCD_H-3*10) / 2; - zone.y = 10; - } - if (index >= 2) { - zone.y += 10 + zone.h; - } + if (IS_MIRRORED()) + index = 3 - index; + + rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); + + zone.w /= 2; + zone.h /= 2; + + if (index == 1 || index == 3) + zone.y += zone.h; + + if (index > 1) + zone.x += zone.w; + return zone; } }; diff --git a/radio/src/gui/colorlcd/layouts/layout2x4.cpp b/radio/src/gui/colorlcd/layouts/layout2x4.cpp index 5a5d183ed..4e04bb9ca 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x4.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x4.cpp @@ -20,6 +20,14 @@ #include "opentx.h" +#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) +#define HAS_FM() (persistentData->options[1].value.boolValue == true) +#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true) +#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) +#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) + +constexpr coord_t border = 10; + const uint8_t LBM_LAYOUT_2x4[] = { #include "mask_layout2x4.lbm" }; @@ -61,56 +69,21 @@ class Layout2x4: public Layout rect_t getZone(unsigned int index) const override { - rect_t zone; - zone.x = (index >= 4) ? 260 : 60; - zone.y = 56 + (index % 4) * 42; - zone.w = 160; - zone.h = 32; + if (IS_MIRRORED()) + index = 7 - index; + + rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); + + zone.w /= 2; + zone.h /= 4; + + if (index > 3) + zone.x += zone.w; + + zone.y += (index % 4) * zone.h; + return zone; } - -// virtual void refresh(); }; -//void Layout2x4::refresh() -//{ -// theme->drawBackground(); -// -// if (persistentData->options[0].value.boolValue) { -// drawTopBar(); -// } -// -// if (persistentData->options[1].value.boolValue) { -// // Flight mode -// lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name, -// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), -// ZCHAR | FONT(XS)) / 2, -// 232, -// g_model.flightModeData[mixerCurrentFlightMode].name, -// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | FONT(XS)); -// } -// -// if (persistentData->options[2].value.boolValue) { -// // Pots and rear sliders positions -// drawMainPots(); -// } -// -// if (persistentData->options[3].value.boolValue) { -// // Trims -// drawTrims(mixerCurrentFlightMode); -// } -// -// if (persistentData->options[4].value.boolValue) { -// lcdSetColor(persistentData->options[5].value.unsignedValue); -// lcdDrawSolidFilledRect(50, 50, 180, 170, CUSTOM_COLOR); -// } -// -// if (persistentData->options[6].value.boolValue) { -// lcdSetColor(persistentData->options[7].value.unsignedValue); -// lcdDrawSolidFilledRect(250, 50, 180, 170, CUSTOM_COLOR); -// } -// -// Layout::refresh(); -//} - BaseLayoutFactory layout2x4("Layout2x4", "2 x 4", LBM_LAYOUT_2x4, OPTIONS_LAYOUT_2x4); From 6239a4000d4a16d43a1e326171a2c346321a7ed1 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 11:13:47 +0200 Subject: [PATCH 10/16] Use new functions --- radio/src/gui/colorlcd/layouts/layout1x1.cpp | 6 ------ radio/src/gui/colorlcd/layouts/layout2+1.cpp | 8 +------- radio/src/gui/colorlcd/layouts/layout2x1.cpp | 8 +------- radio/src/gui/colorlcd/layouts/layout2x2.cpp | 8 +------- radio/src/gui/colorlcd/layouts/layout2x4.cpp | 8 +------- 5 files changed, 4 insertions(+), 34 deletions(-) diff --git a/radio/src/gui/colorlcd/layouts/layout1x1.cpp b/radio/src/gui/colorlcd/layouts/layout1x1.cpp index 13dcf0cd1..e287c1a3f 100644 --- a/radio/src/gui/colorlcd/layouts/layout1x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout1x1.cpp @@ -21,12 +21,6 @@ #include "opentx.h" #include "trims.h" -#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) -#define HAS_FM() (persistentData->options[1].value.boolValue == true) -#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true) -#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) -#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) - constexpr coord_t border = 10; const uint8_t LBM_LAYOUT_1x1[] = { diff --git a/radio/src/gui/colorlcd/layouts/layout2+1.cpp b/radio/src/gui/colorlcd/layouts/layout2+1.cpp index e99b09291..449cc4d82 100644 --- a/radio/src/gui/colorlcd/layouts/layout2+1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2+1.cpp @@ -22,12 +22,6 @@ #include "sliders.h" #include "trims.h" -#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) -#define HAS_FM() (persistentData->options[1].value.boolValue == true) -#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true) -#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) -#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) - constexpr coord_t border = 10; const uint8_t LBM_LAYOUT_2P1[] = { @@ -66,7 +60,7 @@ class Layout2P1: public Layout rect_t getZone(unsigned int index) const override { - if (IS_MIRRORED()) + if (isMirrored()) index = 2 - index; rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); diff --git a/radio/src/gui/colorlcd/layouts/layout2x1.cpp b/radio/src/gui/colorlcd/layouts/layout2x1.cpp index 1e1e078ad..71509cdf6 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x1.cpp @@ -22,12 +22,6 @@ #include "sliders.h" #include "trims.h" -#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) -#define HAS_FM() (persistentData->options[1].value.boolValue == true) -#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true) -#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) -#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) - constexpr coord_t border = 10; const uint8_t LBM_LAYOUT_2x1[] = { @@ -66,7 +60,7 @@ class Layout2x1: public Layout rect_t getZone(unsigned int index) const override { - if (IS_MIRRORED()) + if (isMirrored()) index = 1 - index; rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); diff --git a/radio/src/gui/colorlcd/layouts/layout2x2.cpp b/radio/src/gui/colorlcd/layouts/layout2x2.cpp index 5ee745a43..aba64d808 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x2.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x2.cpp @@ -22,12 +22,6 @@ #include "sliders.h" #include "trims.h" -#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) -#define HAS_FM() (persistentData->options[1].value.boolValue == true) -#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true) -#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) -#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) - constexpr coord_t border = 10; const uint8_t LBM_LAYOUT_2x2[] = { @@ -66,7 +60,7 @@ class Layout2x2: public Layout rect_t getZone(unsigned int index) const override { - if (IS_MIRRORED()) + if (isMirrored()) index = 3 - index; rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); diff --git a/radio/src/gui/colorlcd/layouts/layout2x4.cpp b/radio/src/gui/colorlcd/layouts/layout2x4.cpp index 4e04bb9ca..fbf6a7a81 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x4.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x4.cpp @@ -20,12 +20,6 @@ #include "opentx.h" -#define HAS_TOPBAR() (persistentData->options[0].value.boolValue == true) -#define HAS_FM() (persistentData->options[1].value.boolValue == true) -#define HAS_SLIDERS() (persistentData->options[2].value.boolValue == true) -#define HAS_TRIMS() (persistentData->options[3].value.boolValue == true) -#define IS_MIRRORED() (persistentData->options[4].value.boolValue == true) - constexpr coord_t border = 10; const uint8_t LBM_LAYOUT_2x4[] = { @@ -69,7 +63,7 @@ class Layout2x4: public Layout rect_t getZone(unsigned int index) const override { - if (IS_MIRRORED()) + if (isMirrored()) index = 7 - index; rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); From 88a1ce94d851095291ced74e2485f2f78bfa695d Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 11:56:31 +0200 Subject: [PATCH 11/16] Go straight to add widget when zone is empty --- radio/src/gui/colorlcd/screen_setup.cpp | 34 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/radio/src/gui/colorlcd/screen_setup.cpp b/radio/src/gui/colorlcd/screen_setup.cpp index ca083cbaa..66ddd1b3e 100644 --- a/radio/src/gui/colorlcd/screen_setup.cpp +++ b/radio/src/gui/colorlcd/screen_setup.cpp @@ -158,25 +158,35 @@ class SetupWidgetsPageSlot: public Button { widget = screen->getWidget(slotIndex); setPressHandler([=]() -> uint8_t { - Menu * menu = new Menu(this); - menu->addLine(TR_SELECT_WIDGET, [=]() { - Menu * menu = new Menu(this); - for (auto factory: getRegisteredWidgets()) { - menu->addLine(factory->getName(), [=]() { - if (widget) widget->deleteLater(); - widget = screen->createWidget(slotIndex, factory); - }); - } - }); if (widget) { + Menu * menu = new Menu(this); + menu->addLine(TR_SELECT_WIDGET, [=]() { + Menu * menu = new Menu(this); + for (auto factory: getRegisteredWidgets()) { + menu->addLine(factory->getName(), [=]() { + if (widget) widget->deleteLater(); + widget = screen->createWidget(slotIndex, factory); + }); + } + }); menu->addLine(TR_WIDGET_SETTINGS, [=]() { new WidgetSettings(this, widget); }); menu->addLine(STR_REMOVE_WIDGET, [=]() { - widget->deleteLater(); - widget = nullptr; + widget->deleteLater(); + widget = nullptr; }); + return 0; + } + else { + Menu * menu = new Menu(this); + for (auto factory: getRegisteredWidgets()) { + menu->addLine(factory->getName(), [=]() { + if (widget) widget->deleteLater(); + widget = screen->createWidget(slotIndex, factory); + }); + } } return 0; }); From f9f4155499d008a772e05ee73c82ae6b540125ba Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 14:13:05 +0200 Subject: [PATCH 12/16] Fix layout mirror --- radio/src/gui/colorlcd/layouts/layout2+1.cpp | 9 +++------ radio/src/gui/colorlcd/layouts/layout2x1.cpp | 7 ++----- radio/src/gui/colorlcd/layouts/layout2x2.cpp | 5 +---- radio/src/gui/colorlcd/layouts/layout2x4.cpp | 6 ++---- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/radio/src/gui/colorlcd/layouts/layout2+1.cpp b/radio/src/gui/colorlcd/layouts/layout2+1.cpp index 449cc4d82..85a4a341c 100644 --- a/radio/src/gui/colorlcd/layouts/layout2+1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2+1.cpp @@ -60,19 +60,16 @@ class Layout2P1: public Layout rect_t getZone(unsigned int index) const override { - if (isMirrored()) - index = 2 - index; - rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); if (index == 0) { - return {zone.x, zone.y,zone.w / 2, zone.h}; + return {isMirrored() ? zone.x : zone.x + zone.w / 2, zone.y,zone.w / 2, zone.h}; } else if (index == 1) { - return {zone.x + zone.w / 2, zone.y,zone.w / 2, zone.h / 2}; + return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y,zone.w / 2, zone.h / 2}; } else { - return {zone.x + zone.w / 2, zone.y + zone.h / 2,zone.w / 2, zone.h / 2}; + return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y + zone.h / 2,zone.w / 2, zone.h / 2}; } return zone; diff --git a/radio/src/gui/colorlcd/layouts/layout2x1.cpp b/radio/src/gui/colorlcd/layouts/layout2x1.cpp index 71509cdf6..82887dbec 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x1.cpp @@ -60,16 +60,13 @@ class Layout2x1: public Layout rect_t getZone(unsigned int index) const override { - if (isMirrored()) - index = 1 - index; - rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); if (index == 0) { - return {zone.x, zone.y, zone.w / 2, zone.h}; + return {isMirrored() ? zone.x + zone.w / 2 : zone.x, zone.y, zone.w / 2, zone.h}; } else { - return {zone.x + zone.w / 2, zone.y, zone.w / 2, zone.h}; + return {isMirrored() ? zone.x : zone.x + zone.w / 2, zone.y, zone.w / 2, zone.h}; } return zone; diff --git a/radio/src/gui/colorlcd/layouts/layout2x2.cpp b/radio/src/gui/colorlcd/layouts/layout2x2.cpp index aba64d808..cbf2a1385 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x2.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x2.cpp @@ -60,9 +60,6 @@ class Layout2x2: public Layout rect_t getZone(unsigned int index) const override { - if (isMirrored()) - index = 3 - index; - rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); zone.w /= 2; @@ -71,7 +68,7 @@ class Layout2x2: public Layout if (index == 1 || index == 3) zone.y += zone.h; - if (index > 1) + if ((!isMirrored() && index > 1)) || (isMirrored() && index < 2) zone.x += zone.w; return zone; diff --git a/radio/src/gui/colorlcd/layouts/layout2x4.cpp b/radio/src/gui/colorlcd/layouts/layout2x4.cpp index fbf6a7a81..8cf6ceda5 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x4.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x4.cpp @@ -63,16 +63,14 @@ class Layout2x4: public Layout rect_t getZone(unsigned int index) const override { - if (isMirrored()) - index = 7 - index; - rect_t zone = getMainZone({border, border, LCD_W - 2 * border, LCD_H - 2 * border}); zone.w /= 2; zone.h /= 4; - if (index > 3) + if ((!isMirrored() && index > 3) || (isMirrored() && index < 4)) { zone.x += zone.w; + } zone.y += (index % 4) * zone.h; From d4c172826840257c455c50ebeabdb6e1a00718c2 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 14:14:44 +0200 Subject: [PATCH 13/16] Fix layout mirror --- radio/src/gui/colorlcd/layouts/layout2x2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/gui/colorlcd/layouts/layout2x2.cpp b/radio/src/gui/colorlcd/layouts/layout2x2.cpp index cbf2a1385..7704ee2f7 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x2.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x2.cpp @@ -68,7 +68,7 @@ class Layout2x2: public Layout if (index == 1 || index == 3) zone.y += zone.h; - if ((!isMirrored() && index > 1)) || (isMirrored() && index < 2) + if ((!isMirrored() && index > 1) || (isMirrored() && index < 2)) zone.x += zone.w; return zone; From 979a498093ff792e79de352baceaffab67dcff0a Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 17:00:26 +0200 Subject: [PATCH 14/16] Add ScreenUserPage (content tbd) --- radio/src/gui/colorlcd/menu_screen.cpp | 3 ++- radio/src/gui/colorlcd/screen_setup.cpp | 10 ++++++++++ radio/src/gui/colorlcd/screen_setup.h | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/colorlcd/menu_screen.cpp b/radio/src/gui/colorlcd/menu_screen.cpp index 330ddbedf..f3f896407 100644 --- a/radio/src/gui/colorlcd/menu_screen.cpp +++ b/radio/src/gui/colorlcd/menu_screen.cpp @@ -32,9 +32,10 @@ void ScreenMenu::updateTabs() { removeAllTabs(); + addTab(new ScreenUserPage()); + for (int index = 0; index < MAX_CUSTOM_SCREENS; index++) { if (customScreens[index]) { - auto tab = new ScreenSetupPage(this, customScreens[index], g_model.screenData[index]); std::string title(STR_MAIN_VIEW_X); title.back() = index + '1'; diff --git a/radio/src/gui/colorlcd/screen_setup.cpp b/radio/src/gui/colorlcd/screen_setup.cpp index 66ddd1b3e..f5b8e8a88 100644 --- a/radio/src/gui/colorlcd/screen_setup.cpp +++ b/radio/src/gui/colorlcd/screen_setup.cpp @@ -26,6 +26,16 @@ #define SET_DIRTY() storageDirty(EE_MODEL) +ScreenUserPage::ScreenUserPage(): + PageTab(STR_USER_INTERFACE, ICON_THEME_SETUP) +{ +} + +void ScreenUserPage::build(FormWindow * window) +{ + +} + ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex): PageTab(), menu(menu), diff --git a/radio/src/gui/colorlcd/screen_setup.h b/radio/src/gui/colorlcd/screen_setup.h index d8372ffb6..c68296016 100644 --- a/radio/src/gui/colorlcd/screen_setup.h +++ b/radio/src/gui/colorlcd/screen_setup.h @@ -22,6 +22,15 @@ #include "layout.h" #include "datastructs.h" +class ScreenUserPage: public PageTab { + public: + ScreenUserPage(); + + void build(FormWindow * window) override; + + protected: +}; + class ScreenAddPage: public PageTab { public: ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex); From 463216ebcac513bf8d699b695ba542ae628d39a0 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 6 Apr 2021 18:20:26 +0200 Subject: [PATCH 15/16] Cosmetics --- radio/src/gui/colorlcd/menu_screen.cpp | 2 +- radio/src/gui/colorlcd/screen_setup.cpp | 16 ++++++++++++++-- radio/src/gui/colorlcd/screen_setup.h | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/radio/src/gui/colorlcd/menu_screen.cpp b/radio/src/gui/colorlcd/menu_screen.cpp index f3f896407..5dc29a2c8 100644 --- a/radio/src/gui/colorlcd/menu_screen.cpp +++ b/radio/src/gui/colorlcd/menu_screen.cpp @@ -32,7 +32,7 @@ void ScreenMenu::updateTabs() { removeAllTabs(); - addTab(new ScreenUserPage()); + addTab(new ScreenUserInterfacePage()); for (int index = 0; index < MAX_CUSTOM_SCREENS; index++) { if (customScreens[index]) { diff --git a/radio/src/gui/colorlcd/screen_setup.cpp b/radio/src/gui/colorlcd/screen_setup.cpp index f5b8e8a88..9a586003a 100644 --- a/radio/src/gui/colorlcd/screen_setup.cpp +++ b/radio/src/gui/colorlcd/screen_setup.cpp @@ -26,14 +26,26 @@ #define SET_DIRTY() storageDirty(EE_MODEL) -ScreenUserPage::ScreenUserPage(): +ScreenUserInterfacePage::ScreenUserInterfacePage(): PageTab(STR_USER_INTERFACE, ICON_THEME_SETUP) { } -void ScreenUserPage::build(FormWindow * window) +void ScreenUserInterfacePage::build(FormWindow * window) { + FormGridLayout grid; + // Theme choice + new StaticText(window, grid.getLabelSlot(), STR_THEME, 0, 0); + // TODO: Theme picklist + grid.nextLine(); + + // Theme options ? + + // Top Bar + new StaticText(window, grid.getLabelSlot(), STR_TOP_BAR, 0, 0); + // TODO: enable settings topbar widgets + grid.nextLine(); } ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex): diff --git a/radio/src/gui/colorlcd/screen_setup.h b/radio/src/gui/colorlcd/screen_setup.h index c68296016..a17f714cc 100644 --- a/radio/src/gui/colorlcd/screen_setup.h +++ b/radio/src/gui/colorlcd/screen_setup.h @@ -22,9 +22,9 @@ #include "layout.h" #include "datastructs.h" -class ScreenUserPage: public PageTab { +class ScreenUserInterfacePage: public PageTab { public: - ScreenUserPage(); + ScreenUserInterfacePage(); void build(FormWindow * window) override; From 28026f1a7899df5b51a049f8120b0d534d3dbf2e Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 7 Apr 2021 08:20:30 +0200 Subject: [PATCH 16/16] further unified layout options --- radio/src/gui/colorlcd/layout.h | 14 +++++++++++++- radio/src/gui/colorlcd/layouts/layout1x1.cpp | 15 --------------- radio/src/gui/colorlcd/layouts/layout2+1.cpp | 12 ------------ radio/src/gui/colorlcd/layouts/layout2x1.cpp | 12 ------------ radio/src/gui/colorlcd/layouts/layout2x2.cpp | 12 ------------ radio/src/gui/colorlcd/layouts/layout2x4.cpp | 20 ++++++++++++-------- radio/src/gui/colorlcd/widgets_container.h | 5 +++++ 7 files changed, 30 insertions(+), 60 deletions(-) diff --git a/radio/src/gui/colorlcd/layout.h b/radio/src/gui/colorlcd/layout.h index b387c2fb6..bdaf18c30 100644 --- a/radio/src/gui/colorlcd/layout.h +++ b/radio/src/gui/colorlcd/layout.h @@ -56,7 +56,9 @@ class Layout: public LayoutBase OPTION_FM, OPTION_SLIDERS, OPTION_TRIMS, - OPTION_MIRRORED + OPTION_MIRRORED, + + OPTION_LAST_DEFAULT=OPTION_MIRRORED }; Layout(const LayoutFactory * factory, PersistentData * persistentData): @@ -66,6 +68,16 @@ class Layout: public LayoutBase decorate(); } + void create() override + { + setOptionValue(OPTION_TOPBAR, OPTION_VALUE_BOOL(true)); + setOptionValue(OPTION_FM, OPTION_VALUE_BOOL(true)); + setOptionValue(OPTION_SLIDERS, OPTION_VALUE_BOOL(true)); + setOptionValue(OPTION_TRIMS, OPTION_VALUE_BOOL(true)); + setOptionValue(OPTION_MIRRORED, OPTION_VALUE_BOOL(false)); + decorate(); + } + inline const LayoutFactory * getFactory() const { return factory; diff --git a/radio/src/gui/colorlcd/layouts/layout1x1.cpp b/radio/src/gui/colorlcd/layouts/layout1x1.cpp index e287c1a3f..ee641b530 100644 --- a/radio/src/gui/colorlcd/layouts/layout1x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout1x1.cpp @@ -40,21 +40,6 @@ class Layout1x1: public Layout { } - void create() override - { - Layout::create(); - // TODO: make this common to all layouts as well - persistentData->options[0].value.boolValue = true; - persistentData->options[1].value.boolValue = true; - persistentData->options[2].value.boolValue = true; - persistentData->options[3].value.boolValue = true; - persistentData->options[4].value.boolValue = false; - persistentData->options[5].value.boolValue = false; - - // TODO: really needed? - decorate(); - } - unsigned int getZonesCount() const override { return 1; diff --git a/radio/src/gui/colorlcd/layouts/layout2+1.cpp b/radio/src/gui/colorlcd/layouts/layout2+1.cpp index 85a4a341c..dddd3f5f8 100644 --- a/radio/src/gui/colorlcd/layouts/layout2+1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2+1.cpp @@ -41,18 +41,6 @@ class Layout2P1: public Layout { } - void create() override - { - Layout::create(); - persistentData->options[0].value.boolValue = true; - persistentData->options[1].value.boolValue = true; - persistentData->options[2].value.boolValue = true; - persistentData->options[3].value.boolValue = true; - persistentData->options[4].value.boolValue = false; - persistentData->options[5].value.boolValue = false; - decorate(); - } - unsigned int getZonesCount() const override { return 3; diff --git a/radio/src/gui/colorlcd/layouts/layout2x1.cpp b/radio/src/gui/colorlcd/layouts/layout2x1.cpp index 82887dbec..7db4f8c02 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x1.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x1.cpp @@ -41,18 +41,6 @@ class Layout2x1: public Layout { } - void create() override - { - Layout::create(); - persistentData->options[0].value.boolValue = true; - persistentData->options[1].value.boolValue = true; - persistentData->options[2].value.boolValue = true; - persistentData->options[3].value.boolValue = true; - persistentData->options[4].value.boolValue = false; - persistentData->options[5].value.boolValue = false; - decorate(); - } - unsigned int getZonesCount() const override { return 2; diff --git a/radio/src/gui/colorlcd/layouts/layout2x2.cpp b/radio/src/gui/colorlcd/layouts/layout2x2.cpp index 7704ee2f7..05d973b62 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x2.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x2.cpp @@ -41,18 +41,6 @@ class Layout2x2: public Layout { } - void create() override - { - Layout::create(); - persistentData->options[0].value.boolValue = true; - persistentData->options[1].value.boolValue = true; - persistentData->options[2].value.boolValue = true; - persistentData->options[3].value.boolValue = true; - persistentData->options[4].value.boolValue = false; - persistentData->options[5].value.boolValue = false; - decorate(); - } - unsigned int getZonesCount() const override { return 4; diff --git a/radio/src/gui/colorlcd/layouts/layout2x4.cpp b/radio/src/gui/colorlcd/layouts/layout2x4.cpp index 8cf6ceda5..b08009f83 100644 --- a/radio/src/gui/colorlcd/layouts/layout2x4.cpp +++ b/radio/src/gui/colorlcd/layouts/layout2x4.cpp @@ -38,6 +38,14 @@ const ZoneOption OPTIONS_LAYOUT_2x4[] = { class Layout2x4: public Layout { public: + + enum { + OPTION_PANEL1_BACKGROUND = OPTION_LAST_DEFAULT + 1, + OPTION_PANEL1_COLOR, + OPTION_PANEL2_BACKGROUND, + OPTION_PANEL2_COLOR + }; + Layout2x4(const LayoutFactory * factory, Layout::PersistentData * persistentData): Layout(factory, persistentData) { @@ -46,14 +54,10 @@ class Layout2x4: public Layout void create() override { Layout::create(); - persistentData->options[0] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; - persistentData->options[1] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; - persistentData->options[2] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; - persistentData->options[3] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; - persistentData->options[4] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; - persistentData->options[5] = ZoneOptionValueTyped { ZOV_Unsigned, OPTION_VALUE_UNSIGNED( RGB(77,112,203)) }; - persistentData->options[6] = ZoneOptionValueTyped { ZOV_Bool, OPTION_VALUE_BOOL(true) }; - persistentData->options[7] = ZoneOptionValueTyped { ZOV_Unsigned, OPTION_VALUE_UNSIGNED( RGB(77,112,203)) }; + setOptionValue(OPTION_PANEL1_BACKGROUND, OPTION_VALUE_BOOL(true)); + setOptionValue(OPTION_PANEL1_COLOR, OPTION_VALUE_UNSIGNED( RGB(77,112,203))); + setOptionValue(OPTION_PANEL2_BACKGROUND, OPTION_VALUE_BOOL(true)); + setOptionValue(OPTION_PANEL2_COLOR, OPTION_VALUE_UNSIGNED( RGB(77,112,203))); } unsigned int getZonesCount() const override diff --git a/radio/src/gui/colorlcd/widgets_container.h b/radio/src/gui/colorlcd/widgets_container.h index d1f020a5d..44302ba57 100644 --- a/radio/src/gui/colorlcd/widgets_container.h +++ b/radio/src/gui/colorlcd/widgets_container.h @@ -104,6 +104,11 @@ class WidgetsContainer: public FormGroup, public WidgetsContainerInterface return &persistentData->options[index].value; } + inline void setOptionValue(unsigned int index, const ZoneOptionValue& value) + { + persistentData->options[index].value = value; + } + unsigned int getZonesCount() const override = 0; rect_t getZone(unsigned int index) const override = 0;