Refined WidgetsContainer interface and some names
This commit is contained in:
@@ -47,7 +47,7 @@ void drawCurveHorizontalScale();
|
|||||||
void drawCurveCoord(int x, int y, const char * text, bool active=false);
|
void drawCurveCoord(int x, int y, const char * text, bool active=false);
|
||||||
void drawCurvePoint(int x, int y, LcdFlags color);
|
void drawCurvePoint(int x, int y, LcdFlags color);
|
||||||
|
|
||||||
extern WidgetsContainerInterface * customScreens[MAX_CUSTOM_SCREENS];
|
extern WidgetsContainer * customScreens[MAX_CUSTOM_SCREENS];
|
||||||
|
|
||||||
void drawAlertBox(const char * title, const char * text, const char * action);
|
void drawAlertBox(const char * title, const char * text, const char * action);
|
||||||
void showAlertBox(const char * title, const char * text, const char * action, uint8_t sound);
|
void showAlertBox(const char * title, const char * text, const char * action, uint8_t sound);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "view_main.h"
|
#include "view_main.h"
|
||||||
|
|
||||||
WidgetsContainerInterface * customScreens[MAX_CUSTOM_SCREENS] = {};
|
WidgetsContainer * customScreens[MAX_CUSTOM_SCREENS] = {};
|
||||||
|
|
||||||
std::list<const LayoutFactory *> & getRegisteredLayouts()
|
std::list<const LayoutFactory *> & getRegisteredLayouts()
|
||||||
{
|
{
|
||||||
@@ -49,7 +49,7 @@ const LayoutFactory * getLayoutFactory(const char * name)
|
|||||||
//
|
//
|
||||||
// Loads a layout, but does not attach it to any window
|
// Loads a layout, but does not attach it to any window
|
||||||
//
|
//
|
||||||
WidgetsContainerInterface *
|
WidgetsContainer *
|
||||||
loadLayout(const char * name, LayoutPersistentData * persistentData)
|
loadLayout(const char * name, LayoutPersistentData * persistentData)
|
||||||
{
|
{
|
||||||
const LayoutFactory * factory = getLayoutFactory(name);
|
const LayoutFactory * factory = getLayoutFactory(name);
|
||||||
@@ -137,7 +137,7 @@ void loadCustomScreens()
|
|||||||
// - new screen is configured into g_model
|
// - new screen is configured into g_model
|
||||||
// - the new screen is returned (not attached)
|
// - the new screen is returned (not attached)
|
||||||
//
|
//
|
||||||
WidgetsContainerInterface *
|
WidgetsContainer *
|
||||||
createCustomScreen(const LayoutFactory* factory, unsigned customScreenIndex)
|
createCustomScreen(const LayoutFactory* factory, unsigned customScreenIndex)
|
||||||
{
|
{
|
||||||
if (!factory || (customScreenIndex >= MAX_CUSTOM_SCREENS))
|
if (!factory || (customScreenIndex >= MAX_CUSTOM_SCREENS))
|
||||||
|
|||||||
@@ -42,15 +42,15 @@ class LayoutFactory
|
|||||||
const char * getName() const { return name; }
|
const char * getName() const { return name; }
|
||||||
virtual void drawThumb(BitmapBuffer * dc, uint16_t x, uint16_t y, LcdFlags flags) const = 0;
|
virtual void drawThumb(BitmapBuffer * dc, uint16_t x, uint16_t y, LcdFlags flags) const = 0;
|
||||||
virtual const ZoneOption * getOptions() const = 0;
|
virtual const ZoneOption * getOptions() const = 0;
|
||||||
virtual WidgetsContainerInterface * create(LayoutPersistentData * persistentData) const = 0;
|
virtual WidgetsContainer * create(LayoutPersistentData * persistentData) const = 0;
|
||||||
virtual WidgetsContainerInterface * load(LayoutPersistentData * persistentData) const = 0;
|
virtual WidgetsContainer * load(LayoutPersistentData * persistentData) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char * id;
|
const char * id;
|
||||||
const char * name;
|
const char * name;
|
||||||
};
|
};
|
||||||
|
|
||||||
WidgetsContainerInterface * loadLayout(const char * name, LayoutPersistentData * persistentData);
|
WidgetsContainer * loadLayout(const char * name, LayoutPersistentData * persistentData);
|
||||||
|
|
||||||
// intented for new models
|
// intented for new models
|
||||||
void loadDefaultLayout();
|
void loadDefaultLayout();
|
||||||
@@ -61,7 +61,7 @@ void loadCustomScreens();
|
|||||||
// delete all custom screens from memory
|
// delete all custom screens from memory
|
||||||
void deleteCustomScreens();
|
void deleteCustomScreens();
|
||||||
|
|
||||||
WidgetsContainerInterface *
|
WidgetsContainer *
|
||||||
createCustomScreen(const LayoutFactory* factory, unsigned customScreenIndex);
|
createCustomScreen(const LayoutFactory* factory, unsigned customScreenIndex);
|
||||||
|
|
||||||
// Remove custom screen from the model
|
// Remove custom screen from the model
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ Layout::Layout(const LayoutFactory * factory, PersistentData * persistentData):
|
|||||||
factory(factory),
|
factory(factory),
|
||||||
decoration(new ViewMainDecoration(this, getRect()))
|
decoration(new ViewMainDecoration(this, getRect()))
|
||||||
{
|
{
|
||||||
decorate();
|
adjustLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::create()
|
void Layout::create()
|
||||||
@@ -54,7 +54,7 @@ void Layout::paint(BitmapBuffer * dc)
|
|||||||
void Layout::checkEvents()
|
void Layout::checkEvents()
|
||||||
{
|
{
|
||||||
LayoutBase::checkEvents();
|
LayoutBase::checkEvents();
|
||||||
decorate();
|
adjustLayout();
|
||||||
|
|
||||||
uint32_t now = RTOS_GET_MS();
|
uint32_t now = RTOS_GET_MS();
|
||||||
if (now - lastRefresh >= LAYOUT_REFRESH) {
|
if (now - lastRefresh >= LAYOUT_REFRESH) {
|
||||||
@@ -82,12 +82,7 @@ void Layout::setFlightModeVisible(bool visible)
|
|||||||
decoration->setFlightModeVisible(visible);
|
decoration->setFlightModeVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::adjustDecoration()
|
void Layout::adjustLayout()
|
||||||
{
|
|
||||||
decoration->adjustDecoration();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::decorate()
|
|
||||||
{
|
{
|
||||||
// Check if deco setting are still up-to-date
|
// Check if deco setting are still up-to-date
|
||||||
uint8_t checkSettings =
|
uint8_t checkSettings =
|
||||||
@@ -110,7 +105,7 @@ void Layout::decorate()
|
|||||||
setFlightModeVisible(hasFlightMode());
|
setFlightModeVisible(hasFlightMode());
|
||||||
|
|
||||||
// Re-compute positions
|
// Re-compute positions
|
||||||
adjustDecoration();
|
decoration->adjustDecoration();
|
||||||
|
|
||||||
// and update relevant windows
|
// and update relevant windows
|
||||||
updateZones();
|
updateZones();
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
class ViewMainDecoration;
|
class ViewMainDecoration;
|
||||||
|
|
||||||
typedef WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> LayoutBase;
|
typedef WidgetsContainerImpl<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> LayoutBase;
|
||||||
|
|
||||||
class Layout: public LayoutBase
|
class Layout: public LayoutBase
|
||||||
{
|
{
|
||||||
@@ -61,7 +61,7 @@ class Layout: public LayoutBase
|
|||||||
|
|
||||||
void create() override;
|
void create() override;
|
||||||
|
|
||||||
const LayoutFactory * getFactory() const override
|
const LayoutFactory * getFactory() const
|
||||||
{
|
{
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
@@ -93,11 +93,8 @@ class Layout: public LayoutBase
|
|||||||
void setSlidersVisible(bool visible);
|
void setSlidersVisible(bool visible);
|
||||||
void setFlightModeVisible(bool visible);
|
void setFlightModeVisible(bool visible);
|
||||||
|
|
||||||
// Re-calculate positions
|
|
||||||
void adjustDecoration();
|
|
||||||
|
|
||||||
// Updates settings for trims, sliders, pots, etc...
|
// Updates settings for trims, sliders, pots, etc...
|
||||||
void decorate() override;
|
void adjustLayout() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const LayoutFactory * factory = nullptr;
|
const LayoutFactory * factory = nullptr;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const char * const STR_MONTHS[] = TR_MONTHS;
|
|||||||
constexpr uint32_t TOPBAR_REFRESH = 1000 / 2; // 2 Hz
|
constexpr uint32_t TOPBAR_REFRESH = 1000 / 2; // 2 Hz
|
||||||
|
|
||||||
TopbarImpl::TopbarImpl(Window * parent) :
|
TopbarImpl::TopbarImpl(Window * parent) :
|
||||||
WidgetsContainer<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS>({0, 0, LCD_W, MENU_HEADER_HEIGHT}, &g_model.topbarData)
|
TopbarImplBase({0, 0, LCD_W, MENU_HEADER_HEIGHT}, &g_model.topbarData)
|
||||||
{
|
{
|
||||||
attach(parent);
|
attach(parent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "topbar.h"
|
#include "topbar.h"
|
||||||
#include "layouts/layout_factory_impl.h"
|
#include "layouts/layout_factory_impl.h"
|
||||||
|
|
||||||
typedef WidgetsContainer<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS> TopbarImplBase;
|
typedef WidgetsContainerImpl<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS> TopbarImplBase;
|
||||||
|
|
||||||
class TopbarImpl:
|
class TopbarImpl:
|
||||||
public TopbarImplBase,
|
public TopbarImplBase,
|
||||||
@@ -54,13 +54,6 @@ class TopbarImpl:
|
|||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
|
|
||||||
void checkEvents() override;
|
void checkEvents() override;
|
||||||
|
|
||||||
// Fake implementation to satisfy WidgetsContainerInterface
|
|
||||||
// this should probably be get rid of (might be tricky
|
|
||||||
const LayoutFactory * getFactory() const override
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t lastRefresh = 0;
|
uint32_t lastRefresh = 0;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "widget_settings.h"
|
#include "widget_settings.h"
|
||||||
#include "topbar.h"
|
#include "topbar.h"
|
||||||
#include "libopenui.h"
|
#include "libopenui.h"
|
||||||
|
#include "layouts/layout_factory_impl.h"
|
||||||
|
|
||||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ class LayoutChoice: public FormField
|
|||||||
std::function<void(const LayoutFactory *)> setValue;
|
std::function<void(const LayoutFactory *)> setValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, WidgetsContainerInterface* container, uint8_t slotIndex):
|
SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, WidgetsContainer* container, uint8_t slotIndex):
|
||||||
Button(parent, rect)
|
Button(parent, rect)
|
||||||
{
|
{
|
||||||
setPressHandler([parent, container, slotIndex]() -> uint8_t {
|
setPressHandler([parent, container, slotIndex]() -> uint8_t {
|
||||||
@@ -353,32 +354,39 @@ static void updateLayoutOptions(FormGroup* optionsWindow, unsigned customScreenI
|
|||||||
|
|
||||||
// Layout options...
|
// Layout options...
|
||||||
int index = 0;
|
int index = 0;
|
||||||
auto factory = customScreens[customScreenIndex]->getFactory();
|
auto layout = dynamic_cast<Layout*>(customScreens[customScreenIndex]);
|
||||||
if (factory) {
|
if (!layout) {
|
||||||
for (auto * option = factory->getOptions(); option->name; option++, index++) {
|
return;
|
||||||
|
|
||||||
auto layoutData = g_model.screenData[customScreenIndex].layoutData;
|
|
||||||
ZoneOptionValue * value = &layoutData.options[index].value;
|
|
||||||
|
|
||||||
// Option label
|
|
||||||
new StaticText(optionsWindow, grid.getLabelSlot(false), option->name);
|
|
||||||
|
|
||||||
// Option value
|
|
||||||
switch (option->type) {
|
|
||||||
case ZoneOption::Bool:
|
|
||||||
new CheckBox(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->boolValue));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ZoneOption::Color:
|
|
||||||
new ColorEdit(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->unsignedValue));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
grid.nextLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
auto factory = layout->getFactory();
|
||||||
|
if (!factory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto * option = factory->getOptions(); option->name; option++, index++) {
|
||||||
|
|
||||||
|
auto layoutData = g_model.screenData[customScreenIndex].layoutData;
|
||||||
|
ZoneOptionValue * value = &layoutData.options[index].value;
|
||||||
|
|
||||||
|
// Option label
|
||||||
|
new StaticText(optionsWindow, grid.getLabelSlot(false), option->name);
|
||||||
|
|
||||||
|
// Option value
|
||||||
|
switch (option->type) {
|
||||||
|
case ZoneOption::Bool:
|
||||||
|
new CheckBox(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->boolValue));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ZoneOption::Color:
|
||||||
|
new ColorEdit(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->unsignedValue));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
grid.nextLine();
|
||||||
|
}
|
||||||
|
|
||||||
optionsWindow->adjustHeight();
|
optionsWindow->adjustHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,7 +406,11 @@ void ScreenSetupPage::build(FormWindow * window)
|
|||||||
rect_t optRect = {0, grid.getWindowHeight(), window->width(), 0};
|
rect_t optRect = {0, grid.getWindowHeight(), window->width(), 0};
|
||||||
auto optionsWindow = new FormGroup(window, optRect, FORWARD_SCROLL | FORM_FORWARD_FOCUS);
|
auto optionsWindow = new FormGroup(window, optRect, FORWARD_SCROLL | FORM_FORWARD_FOCUS);
|
||||||
|
|
||||||
LayoutChoice::LayoutFactoryGetter getFactory = GET_VALUE(customScreens[idx]->getFactory());
|
LayoutChoice::LayoutFactoryGetter getFactory = [idx] () -> const LayoutFactory * {
|
||||||
|
auto layout = dynamic_cast<Layout*>(customScreens[idx]);
|
||||||
|
if (!layout) return nullptr;
|
||||||
|
return layout->getFactory();
|
||||||
|
};
|
||||||
LayoutChoice::LayoutFactorySetter setLayout = [idx, optionsWindow](const LayoutFactory *factory) {
|
LayoutChoice::LayoutFactorySetter setLayout = [idx, optionsWindow](const LayoutFactory *factory) {
|
||||||
// delete any options potentially accessing
|
// delete any options potentially accessing
|
||||||
// the old custom screen
|
// the old custom screen
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class ScreenSetupPage: public PageTab {
|
|||||||
class SetupWidgetsPageSlot: public Button
|
class SetupWidgetsPageSlot: public Button
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, WidgetsContainerInterface* container, uint8_t slotIndex);
|
SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, WidgetsContainer* container, uint8_t slotIndex);
|
||||||
|
|
||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ void ViewMain::updateTopbarVisibility()
|
|||||||
int leftScroll = getScrollPositionX() % pageWidth;
|
int leftScroll = getScrollPositionX() % pageWidth;
|
||||||
if (leftScroll == 0) {
|
if (leftScroll == 0) {
|
||||||
setTopbarVisible(hasTopbar(g_model.view));
|
setTopbarVisible(hasTopbar(g_model.view));
|
||||||
customScreens[g_model.view]->decorate();
|
customScreens[g_model.view]->adjustLayout();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int leftIdx = getScrollPositionX() / pageWidth;
|
int leftIdx = getScrollPositionX() / pageWidth;
|
||||||
@@ -185,8 +185,8 @@ void ViewMain::updateTopbarVisibility()
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTopbarVisible(ratio);
|
setTopbarVisible(ratio);
|
||||||
customScreens[leftIdx]->decorate();
|
customScreens[leftIdx]->adjustLayout();
|
||||||
customScreens[leftIdx+1]->decorate();
|
customScreens[leftIdx+1]->adjustLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,22 +24,13 @@
|
|||||||
#include "widgets_container.h"
|
#include "widgets_container.h"
|
||||||
|
|
||||||
template<int N, int O>
|
template<int N, int O>
|
||||||
class WidgetsContainer: public WidgetsContainerInterface
|
class WidgetsContainerImpl: public WidgetsContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// struct ZonePersistentData {
|
|
||||||
// char widgetName[WIDGET_NAME_LEN];
|
|
||||||
// Widget::PersistentData widgetData;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// struct PersistentData {
|
|
||||||
// ZonePersistentData zones[N];
|
|
||||||
// ZoneOptionValueTyped options[O];
|
|
||||||
// };
|
|
||||||
typedef WidgetsContainerPersistentData<N,O> PersistentData;
|
typedef WidgetsContainerPersistentData<N,O> PersistentData;
|
||||||
|
|
||||||
WidgetsContainer(const rect_t & rect, PersistentData * persistentData):
|
WidgetsContainerImpl(const rect_t & rect, PersistentData * persistentData):
|
||||||
WidgetsContainerInterface(nullptr, rect, FORM_FORWARD_FOCUS),
|
WidgetsContainer(nullptr, rect, FORM_FORWARD_FOCUS),
|
||||||
persistentData(persistentData)
|
persistentData(persistentData)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -146,7 +137,7 @@ class WidgetsContainer: public WidgetsContainerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void decorate() override
|
void adjustLayout() override
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ struct WidgetsContainerPersistentData {
|
|||||||
|
|
||||||
typedef WidgetsContainerPersistentData<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS> TopBarPersistentData;
|
typedef WidgetsContainerPersistentData<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS> TopBarPersistentData;
|
||||||
|
|
||||||
class WidgetsContainerInterface: public FormGroup
|
class WidgetsContainer: public FormGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using FormGroup::FormGroup;
|
using FormGroup::FormGroup;
|
||||||
@@ -74,10 +74,7 @@ class WidgetsContainerInterface: public FormGroup
|
|||||||
virtual Widget * createWidget(unsigned int index, const WidgetFactory * factory) = 0;
|
virtual Widget * createWidget(unsigned int index, const WidgetFactory * factory) = 0;
|
||||||
virtual Widget * getWidget(unsigned int index) = 0;
|
virtual Widget * getWidget(unsigned int index) = 0;
|
||||||
virtual void removeWidget(unsigned int index) = 0;
|
virtual void removeWidget(unsigned int index) = 0;
|
||||||
|
virtual void adjustLayout() = 0;
|
||||||
// this should go away...
|
|
||||||
virtual const LayoutFactory * getFactory() const = 0;
|
|
||||||
virtual void decorate() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user