From 943b1e7cd0d7c0cd944adb8b9d5d10a3d2239608 Mon Sep 17 00:00:00 2001 From: philmoz Date: Sun, 1 Jan 2023 12:11:59 +1100 Subject: [PATCH] fix(color): Fix single widget layout size, improve code readability (#2962) --- .../src/gui/colorlcd/layouts/layout_factory_impl.cpp | 12 ++++++------ radio/src/gui/colorlcd/layouts/layout_factory_impl.h | 12 +++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp b/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp index b92e0fed8..90c9c46f4 100644 --- a/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp +++ b/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp @@ -93,11 +93,11 @@ void Layout::adjustLayout() { // Check if deco setting are still up-to-date uint8_t checkSettings = - (hasTopbar() ? 1 << 0 : 0) | - (hasSliders() ? 1 << 1 : 0) | - (hasTrims() ? 1 << 2 : 0) | - (hasFlightMode() ? 1 << 3 : 0) | - (isMirrored() ? 1 << 4 : 0); + (hasTopbar() ? DECORATION_TOPBAR : 0) | + (hasSliders() ? DECORATION_SLIDERS : 0) | + (hasTrims() ? DECORATION_TRIMS : 0) | + (hasFlightMode() ? DECORATION_FLIGHTMODE : 0) | + (isMirrored() ? DECORATION_MIRRORED : 0); if (checkSettings == decorationSettings) { // everything ok, exit! @@ -119,7 +119,7 @@ void Layout::adjustLayout() rect_t Layout::getMainZone() const { rect_t zone = decoration->getMainZone(); - if (decorationSettings & 0x7) { + if (decorationSettings & (DECORATION_SLIDERS|DECORATION_TRIMS|DECORATION_FLIGHTMODE)) { // some decoration activated zone.x += MAIN_ZONE_BORDER; zone.y += MAIN_ZONE_BORDER; diff --git a/radio/src/gui/colorlcd/layouts/layout_factory_impl.h b/radio/src/gui/colorlcd/layouts/layout_factory_impl.h index 0d4f8e49c..82ad59e59 100644 --- a/radio/src/gui/colorlcd/layouts/layout_factory_impl.h +++ b/radio/src/gui/colorlcd/layouts/layout_factory_impl.h @@ -105,8 +105,18 @@ class Layout: public LayoutBase const LayoutFactory * factory = nullptr; std::unique_ptr decoration; + enum DecorationSettings { + DECORATION_NONE = 0x00, + DECORATION_TOPBAR = 0x01, + DECORATION_SLIDERS = 0x02, + DECORATION_TRIMS = 0x04, + DECORATION_FLIGHTMODE = 0x08, + DECORATION_MIRRORED = 0x10, + DECORATION_UNKNOWN = 0xFF + }; + // Decoration settings bitmask to detect updates - uint8_t decorationSettings = 255; + uint8_t decorationSettings = DECORATION_UNKNOWN; // Last time we refreshed the window uint32_t lastRefresh = 0;