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:
@@ -22,6 +22,7 @@
|
|||||||
#include "view_main.h"
|
#include "view_main.h"
|
||||||
#include "layouts/trims.h"
|
#include "layouts/trims.h"
|
||||||
#include "layouts/sliders.h"
|
#include "layouts/sliders.h"
|
||||||
|
#include "view_main_decoration.h"
|
||||||
|
|
||||||
constexpr uint32_t LAYOUT_REFRESH = 1000 / 2; // 2 Hz
|
constexpr uint32_t LAYOUT_REFRESH = 1000 / 2; // 2 Hz
|
||||||
|
|
||||||
@@ -172,6 +173,14 @@ void disposeCustomScreen(unsigned idx)
|
|||||||
memset(dst, 0, len);
|
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()
|
void Layout::create()
|
||||||
{
|
{
|
||||||
memset(persistentData, 0, sizeof(PersistentData));
|
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()
|
void Layout::decorate()
|
||||||
{
|
{
|
||||||
// Check if deco setting are still up-to-date
|
// Check if deco setting are still up-to-date
|
||||||
@@ -222,23 +251,29 @@ void Layout::decorate()
|
|||||||
// Save settings
|
// Save settings
|
||||||
decorationSettings = checkSettings;
|
decorationSettings = checkSettings;
|
||||||
|
|
||||||
auto viewMain = ViewMain::instance();
|
|
||||||
|
|
||||||
// Set visible decoration
|
// Set visible decoration
|
||||||
viewMain->setTopbarVisible(hasTopbar());
|
ViewMain::instance()->setTopbarVisible(hasTopbar());
|
||||||
viewMain->setSlidersVisible(hasSliders());
|
setSlidersVisible(hasSliders());
|
||||||
viewMain->setTrimsVisible(hasTrims());
|
setTrimsVisible(hasTrims());
|
||||||
viewMain->setFlightModeVisible(hasFlightMode());
|
setFlightModeVisible(hasFlightMode());
|
||||||
|
|
||||||
// Re-compute positions
|
// Re-compute positions
|
||||||
viewMain->adjustDecoration();
|
adjustDecoration();
|
||||||
|
|
||||||
// and update relevant windows
|
// and update relevant windows
|
||||||
updateZones();
|
updateZones();
|
||||||
invalidate();
|
|
||||||
|
// probably not needed
|
||||||
|
//invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::createDecoration()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
rect_t Layout::getMainZone() const
|
rect_t Layout::getMainZone() const
|
||||||
{
|
{
|
||||||
return ViewMain::instance()->getMainZone();
|
rect_t zone = decoration->getMainZone();
|
||||||
|
return ViewMain::instance()->getMainZone(zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ constexpr coord_t TRIM_SQUARE_SIZE = 17;
|
|||||||
constexpr coord_t MAIN_ZONE_BORDER = 10;
|
constexpr coord_t MAIN_ZONE_BORDER = 10;
|
||||||
|
|
||||||
class LayoutFactory;
|
class LayoutFactory;
|
||||||
|
class ViewMainDecoration;
|
||||||
|
|
||||||
#define LAYOUT_COMMON_OPTIONS \
|
#define LAYOUT_COMMON_OPTIONS \
|
||||||
{ STR_TOP_BAR, ZoneOption::Bool }, \
|
{ STR_TOP_BAR, ZoneOption::Bool }, \
|
||||||
@@ -62,12 +63,7 @@ class Layout: public LayoutBase
|
|||||||
OPTION_LAST_DEFAULT=OPTION_MIRRORED
|
OPTION_LAST_DEFAULT=OPTION_MIRRORED
|
||||||
};
|
};
|
||||||
|
|
||||||
Layout(const LayoutFactory * factory, PersistentData * persistentData):
|
Layout(const LayoutFactory * factory, PersistentData * persistentData);
|
||||||
LayoutBase({0, 0, LCD_W, LCD_H}, persistentData),
|
|
||||||
factory(factory)
|
|
||||||
{
|
|
||||||
decorate();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override
|
std::string getName() const override
|
||||||
@@ -107,8 +103,17 @@ class Layout: public LayoutBase
|
|||||||
return getOptionValue(OPTION_MIRRORED)->boolValue;
|
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:
|
protected:
|
||||||
const LayoutFactory * factory;
|
const LayoutFactory * factory = nullptr;
|
||||||
|
ViewMainDecoration* decoration = nullptr;
|
||||||
|
|
||||||
// Decoration settings bitmask to detect updates
|
// Decoration settings bitmask to detect updates
|
||||||
uint8_t decorationSettings = 0;
|
uint8_t decorationSettings = 0;
|
||||||
@@ -119,6 +124,8 @@ class Layout: public LayoutBase
|
|||||||
// Updates settings for trims, sliders, pots, etc...
|
// Updates settings for trims, sliders, pots, etc...
|
||||||
void decorate();
|
void decorate();
|
||||||
|
|
||||||
|
void createDecoration();
|
||||||
|
|
||||||
// Get the available space for widgets
|
// Get the available space for widgets
|
||||||
rect_t getMainZone() const;
|
rect_t getMainZone() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -137,17 +137,6 @@ class SetupWidgetsPageSlot: public Button
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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:
|
public:
|
||||||
SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx):
|
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),
|
menu(menu),
|
||||||
customScreenIdx(customScreenIdx)
|
customScreenIdx(customScreenIdx)
|
||||||
{
|
{
|
||||||
@@ -173,11 +162,13 @@ class SetupWidgetsPage: public FormWindow
|
|||||||
auto screen = customScreens[customScreenIdx];
|
auto screen = customScreens[customScreenIdx];
|
||||||
if (screen) {
|
if (screen) {
|
||||||
screen->attach(this);
|
screen->attach(this);
|
||||||
screen->setLeft(0);
|
|
||||||
setRect(screen->getRect());
|
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++) {
|
for (unsigned i = 0; i < screen->getZonesCount(); i++) {
|
||||||
auto rect = screen->getZone(i);
|
auto rect = screen->getZone(i);
|
||||||
@@ -203,8 +194,8 @@ class SetupWidgetsPage: public FormWindow
|
|||||||
auto screen = customScreens[customScreenIdx];
|
auto screen = customScreens[customScreenIdx];
|
||||||
if (screen) {
|
if (screen) {
|
||||||
auto viewMain = ViewMain::instance();
|
auto viewMain = ViewMain::instance();
|
||||||
screen->setLeft(viewMain->getMainViewLeftPos(customScreenIdx));
|
|
||||||
screen->attach(viewMain);
|
screen->attach(viewMain);
|
||||||
|
viewMain->setCurrentMainView(customScreenIdx);
|
||||||
}
|
}
|
||||||
FormWindow::deleteLater(detach, trash);
|
FormWindow::deleteLater(detach, trash);
|
||||||
|
|
||||||
@@ -228,6 +219,7 @@ class SetupWidgetsPage: public FormWindow
|
|||||||
protected:
|
protected:
|
||||||
ScreenMenu* menu;
|
ScreenMenu* menu;
|
||||||
uint8_t customScreenIdx;
|
uint8_t customScreenIdx;
|
||||||
|
unsigned savedView = 0;
|
||||||
|
|
||||||
// void paint(BitmapBuffer * dc) override
|
// void paint(BitmapBuffer * dc) override
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ ViewMain::ViewMain():
|
|||||||
}, NO_FOCUS);
|
}, NO_FOCUS);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
createDecoration();
|
createTopbar();
|
||||||
setPageWidth(getParent()->width());
|
setPageWidth(getParent()->width());
|
||||||
|
|
||||||
focusWindow = this;
|
focusWindow = this;
|
||||||
@@ -77,29 +77,6 @@ void ViewMain::setTopbarVisible(bool visible)
|
|||||||
topbar->setVisible(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
|
unsigned ViewMain::getMainViewsCount() const
|
||||||
{
|
{
|
||||||
return views;
|
return views;
|
||||||
@@ -112,7 +89,6 @@ void ViewMain::setMainViewsCount(unsigned views)
|
|||||||
|
|
||||||
this->views = views;
|
this->views = views;
|
||||||
setInnerWidth(getParent()->width() * views);
|
setInnerWidth(getParent()->width() * views);
|
||||||
//setWidth(getParent()->width() * views);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
coord_t ViewMain::getMainViewLeftPos(unsigned view) const
|
coord_t ViewMain::getMainViewLeftPos(unsigned view) const
|
||||||
@@ -120,15 +96,48 @@ coord_t ViewMain::getMainViewLeftPos(unsigned view) const
|
|||||||
return getParent()->width() * view;
|
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.y += topbar->bottom();
|
||||||
zone.h -= topbar->height();
|
zone.h -= topbar->height();
|
||||||
|
|
||||||
return zone;
|
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)
|
#if defined(HARDWARE_KEYS)
|
||||||
void ViewMain::onEvent(event_t event)
|
void ViewMain::onEvent(event_t event)
|
||||||
{
|
{
|
||||||
@@ -155,12 +164,7 @@ void ViewMain::onEvent(event_t event)
|
|||||||
|
|
||||||
case EVT_KEY_BREAK(KEY_PGDN):
|
case EVT_KEY_BREAK(KEY_PGDN):
|
||||||
killEvents(event);
|
killEvents(event);
|
||||||
g_model.view++;
|
nextMainView();
|
||||||
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);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//TODO: these need to go away!
|
//TODO: these need to go away!
|
||||||
@@ -171,13 +175,7 @@ void ViewMain::onEvent(event_t event)
|
|||||||
case EVT_KEY_LONG(KEY_PGDN):
|
case EVT_KEY_LONG(KEY_PGDN):
|
||||||
#endif
|
#endif
|
||||||
killEvents(event);
|
killEvents(event);
|
||||||
if (!g_model.view)
|
previousMainView();
|
||||||
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);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,12 +233,6 @@ void ViewMain::paint(BitmapBuffer * dc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewMain::createDecoration()
|
|
||||||
{
|
|
||||||
createTopbar();
|
|
||||||
decoration = new ViewMainDecoration(this, getRect());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewMain::createTopbar()
|
void ViewMain::createTopbar()
|
||||||
{
|
{
|
||||||
topbar = new TopBar(this);
|
topbar = new TopBar(this);
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class TopBar;
|
class TopBar;
|
||||||
class ViewMainDecoration;
|
|
||||||
class SetupWidgetsPage;
|
class SetupWidgetsPage;
|
||||||
|
|
||||||
class ViewMain: public FormWindow
|
class ViewMain: public FormWindow
|
||||||
@@ -51,18 +50,12 @@ class ViewMain: public FormWindow
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set topbar & decoration visibility
|
// Set topbar visibility
|
||||||
void setTopbarVisible(bool visible);
|
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
|
// Get the available space in the middle of the screen
|
||||||
// (without decoration)
|
// (without topbar)
|
||||||
rect_t getMainZone() const;
|
rect_t getMainZone(rect_t zone) const;
|
||||||
|
|
||||||
unsigned getMainViewsCount() const;
|
unsigned getMainViewsCount() const;
|
||||||
void setMainViewsCount(unsigned views);
|
void setMainViewsCount(unsigned views);
|
||||||
@@ -72,11 +65,15 @@ class ViewMain: public FormWindow
|
|||||||
protected:
|
protected:
|
||||||
static ViewMain * _instance;
|
static ViewMain * _instance;
|
||||||
|
|
||||||
unsigned views = 0;
|
unsigned views = 0;
|
||||||
TopBar* topbar = nullptr;
|
TopBar* topbar = nullptr;
|
||||||
ViewMainDecoration* decoration = nullptr;
|
|
||||||
|
|
||||||
friend class SetupWidgetsPage;
|
friend class SetupWidgetsPage;
|
||||||
|
|
||||||
|
unsigned getCurrentMainView() const;
|
||||||
|
void setCurrentMainView(unsigned view);
|
||||||
|
void nextMainView();
|
||||||
|
void previousMainView();
|
||||||
|
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
void onEvent(event_t event) override;
|
void onEvent(event_t event) override;
|
||||||
@@ -84,11 +81,7 @@ class ViewMain: public FormWindow
|
|||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
|
|
||||||
void openMenu();
|
void openMenu();
|
||||||
|
|
||||||
void createDecoration();
|
|
||||||
void createTopbar();
|
void createTopbar();
|
||||||
|
|
||||||
void nextView();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _VIEW_MAIN_H_
|
#endif // _VIEW_MAIN_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user