fix(ui): Update flight mode color on startup/theme edited/theme changed (#2928)

This commit is contained in:
philmoz
2022-12-23 11:08:22 +10:00
committed by GitHub
parent 3f08af6120
commit f8f2258a79
9 changed files with 45 additions and 1 deletions
@@ -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
@@ -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;
+7
View File
@@ -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;
@@ -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
+9
View File
@@ -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)
+5
View File
@@ -46,6 +46,8 @@ class ViewMain: public Window
return _instance;
}
static ViewMain* getInstance() { return _instance; }
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
@@ -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)
@@ -98,6 +98,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
@@ -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)
@@ -141,6 +141,7 @@ class WidgetsContainerImpl : public WidgetsContainer
}
void adjustLayout() override {}
void updateFromTheme() override {};
protected:
PersistentData* persistentData;
@@ -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;
};