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
switch (option->type) {
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;
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
{
if (visible == 0.0) {
@@ -98,16 +112,6 @@ coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
return (coord_t)h;
}
void TopBar::showEdgeTxButton()
{
headerIcon->show();
}
void TopBar::hideEdgeTxButton()
{
headerIcon->hide();
}
void TopBar::checkEvents()
{
uint32_t now = RTOS_GET_MS();
@@ -50,9 +50,8 @@ class TopBar: public TopBarBase
rect_t getZone(unsigned int index) const override;
void setVisible(float visible);
void setEdgeTxButtonVisible(float visible);
coord_t getVisibleHeight(float visible) const; // 0.0 -> 1.0
void showEdgeTxButton();
void hideEdgeTxButton();
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::setEdgeTxButtonVisible(float visible) { topbar->setEdgeTxButtonVisible(visible); }
unsigned ViewMain::getMainViewsCount() const
{
@@ -169,16 +170,6 @@ void ViewMain::previousMainView()
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()
{
if (topbar) topbar->show();
@@ -200,28 +191,51 @@ void ViewMain::updateTopbarVisibility()
int leftScroll = scrollPos % width();
if (leftScroll == 0) {
int view = scrollPos / pageWidth;
setTopbarVisible(::hasTopbar(view));
setTopbarVisible(hasTopbar(view));
setEdgeTxButtonVisible(hasTopbar(view) || isAppMode(view));
if (customScreens[view]) customScreens[view]->adjustLayout();
} else {
int leftIdx = scrollPos / pageWidth;
bool leftTopbar = ::hasTopbar(leftIdx);
bool rightTopbar = ::hasTopbar(leftIdx + 1);
bool leftTopbar = hasTopbar(leftIdx);
bool rightTopbar = hasTopbar(leftIdx + 1);
if (leftTopbar != rightTopbar) {
float ratio = (float)leftScroll / (float)pageWidth;
float ratio;
if (leftTopbar) {
// scrolling from a screen with Topbar
ratio = 1.0 - ratio;
} else {
// scrolling to a screen with Topbar
// -> ratio is ok
}
setTopbarVisible(ratio);
customScreens[leftIdx]->adjustLayout();
customScreens[leftIdx + 1]->adjustLayout();
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;
}
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;
isVisible = visible;
int view = getCurrentMainView();
setTopbarVisible(visible && ::hasTopbar(view));
if (visible && (::hasTopbar(view) || isAppMode()))
topbar->showEdgeTxButton();
else
topbar->hideEdgeTxButton();
setTopbarVisible(visible && hasTopbar(view));
setEdgeTxButtonVisible(visible && (hasTopbar(view) || isAppMode()));
if (customScreens[view]) {
customScreens[view]->show(visible);
customScreens[view]->showWidgets(visible);
@@ -372,25 +383,36 @@ void ViewMain::show(bool visible)
bool ViewMain::isAppMode()
{
int view = getCurrentMainView();
if (!customScreens[view]) return false;
return ((Layout*)customScreens[view])->isAppMode();
return isAppMode(getCurrentMainView());
}
bool ViewMain::isAppMode(unsigned view)
{
if (view < MAX_CUSTOM_SCREENS && customScreens[view])
return ((Layout*)customScreens[view])->isAppMode();
return false;
}
bool ViewMain::hasTopbar()
{
int view = getCurrentMainView();
return ::hasTopbar(view);
return hasTopbar(getCurrentMainView());
}
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()
{
topbar->showEdgeTxButton();
topbar->setEdgeTxButtonVisible(hasTopbar() || isAppMode());
}
void ViewMain::hideTopBarEdgeTxButton()
{
topbar->hideEdgeTxButton();
topbar->setEdgeTxButtonVisible(0.0);
}
void ViewMain::runBackground()
@@ -80,7 +80,9 @@ class ViewMain : public NavWindow
void hideTopBarEdgeTxButton();
bool hasTopbar();
bool hasTopbar(unsigned view);
bool isAppMode();
bool isAppMode(unsigned view);
void runBackground();
void refreshWidgetSelectTimer();
@@ -103,6 +105,7 @@ class ViewMain : public NavWindow
// Set topbar visibility [0.0 -> 1.0]
void setTopbarVisible(float visible);
void setEdgeTxButtonVisible(float visible);
static void ws_timer(lv_timer_t* t);
-9
View File
@@ -51,15 +51,6 @@ class Widget : public ButtonBase
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; }
#if defined(DEBUG_WINDOWS)
@@ -111,12 +111,6 @@ class WidgetsContainerImpl : public WidgetsContainer
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;
rect_t getZone(unsigned int index) const override = 0;