fix(ui): Update flight mode color on startup/theme edited/theme changed (#2928)
This commit is contained in:
@@ -81,6 +81,14 @@ void Layout::setFlightModeVisible(bool visible)
|
|||||||
decoration->setFlightModeVisible(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()
|
void Layout::adjustLayout()
|
||||||
{
|
{
|
||||||
// Check if deco setting are still up-to-date
|
// Check if deco setting are still up-to-date
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ class Layout: public LayoutBase
|
|||||||
void setSlidersVisible(bool visible);
|
void setSlidersVisible(bool visible);
|
||||||
void setFlightModeVisible(bool visible);
|
void setFlightModeVisible(bool visible);
|
||||||
|
|
||||||
|
// Update from theme settings
|
||||||
|
void updateFromTheme() override;
|
||||||
|
|
||||||
// Updates settings for trims, sliders, pots, etc...
|
// Updates settings for trims, sliders, pots, etc...
|
||||||
void adjustLayout() override;
|
void adjustLayout() override;
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
#include "theme_manager.h"
|
#include "theme_manager.h"
|
||||||
|
#include "view_main.h"
|
||||||
|
|
||||||
#define MAX_FILES 9
|
#define MAX_FILES 9
|
||||||
ThemePersistance themePersistance;
|
ThemePersistance themePersistance;
|
||||||
@@ -327,6 +328,12 @@ void ThemeFile::applyTheme()
|
|||||||
applyColors();
|
applyColors();
|
||||||
applyBackground();
|
applyBackground();
|
||||||
OpenTxTheme::instance()->update(false);
|
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
|
// avoid leaking memory
|
||||||
|
|||||||
@@ -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)
|
void ViewMain::onEvent(event_t event)
|
||||||
{
|
{
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ class ViewMain: public Window
|
|||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ViewMain* getInstance() { return _instance; }
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override
|
std::string getName() const override
|
||||||
{
|
{
|
||||||
@@ -60,6 +62,9 @@ class ViewMain: public Window
|
|||||||
void updateTopbarVisibility();
|
void updateTopbarVisibility();
|
||||||
bool enableWidgetSelect(bool enable);
|
bool enableWidgetSelect(bool enable);
|
||||||
|
|
||||||
|
// Update after theme loaded / changed
|
||||||
|
void updateFromTheme();
|
||||||
|
|
||||||
// Get the available space in the middle of the screen
|
// Get the available space in the middle of the screen
|
||||||
// (without topbar)
|
// (without topbar)
|
||||||
rect_t getMainZone(rect_t zone, bool hasTopbar) const;
|
rect_t getMainZone(rect_t zone, bool hasTopbar) const;
|
||||||
|
|||||||
@@ -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
|
rect_t ViewMainDecoration::getMainZone() const
|
||||||
{
|
{
|
||||||
// update layout first
|
// update layout first
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class ViewMainDecoration
|
|||||||
void setTrimsVisible(bool visible);
|
void setTrimsVisible(bool visible);
|
||||||
void setSlidersVisible(bool visible);
|
void setSlidersVisible(bool visible);
|
||||||
void setFlightModeVisible(bool visible);
|
void setFlightModeVisible(bool visible);
|
||||||
|
void setFlightModeColor();
|
||||||
|
|
||||||
// Get the available space in the middle of the screen
|
// Get the available space in the middle of the screen
|
||||||
// (without decoration)
|
// (without decoration)
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ class WidgetsContainerImpl : public WidgetsContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
void adjustLayout() override {}
|
void adjustLayout() override {}
|
||||||
|
void updateFromTheme() override {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PersistentData* persistentData;
|
PersistentData* persistentData;
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class WidgetsContainer: public Window
|
|||||||
virtual void removeWidget(unsigned int index) = 0;
|
virtual void removeWidget(unsigned int index) = 0;
|
||||||
virtual void adjustLayout() = 0;
|
virtual void adjustLayout() = 0;
|
||||||
virtual void updateZones() = 0;
|
virtual void updateZones() = 0;
|
||||||
|
virtual void updateFromTheme() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user