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->setTopbarVisible(customScreens[0]->hasTopbar());
viewMain->updateTopbarVisibility();
}
//
@@ -272,13 +272,9 @@ void Layout::decorate()
//invalidate();
}
void Layout::createDecoration()
{
}
rect_t Layout::getMainZone() const
{
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
uint32_t lastRefresh = 0;
void createDecoration();
// Get the available space for widgets
rect_t getMainZone() const;
};
+47 -19
View File
@@ -86,8 +86,15 @@ void ViewMain::setMainViewsCount(unsigned views)
{
if (views > MAX_CUSTOM_SCREENS)
views = MAX_CUSTOM_SCREENS;
// update number of views
this->views = views;
// adjust current screen if needed
if (g_model.view >= views) {
setCurrentMainView(views - 1);
}
setInnerWidth(getParent()->width() * views);
}
@@ -96,9 +103,9 @@ coord_t ViewMain::getMainViewLeftPos(unsigned view) const
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.h -= visibleHeight;
@@ -138,28 +145,49 @@ void ViewMain::previousMainView()
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)
{
Window::setScrollPositionX(value);
topbar->setLeft(getScrollPositionX());
auto newIdx = getPageIndex();
if (newIdx != g_model.view) {
// update page index
g_model.view = getPageIndex();
auto oldIdx = g_model.view;
// auto hadTopbar = customScreens[oldIdx]->hasTopbar();
// 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;
}
// update Topbar
updateTopbarVisibility();
}
void ViewMain::setScrollPositionY(coord_t value)
+6 -3
View File
@@ -50,12 +50,11 @@ class ViewMain: public Window
}
#endif
// Set topbar visibility [0.0 -> 1.0]
void setTopbarVisible(float visible);
void updateTopbarVisibility();
// Get the available space in the middle of the screen
// (without topbar)
rect_t getMainZone(rect_t zone) const;
rect_t getMainZone(rect_t zone, bool hasTopbar) const;
unsigned getMainViewsCount() const;
void setMainViewsCount(unsigned views);
@@ -64,6 +63,7 @@ class ViewMain: public Window
unsigned getCurrentMainView() const;
void setCurrentMainView(unsigned view);
void nextMainView();
void previousMainView();
@@ -75,6 +75,9 @@ class ViewMain: public Window
friend class SetupWidgetsPage;
// Set topbar visibility [0.0 -> 1.0]
void setTopbarVisible(float visible);
void setScrollPositionX(coord_t value) override;
void setScrollPositionY(coord_t value) override;