fix(color): issues with main view UI (#5659)

This commit is contained in:
philmoz
2024-11-19 10:42:16 +10:00
committed by GitHub
parent f0522f8b38
commit 2150ac46e7
7 changed files with 85 additions and 66 deletions
@@ -338,7 +338,13 @@ void ScreenSetupPage::buildLayoutOptions()
// Option value // Option value
switch (option->type) { switch (option->type) {
case ZoneOption::Bool: case ZoneOption::Bool:
new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(value->boolValue)); new ToggleSwitch(line, rect_t{},
GET_DEFAULT(value->boolValue),
[=](int newValue) {
value->boolValue = newValue;
customScreens[customScreenIndex]->show();
SET_DIRTY();
});
break; break;
case ZoneOption::Color: case ZoneOption::Color:
+14 -10
View File
@@ -85,6 +85,20 @@ void TopBar::setVisible(float visible) // 0.0 -> 1.0
} }
} }
void TopBar::setEdgeTxButtonVisible(float visible) // 0.0 -> 1.0
{
if (visible == 0.0) {
headerIcon->setTop(-(int)EdgeTxStyles::MENU_HEADER_HEIGHT);
}
else if (visible == 1.0) {
headerIcon->setTop(0);
}
else if (visible > 0.0 && visible < 1.0){
float top = - (float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
headerIcon->setTop((coord_t)top);
}
}
coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0 coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
{ {
if (visible == 0.0) { if (visible == 0.0) {
@@ -98,16 +112,6 @@ coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
return (coord_t)h; return (coord_t)h;
} }
void TopBar::showEdgeTxButton()
{
headerIcon->show();
}
void TopBar::hideEdgeTxButton()
{
headerIcon->hide();
}
void TopBar::checkEvents() void TopBar::checkEvents()
{ {
uint32_t now = RTOS_GET_MS(); uint32_t now = RTOS_GET_MS();
@@ -50,9 +50,8 @@ class TopBar: public TopBarBase
rect_t getZone(unsigned int index) const override; rect_t getZone(unsigned int index) const override;
void setVisible(float visible); void setVisible(float visible);
void setEdgeTxButtonVisible(float visible);
coord_t getVisibleHeight(float visible) const; // 0.0 -> 1.0 coord_t getVisibleHeight(float visible) const; // 0.0 -> 1.0
void showEdgeTxButton();
void hideEdgeTxButton();
void checkEvents() override; void checkEvents() override;
+60 -38
View File
@@ -116,6 +116,7 @@ void ViewMain::addMainView(WidgetsContainer* view, uint32_t viewId)
} }
void ViewMain::setTopbarVisible(float visible) { topbar->setVisible(visible); } void ViewMain::setTopbarVisible(float visible) { topbar->setVisible(visible); }
void ViewMain::setEdgeTxButtonVisible(float visible) { topbar->setEdgeTxButtonVisible(visible); }
unsigned ViewMain::getMainViewsCount() const unsigned ViewMain::getMainViewsCount() const
{ {
@@ -169,16 +170,6 @@ void ViewMain::previousMainView()
TopBar* ViewMain::getTopbar() { return topbar; } TopBar* ViewMain::getTopbar() { return topbar; }
static bool hasTopbar(unsigned view)
{
if (view < sizeof(g_model.screenData)) {
const auto& layoutData = g_model.screenData[view].layoutData;
return layoutData.options[LAYOUT_OPTION_TOPBAR].value.boolValue;
}
return false;
}
void ViewMain::enableTopbar() void ViewMain::enableTopbar()
{ {
if (topbar) topbar->show(); if (topbar) topbar->show();
@@ -200,28 +191,51 @@ void ViewMain::updateTopbarVisibility()
int leftScroll = scrollPos % width(); int leftScroll = scrollPos % width();
if (leftScroll == 0) { if (leftScroll == 0) {
int view = scrollPos / pageWidth; int view = scrollPos / pageWidth;
setTopbarVisible(::hasTopbar(view)); setTopbarVisible(hasTopbar(view));
setEdgeTxButtonVisible(hasTopbar(view) || isAppMode(view));
if (customScreens[view]) customScreens[view]->adjustLayout(); if (customScreens[view]) customScreens[view]->adjustLayout();
} else { } else {
int leftIdx = scrollPos / pageWidth; int leftIdx = scrollPos / pageWidth;
bool leftTopbar = ::hasTopbar(leftIdx); bool leftTopbar = hasTopbar(leftIdx);
bool rightTopbar = ::hasTopbar(leftIdx + 1); bool rightTopbar = hasTopbar(leftIdx + 1);
if (leftTopbar != rightTopbar) { float ratio;
float ratio = (float)leftScroll / (float)pageWidth;
if (leftTopbar) { if (leftTopbar && rightTopbar) {
// scrolling from a screen with Topbar ratio = 1.0;
ratio = 1.0 - ratio; } else if (leftTopbar) {
} else { // scrolling from a screen with Topbar
// scrolling to a screen with Topbar ratio = 1.0 - (float)leftScroll / (float)pageWidth;
// -> ratio is ok } else if (rightTopbar) {
} // scrolling to a screen with Topbar
ratio = (float)leftScroll / (float)pageWidth;
setTopbarVisible(ratio); } else {
customScreens[leftIdx]->adjustLayout(); ratio = 0.0;
customScreens[leftIdx + 1]->adjustLayout();
} }
setTopbarVisible(ratio);
leftTopbar = hasTopbar(leftIdx) || isAppMode(leftIdx);
rightTopbar = hasTopbar(leftIdx + 1) || isAppMode(leftIdx + 1);
ratio = (float)leftScroll / (float)pageWidth;
if (leftTopbar && rightTopbar) {
ratio = 1.0;
} else if (leftTopbar) {
// scrolling from a screen with Topbar
ratio = 1.0 - (float)leftScroll / (float)pageWidth;
} else if (rightTopbar) {
// scrolling to a screen with Topbar
ratio = (float)leftScroll / (float)pageWidth;
} else {
ratio = 0.0;
}
setEdgeTxButtonVisible(ratio);
customScreens[leftIdx]->adjustLayout();
customScreens[leftIdx + 1]->adjustLayout();
} }
} }
@@ -359,11 +373,8 @@ void ViewMain::show(bool visible)
if (deleted()) return; if (deleted()) return;
isVisible = visible; isVisible = visible;
int view = getCurrentMainView(); int view = getCurrentMainView();
setTopbarVisible(visible && ::hasTopbar(view)); setTopbarVisible(visible && hasTopbar(view));
if (visible && (::hasTopbar(view) || isAppMode())) setEdgeTxButtonVisible(visible && (hasTopbar(view) || isAppMode()));
topbar->showEdgeTxButton();
else
topbar->hideEdgeTxButton();
if (customScreens[view]) { if (customScreens[view]) {
customScreens[view]->show(visible); customScreens[view]->show(visible);
customScreens[view]->showWidgets(visible); customScreens[view]->showWidgets(visible);
@@ -372,25 +383,36 @@ void ViewMain::show(bool visible)
bool ViewMain::isAppMode() bool ViewMain::isAppMode()
{ {
int view = getCurrentMainView(); return isAppMode(getCurrentMainView());
if (!customScreens[view]) return false; }
return ((Layout*)customScreens[view])->isAppMode();
bool ViewMain::isAppMode(unsigned view)
{
if (view < MAX_CUSTOM_SCREENS && customScreens[view])
return ((Layout*)customScreens[view])->isAppMode();
return false;
} }
bool ViewMain::hasTopbar() bool ViewMain::hasTopbar()
{ {
int view = getCurrentMainView(); return hasTopbar(getCurrentMainView());
return ::hasTopbar(view); }
bool ViewMain::hasTopbar(unsigned view)
{
if (view < MAX_CUSTOM_SCREENS)
return g_model.screenData[view].layoutData.options[LAYOUT_OPTION_TOPBAR].value.boolValue;
return false;
} }
void ViewMain::showTopBarEdgeTxButton() void ViewMain::showTopBarEdgeTxButton()
{ {
topbar->showEdgeTxButton(); topbar->setEdgeTxButtonVisible(hasTopbar() || isAppMode());
} }
void ViewMain::hideTopBarEdgeTxButton() void ViewMain::hideTopBarEdgeTxButton()
{ {
topbar->hideEdgeTxButton(); topbar->setEdgeTxButtonVisible(0.0);
} }
void ViewMain::runBackground() void ViewMain::runBackground()
@@ -80,7 +80,9 @@ class ViewMain : public NavWindow
void hideTopBarEdgeTxButton(); void hideTopBarEdgeTxButton();
bool hasTopbar(); bool hasTopbar();
bool hasTopbar(unsigned view);
bool isAppMode(); bool isAppMode();
bool isAppMode(unsigned view);
void runBackground(); void runBackground();
void refreshWidgetSelectTimer(); void refreshWidgetSelectTimer();
@@ -103,6 +105,7 @@ class ViewMain : public NavWindow
// Set topbar visibility [0.0 -> 1.0] // Set topbar visibility [0.0 -> 1.0]
void setTopbarVisible(float visible); void setTopbarVisible(float visible);
void setEdgeTxButtonVisible(float visible);
static void ws_timer(lv_timer_t* t); static void ws_timer(lv_timer_t* t);
-9
View File
@@ -51,15 +51,6 @@ class Widget : public ButtonBase
return &persistentData->options[index].value; return &persistentData->options[index].value;
} }
//
// TODO: for some reason, this one crashes on the radio...
//
// inline void setOptionValue(unsigned int index, const ZoneOptionValue&
// value)
// {
// persistentData->options[index].value = value;
// }
PersistentData* getPersistentData() { return persistentData; } PersistentData* getPersistentData() { return persistentData; }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
@@ -111,12 +111,6 @@ class WidgetsContainerImpl : public WidgetsContainer
return &persistentData->options[index].value; return &persistentData->options[index].value;
} }
inline void setOptionValue(unsigned int index, const ZoneOptionValue& value)
{
persistentData->options[index].value = value;
adjustLayout();
}
unsigned int getZonesCount() const override = 0; unsigned int getZonesCount() const override = 0;
rect_t getZone(unsigned int index) const override = 0; rect_t getZone(unsigned int index) const override = 0;