Skip to content

Commit

Permalink
Fix flight mode color on startup, or when theme is edited or when act…
Browse files Browse the repository at this point in the history
…ive theme is changed.
  • Loading branch information
Phil Mitchell committed Dec 22, 2022
1 parent 8eb5545 commit cb77ec6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 1 deletion.
8 changes: 8 additions & 0 deletions radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ void Layout::setFlightModeVisible(bool visible)
decoration->setFlightModeVisible(visible);
}

void Layout::updateFromTheme()
{
// Hack to fix flight mode color on main view
// Required because theme is loaded after the main view has been created
if (decoration)
decoration->setFlightModeColor();
}

void Layout::adjustLayout()
{
// Check if deco setting are still up-to-date
Expand Down
3 changes: 3 additions & 0 deletions radio/src/gui/colorlcd/layouts/layout_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class Layout: public LayoutBase
void setSlidersVisible(bool visible);
void setFlightModeVisible(bool visible);

// Update from theme settings
void updateFromTheme() override;

// Updates settings for trims, sliders, pots, etc...
void adjustLayout() override;

Expand Down
7 changes: 7 additions & 0 deletions radio/src/gui/colorlcd/theme_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* GNU General Public License for more details.
*/
#include "theme_manager.h"
#include "view_main.h"

#define MAX_FILES 9
ThemePersistance themePersistance;
Expand Down Expand Up @@ -327,6 +328,12 @@ void ThemeFile::applyTheme()
applyColors();
applyBackground();
OpenTxTheme::instance()->update(false);

// Update views with new theme
// Currently, on startup, active theme is loaded after ViewMain is created so ViewMain instance is defined
// In case this changes, we call getInstance() here to avoid creating ViewMain
if (ViewMain::getInstance())
ViewMain::getInstance()->updateFromTheme();
}

// avoid leaking memory
Expand Down
9 changes: 9 additions & 0 deletions radio/src/gui/colorlcd/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ void ViewMain::updateTopbarVisibility()
}
}

// Update screens after theme loaded / changed
void ViewMain::updateFromTheme()
{
for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) {
if (customScreens[i])
customScreens[i]->updateFromTheme();
}
}

void ViewMain::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS)
Expand Down
5 changes: 5 additions & 0 deletions radio/src/gui/colorlcd/view_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ViewMain: public Window
return _instance;
}

static ViewMain* getInstance() { return _instance; }

#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
Expand All @@ -59,6 +61,9 @@ class ViewMain: public Window
void disableTopbar();
void updateTopbarVisibility();
bool enableWidgetSelect(bool enable);

// Update after theme loaded / changed
void updateFromTheme();

// Get the available space in the middle of the screen
// (without topbar)
Expand Down
10 changes: 10 additions & 0 deletions radio/src/gui/colorlcd/view_main_decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ void ViewMainDecoration::setFlightModeVisible(bool visible)
}
}

void ViewMainDecoration::setFlightModeColor()
{
// Hack to fix flight mode color on main view
// Required because theme is loaded after the main view has been created
if (flightMode) {
lv_obj_set_style_text_color(flightMode->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY1), 0);
flightMode->invalidate();
}
}

rect_t ViewMainDecoration::getMainZone() const
{
// update layout first
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/view_main_decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ViewMainDecoration
void setTrimsVisible(bool visible);
void setSlidersVisible(bool visible);
void setFlightModeVisible(bool visible);

void setFlightModeColor();

// Get the available space in the middle of the screen
// (without decoration)
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/widgets/widgets_container_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class WidgetsContainerImpl : public WidgetsContainer
}

void adjustLayout() override {}
void updateFromTheme() override {};

protected:
PersistentData* persistentData;
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/widgets_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class WidgetsContainer: public Window
virtual void removeWidget(unsigned int index) = 0;
virtual void adjustLayout() = 0;
virtual void updateZones() = 0;
virtual void updateFromTheme() = 0;
};


Expand Down

0 comments on commit cb77ec6

Please sign in to comment.