From dd21df8c7f663da4bf5053767928615616a4eb4b Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Tue, 6 Apr 2021 08:47:09 +0200 Subject: [PATCH 1/6] [Checkbox] Fix when disabled --- radio/src/thirdparty/libopenui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index a106ff4ff..17029da9d 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit a106ff4ff7b0437fbd9b43c24546df93049f3e57 +Subproject commit 17029da9d7fb6b2c31b417131fd1118e63300b04 From ab138debe1c3cc8d73f53565cd46ed8d20c721b9 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 6 Apr 2021 09:19:59 +0200 Subject: [PATCH 2/6] updated libopenui --- radio/src/thirdparty/libopenui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index 17029da9d..bf5632d53 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit 17029da9d7fb6b2c31b417131fd1118e63300b04 +Subproject commit bf5632d53b93b9d4cf103a0e5339c0c5486d7392 From 5c8448a696014ccd7670ea3a82e6b849ecb43035 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 5 Apr 2021 18:04:12 +0200 Subject: [PATCH 3/6] 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 4/6] 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 5/6] 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 6/6] 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*/