diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index 5709ac81d..b9b5cb962 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -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()); } diff --git a/radio/src/gui/colorlcd/layout.h b/radio/src/gui/colorlcd/layout.h index 4246b540e..81b095577 100644 --- a/radio/src/gui/colorlcd/layout.h +++ b/radio/src/gui/colorlcd/layout.h @@ -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; }; diff --git a/radio/src/gui/colorlcd/view_main.cpp b/radio/src/gui/colorlcd/view_main.cpp index 5e1fc2183..81db27952 100644 --- a/radio/src/gui/colorlcd/view_main.cpp +++ b/radio/src/gui/colorlcd/view_main.cpp @@ -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) diff --git a/radio/src/gui/colorlcd/view_main.h b/radio/src/gui/colorlcd/view_main.h index 92cb3b31f..07ed08f34 100644 --- a/radio/src/gui/colorlcd/view_main.h +++ b/radio/src/gui/colorlcd/view_main.h @@ -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;