Moved ViewMainDecoration back to Layout

This allows each custom screen to have its own trims/sliders/etc being displayed properly while scrolling from view to view.
This commit is contained in:
Raphael Coeffic
2021-04-18 07:57:42 +02:00
parent 19cab41034
commit d0a14cf2a2
5 changed files with 114 additions and 95 deletions
+44 -9
View File
@@ -22,6 +22,7 @@
#include "view_main.h"
#include "layouts/trims.h"
#include "layouts/sliders.h"
#include "view_main_decoration.h"
constexpr uint32_t LAYOUT_REFRESH = 1000 / 2; // 2 Hz
@@ -172,6 +173,14 @@ void disposeCustomScreen(unsigned idx)
memset(dst, 0, len);
}
Layout::Layout(const LayoutFactory * factory, PersistentData * persistentData):
LayoutBase({0, 0, LCD_W, LCD_H}, persistentData),
factory(factory),
decoration(new ViewMainDecoration(this, getRect()))
{
decorate();
}
void Layout::create()
{
memset(persistentData, 0, sizeof(PersistentData));
@@ -205,6 +214,26 @@ void Layout::checkEvents()
}
}
void Layout::setTrimsVisible(bool visible)
{
decoration->setTrimsVisible(visible);
}
void Layout::setSlidersVisible(bool visible)
{
decoration->setSlidersVisible(visible);
}
void Layout::setFlightModeVisible(bool visible)
{
decoration->setFlightModeVisible(visible);
}
void Layout::adjustDecoration()
{
decoration->adjustDecoration();
}
void Layout::decorate()
{
// Check if deco setting are still up-to-date
@@ -222,23 +251,29 @@ void Layout::decorate()
// Save settings
decorationSettings = checkSettings;
auto viewMain = ViewMain::instance();
// Set visible decoration
viewMain->setTopbarVisible(hasTopbar());
viewMain->setSlidersVisible(hasSliders());
viewMain->setTrimsVisible(hasTrims());
viewMain->setFlightModeVisible(hasFlightMode());
ViewMain::instance()->setTopbarVisible(hasTopbar());
setSlidersVisible(hasSliders());
setTrimsVisible(hasTrims());
setFlightModeVisible(hasFlightMode());
// Re-compute positions
viewMain->adjustDecoration();
adjustDecoration();
// and update relevant windows
updateZones();
invalidate();
// probably not needed
//invalidate();
}
void Layout::createDecoration()
{
}
rect_t Layout::getMainZone() const
{
return ViewMain::instance()->getMainZone();
rect_t zone = decoration->getMainZone();
return ViewMain::instance()->getMainZone(zone);
}
+14 -7
View File
@@ -32,6 +32,7 @@ constexpr coord_t TRIM_SQUARE_SIZE = 17;
constexpr coord_t MAIN_ZONE_BORDER = 10;
class LayoutFactory;
class ViewMainDecoration;
#define LAYOUT_COMMON_OPTIONS \
{ STR_TOP_BAR, ZoneOption::Bool }, \
@@ -62,12 +63,7 @@ class Layout: public LayoutBase
OPTION_LAST_DEFAULT=OPTION_MIRRORED
};
Layout(const LayoutFactory * factory, PersistentData * persistentData):
LayoutBase({0, 0, LCD_W, LCD_H}, persistentData),
factory(factory)
{
decorate();
}
Layout(const LayoutFactory * factory, PersistentData * persistentData);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
@@ -107,8 +103,17 @@ class Layout: public LayoutBase
return getOptionValue(OPTION_MIRRORED)->boolValue;
}
// Set decoration visibility
void setTrimsVisible(bool visible);
void setSlidersVisible(bool visible);
void setFlightModeVisible(bool visible);
// Re-calculate positions
void adjustDecoration();
protected:
const LayoutFactory * factory;
const LayoutFactory * factory = nullptr;
ViewMainDecoration* decoration = nullptr;
// Decoration settings bitmask to detect updates
uint8_t decorationSettings = 0;
@@ -119,6 +124,8 @@ class Layout: public LayoutBase
// Updates settings for trims, sliders, pots, etc...
void decorate();
void createDecoration();
// Get the available space for widgets
rect_t getMainZone() const;
};
+8 -16
View File
@@ -137,17 +137,6 @@ class SetupWidgetsPageSlot: public Button
}
return 0;
// }
// else {
// Menu * menu = new Menu(this);
// for (auto factory: getRegisteredWidgets()) {
// menu->addLine(factory->getName(), [=]() {
// if (widget) widget->deleteLater();
// widget = screen->createWidget(slotIndex, factory);
// });
// }
// }
// return 0;
});
}
@@ -163,7 +152,7 @@ class SetupWidgetsPage: public FormWindow
{
public:
SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx):
FormWindow(ViewMain::instance(), {0, 0, LCD_W, LCD_H}, /*OPAQUE |*/ FORM_FORWARD_FOCUS),
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, /*OPAQUE |*/ FORM_FORWARD_FOCUS),
menu(menu),
customScreenIdx(customScreenIdx)
{
@@ -173,11 +162,13 @@ class SetupWidgetsPage: public FormWindow
auto screen = customScreens[customScreenIdx];
if (screen) {
screen->attach(this);
screen->setLeft(0);
setRect(screen->getRect());
}
ViewMain::instance()->bringToTop();
auto viewMain = ViewMain::instance();
savedView = viewMain->getCurrentMainView();
viewMain->setCurrentMainView(customScreenIdx);
viewMain->bringToTop();
}
for (unsigned i = 0; i < screen->getZonesCount(); i++) {
auto rect = screen->getZone(i);
@@ -203,8 +194,8 @@ class SetupWidgetsPage: public FormWindow
auto screen = customScreens[customScreenIdx];
if (screen) {
auto viewMain = ViewMain::instance();
screen->setLeft(viewMain->getMainViewLeftPos(customScreenIdx));
screen->attach(viewMain);
viewMain->setCurrentMainView(customScreenIdx);
}
FormWindow::deleteLater(detach, trash);
@@ -228,6 +219,7 @@ class SetupWidgetsPage: public FormWindow
protected:
ScreenMenu* menu;
uint8_t customScreenIdx;
unsigned savedView = 0;
// void paint(BitmapBuffer * dc) override
// {
+38 -46
View File
@@ -62,7 +62,7 @@ ViewMain::ViewMain():
}, NO_FOCUS);
#endif
createDecoration();
createTopbar();
setPageWidth(getParent()->width());
focusWindow = this;
@@ -77,29 +77,6 @@ void ViewMain::setTopbarVisible(bool visible)
topbar->setVisible(visible);
}
void ViewMain::setTrimsVisible(bool visible)
{
decoration->setTrimsVisible(visible);
}
void ViewMain::setSlidersVisible(bool visible)
{
decoration->setSlidersVisible(visible);
}
void ViewMain::setFlightModeVisible(bool visible)
{
decoration->setFlightModeVisible(visible);
}
void ViewMain::adjustDecoration()
{
// Topbar does not need any computation
// (height() has been set in setTopbarVisible())
decoration->adjustDecoration();
}
unsigned ViewMain::getMainViewsCount() const
{
return views;
@@ -112,7 +89,6 @@ void ViewMain::setMainViewsCount(unsigned views)
this->views = views;
setInnerWidth(getParent()->width() * views);
//setWidth(getParent()->width() * views);
}
coord_t ViewMain::getMainViewLeftPos(unsigned view) const
@@ -120,15 +96,48 @@ coord_t ViewMain::getMainViewLeftPos(unsigned view) const
return getParent()->width() * view;
}
rect_t ViewMain::getMainZone() const
rect_t ViewMain::getMainZone(rect_t zone) const
{
rect_t zone = decoration->getMainZone();
zone.y += topbar->bottom();
zone.h -= topbar->height();
return zone;
}
unsigned ViewMain::getCurrentMainView() const
{
return g_model.view;
}
void ViewMain::setCurrentMainView(unsigned view)
{
if (view < getMainViewsCount()) {
g_model.view = view;
setScrollPositionX(g_model.view * pageWidth);
TRACE("### switched to view #%i", g_model.view);
}
}
void ViewMain::nextMainView()
{
auto view = getCurrentMainView();
if (++view >= getMainViewsCount())
view = 0;
setCurrentMainView(view);
}
void ViewMain::previousMainView()
{
auto view = getCurrentMainView();
if (view > 0)
view--;
else
view = getMainViewsCount() - 1;
setCurrentMainView(view);
}
#if defined(HARDWARE_KEYS)
void ViewMain::onEvent(event_t event)
{
@@ -155,12 +164,7 @@ void ViewMain::onEvent(event_t event)
case EVT_KEY_BREAK(KEY_PGDN):
killEvents(event);
g_model.view++;
if (g_model.view >= getMainViewsCount())
g_model.view = 0;
setScrollPositionX(g_model.view * pageWidth);
//customScreens[g_model.view]->setFocus();
TRACE("### switched to view #%i", g_model.view);
nextMainView();
break;
//TODO: these need to go away!
@@ -171,13 +175,7 @@ void ViewMain::onEvent(event_t event)
case EVT_KEY_LONG(KEY_PGDN):
#endif
killEvents(event);
if (!g_model.view)
g_model.view = getMainViewsCount() - 1;
else
g_model.view--;
setScrollPositionX(g_model.view * pageWidth);
//customScreens[g_model.view]->setFocus();
TRACE("### switched to view #%i", g_model.view);
previousMainView();
break;
}
}
@@ -235,12 +233,6 @@ void ViewMain::paint(BitmapBuffer * dc)
}
}
void ViewMain::createDecoration()
{
createTopbar();
decoration = new ViewMainDecoration(this, getRect());
}
void ViewMain::createTopbar()
{
topbar = new TopBar(this);
+10 -17
View File
@@ -25,7 +25,6 @@
#include <memory>
class TopBar;
class ViewMainDecoration;
class SetupWidgetsPage;
class ViewMain: public FormWindow
@@ -51,18 +50,12 @@ class ViewMain: public FormWindow
}
#endif
// Set topbar & decoration visibility
// Set topbar visibility
void setTopbarVisible(bool visible);
void setTrimsVisible(bool visible);
void setSlidersVisible(bool visible);
void setFlightModeVisible(bool visible);
// Re-calculate positions
void adjustDecoration();
// Get the available space in the middle of the screen
// (without decoration)
rect_t getMainZone() const;
// (without topbar)
rect_t getMainZone(rect_t zone) const;
unsigned getMainViewsCount() const;
void setMainViewsCount(unsigned views);
@@ -72,11 +65,15 @@ class ViewMain: public FormWindow
protected:
static ViewMain * _instance;
unsigned views = 0;
TopBar* topbar = nullptr;
ViewMainDecoration* decoration = nullptr;
unsigned views = 0;
TopBar* topbar = nullptr;
friend class SetupWidgetsPage;
unsigned getCurrentMainView() const;
void setCurrentMainView(unsigned view);
void nextMainView();
void previousMainView();
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
@@ -84,11 +81,7 @@ class ViewMain: public FormWindow
void paint(BitmapBuffer * dc) override;
void openMenu();
void createDecoration();
void createTopbar();
void nextView();
};
#endif // _VIEW_MAIN_H_