Fix a couple of bugs related to topbar appearance

This commit is contained in:
Raphael Coeffic
2021-04-18 07:58:28 +02:00
parent 256e53a016
commit 93b5b1db1b
4 changed files with 55 additions and 30 deletions
+2 -6
View File
@@ -127,7 +127,7 @@ void loadCustomScreens()
} }
viewMain->setCurrentMainView(0); viewMain->setCurrentMainView(0);
viewMain->setTopbarVisible(customScreens[0]->hasTopbar()); viewMain->updateTopbarVisibility();
} }
// //
@@ -272,13 +272,9 @@ void Layout::decorate()
//invalidate(); //invalidate();
} }
void Layout::createDecoration()
{
}
rect_t Layout::getMainZone() const rect_t Layout::getMainZone() const
{ {
rect_t zone = decoration->getMainZone(); rect_t zone = decoration->getMainZone();
return ViewMain::instance()->getMainZone(zone); return ViewMain::instance()->getMainZone(zone, hasTopbar());
} }
-2
View File
@@ -124,8 +124,6 @@ class Layout: public LayoutBase
// Last time we refreshed the window // Last time we refreshed the window
uint32_t lastRefresh = 0; uint32_t lastRefresh = 0;
void createDecoration();
// Get the available space for widgets // Get the available space for widgets
rect_t getMainZone() const; rect_t getMainZone() const;
}; };
+47 -19
View File
@@ -86,8 +86,15 @@ void ViewMain::setMainViewsCount(unsigned views)
{ {
if (views > MAX_CUSTOM_SCREENS) if (views > MAX_CUSTOM_SCREENS)
views = MAX_CUSTOM_SCREENS; views = MAX_CUSTOM_SCREENS;
// update number of views
this->views = views; this->views = views;
// adjust current screen if needed
if (g_model.view >= views) {
setCurrentMainView(views - 1);
}
setInnerWidth(getParent()->width() * views); setInnerWidth(getParent()->width() * views);
} }
@@ -96,9 +103,9 @@ coord_t ViewMain::getMainViewLeftPos(unsigned view) const
return getParent()->width() * view; return getParent()->width() * view;
} }
rect_t ViewMain::getMainZone(rect_t zone) const rect_t ViewMain::getMainZone(rect_t zone, bool hasTopbar) const
{ {
auto visibleHeight = topbar->bottom() - zone.y; auto visibleHeight = topbar->getVisibleHeight(hasTopbar ? 1.0 : 0.0);
zone.y += visibleHeight; zone.y += visibleHeight;
zone.h -= visibleHeight; zone.h -= visibleHeight;
@@ -138,28 +145,49 @@ void ViewMain::previousMainView()
setCurrentMainView(view); setCurrentMainView(view);
} }
void ViewMain::updateTopbarVisibility()
{
// relative to left visible page
int leftScroll = getScrollPositionX() % pageWidth;
if (leftScroll == 0) {
setTopbarVisible(customScreens[g_model.view]->hasTopbar());
customScreens[g_model.view]->decorate();
}
else {
int leftIdx = getScrollPositionX() / pageWidth;
bool leftTopbar = customScreens[leftIdx]->hasTopbar();
bool rightTopbar = customScreens[leftIdx+1]->hasTopbar();
if (leftTopbar != rightTopbar) {
float ratio = (float)leftScroll / (float)pageWidth;
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]->decorate();
customScreens[leftIdx+1]->decorate();
}
}
}
void ViewMain::setScrollPositionX(coord_t value) void ViewMain::setScrollPositionX(coord_t value)
{ {
Window::setScrollPositionX(value); Window::setScrollPositionX(value);
topbar->setLeft(getScrollPositionX()); topbar->setLeft(getScrollPositionX());
auto newIdx = getPageIndex(); // update page index
if (newIdx != g_model.view) { g_model.view = getPageIndex();
auto oldIdx = g_model.view; // update Topbar
// auto hadTopbar = customScreens[oldIdx]->hasTopbar(); updateTopbarVisibility();
// auto willHaveTopbar = customScreens[newIdx]->hasTopbar();
// update current view
g_model.view = newIdx;
// crude on/off for now
setTopbarVisible(customScreens[pageIdx]->hasTopbar());
customScreens[pageIdx]->decorate();
//TODO: compute topbar visibility
//auto relativeScrollPosition = getScrollPositionX() % pageWidth;
}
} }
void ViewMain::setScrollPositionY(coord_t value) void ViewMain::setScrollPositionY(coord_t value)
+6 -3
View File
@@ -50,12 +50,11 @@ class ViewMain: public Window
} }
#endif #endif
// Set topbar visibility [0.0 -> 1.0] void updateTopbarVisibility();
void setTopbarVisible(float visible);
// 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) const; rect_t getMainZone(rect_t zone, bool hasTopbar) const;
unsigned getMainViewsCount() const; unsigned getMainViewsCount() const;
void setMainViewsCount(unsigned views); void setMainViewsCount(unsigned views);
@@ -64,6 +63,7 @@ class ViewMain: public Window
unsigned getCurrentMainView() const; unsigned getCurrentMainView() const;
void setCurrentMainView(unsigned view); void setCurrentMainView(unsigned view);
void nextMainView(); void nextMainView();
void previousMainView(); void previousMainView();
@@ -75,6 +75,9 @@ class ViewMain: public Window
friend class SetupWidgetsPage; friend class SetupWidgetsPage;
// Set topbar visibility [0.0 -> 1.0]
void setTopbarVisible(float visible);
void setScrollPositionX(coord_t value) override; void setScrollPositionX(coord_t value) override;
void setScrollPositionY(coord_t value) override; void setScrollPositionY(coord_t value) override;