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 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 showAlertBox(const char * title, const char * text, const char * action, uint8_t sound);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "opentx.h"
|
||||
#include "view_main.h"
|
||||
|
||||
WidgetsContainerInterface * customScreens[MAX_CUSTOM_SCREENS] = {};
|
||||
WidgetsContainer * customScreens[MAX_CUSTOM_SCREENS] = {};
|
||||
|
||||
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
|
||||
//
|
||||
WidgetsContainerInterface *
|
||||
WidgetsContainer *
|
||||
loadLayout(const char * name, LayoutPersistentData * persistentData)
|
||||
{
|
||||
const LayoutFactory * factory = getLayoutFactory(name);
|
||||
@@ -137,7 +137,7 @@ void loadCustomScreens()
|
||||
// - new screen is configured into g_model
|
||||
// - the new screen is returned (not attached)
|
||||
//
|
||||
WidgetsContainerInterface *
|
||||
WidgetsContainer *
|
||||
createCustomScreen(const LayoutFactory* factory, unsigned customScreenIndex)
|
||||
{
|
||||
if (!factory || (customScreenIndex >= MAX_CUSTOM_SCREENS))
|
||||
|
||||
@@ -42,15 +42,15 @@ class LayoutFactory
|
||||
const char * getName() const { return name; }
|
||||
virtual void drawThumb(BitmapBuffer * dc, uint16_t x, uint16_t y, LcdFlags flags) const = 0;
|
||||
virtual const ZoneOption * getOptions() const = 0;
|
||||
virtual WidgetsContainerInterface * create(LayoutPersistentData * persistentData) const = 0;
|
||||
virtual WidgetsContainerInterface * load(LayoutPersistentData * persistentData) const = 0;
|
||||
virtual WidgetsContainer * create(LayoutPersistentData * persistentData) const = 0;
|
||||
virtual WidgetsContainer * load(LayoutPersistentData * persistentData) const = 0;
|
||||
|
||||
protected:
|
||||
const char * id;
|
||||
const char * name;
|
||||
};
|
||||
|
||||
WidgetsContainerInterface * loadLayout(const char * name, LayoutPersistentData * persistentData);
|
||||
WidgetsContainer * loadLayout(const char * name, LayoutPersistentData * persistentData);
|
||||
|
||||
// intented for new models
|
||||
void loadDefaultLayout();
|
||||
@@ -61,7 +61,7 @@ void loadCustomScreens();
|
||||
// delete all custom screens from memory
|
||||
void deleteCustomScreens();
|
||||
|
||||
WidgetsContainerInterface *
|
||||
WidgetsContainer *
|
||||
createCustomScreen(const LayoutFactory* factory, unsigned customScreenIndex);
|
||||
|
||||
// Remove custom screen from the model
|
||||
|
||||
@@ -29,7 +29,7 @@ Layout::Layout(const LayoutFactory * factory, PersistentData * persistentData):
|
||||
factory(factory),
|
||||
decoration(new ViewMainDecoration(this, getRect()))
|
||||
{
|
||||
decorate();
|
||||
adjustLayout();
|
||||
}
|
||||
|
||||
void Layout::create()
|
||||
@@ -54,7 +54,7 @@ void Layout::paint(BitmapBuffer * dc)
|
||||
void Layout::checkEvents()
|
||||
{
|
||||
LayoutBase::checkEvents();
|
||||
decorate();
|
||||
adjustLayout();
|
||||
|
||||
uint32_t now = RTOS_GET_MS();
|
||||
if (now - lastRefresh >= LAYOUT_REFRESH) {
|
||||
@@ -82,12 +82,7 @@ void Layout::setFlightModeVisible(bool visible)
|
||||
decoration->setFlightModeVisible(visible);
|
||||
}
|
||||
|
||||
void Layout::adjustDecoration()
|
||||
{
|
||||
decoration->adjustDecoration();
|
||||
}
|
||||
|
||||
void Layout::decorate()
|
||||
void Layout::adjustLayout()
|
||||
{
|
||||
// Check if deco setting are still up-to-date
|
||||
uint8_t checkSettings =
|
||||
@@ -110,7 +105,7 @@ void Layout::decorate()
|
||||
setFlightModeVisible(hasFlightMode());
|
||||
|
||||
// Re-compute positions
|
||||
adjustDecoration();
|
||||
decoration->adjustDecoration();
|
||||
|
||||
// and update relevant windows
|
||||
updateZones();
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
class ViewMainDecoration;
|
||||
|
||||
typedef WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> LayoutBase;
|
||||
typedef WidgetsContainerImpl<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> LayoutBase;
|
||||
|
||||
class Layout: public LayoutBase
|
||||
{
|
||||
@@ -61,7 +61,7 @@ class Layout: public LayoutBase
|
||||
|
||||
void create() override;
|
||||
|
||||
const LayoutFactory * getFactory() const override
|
||||
const LayoutFactory * getFactory() const
|
||||
{
|
||||
return factory;
|
||||
}
|
||||
@@ -93,11 +93,8 @@ class Layout: public LayoutBase
|
||||
void setSlidersVisible(bool visible);
|
||||
void setFlightModeVisible(bool visible);
|
||||
|
||||
// Re-calculate positions
|
||||
void adjustDecoration();
|
||||
|
||||
// Updates settings for trims, sliders, pots, etc...
|
||||
void decorate() override;
|
||||
void adjustLayout() override;
|
||||
|
||||
protected:
|
||||
const LayoutFactory * factory = nullptr;
|
||||
|
||||
@@ -25,7 +25,7 @@ const char * const STR_MONTHS[] = TR_MONTHS;
|
||||
constexpr uint32_t TOPBAR_REFRESH = 1000 / 2; // 2 Hz
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "topbar.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:
|
||||
public TopbarImplBase,
|
||||
@@ -54,13 +54,6 @@ class TopbarImpl:
|
||||
void paint(BitmapBuffer * dc) 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:
|
||||
uint32_t lastRefresh = 0;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "widget_settings.h"
|
||||
#include "topbar.h"
|
||||
#include "libopenui.h"
|
||||
#include "layouts/layout_factory_impl.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
@@ -108,7 +109,7 @@ class LayoutChoice: public FormField
|
||||
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)
|
||||
{
|
||||
setPressHandler([parent, container, slotIndex]() -> uint8_t {
|
||||
@@ -353,32 +354,39 @@ static void updateLayoutOptions(FormGroup* optionsWindow, unsigned customScreenI
|
||||
|
||||
// Layout options...
|
||||
int index = 0;
|
||||
auto factory = customScreens[customScreenIndex]->getFactory();
|
||||
if (factory) {
|
||||
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();
|
||||
}
|
||||
auto layout = dynamic_cast<Layout*>(customScreens[customScreenIndex]);
|
||||
if (!layout) {
|
||||
return;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -398,7 +406,11 @@ void ScreenSetupPage::build(FormWindow * window)
|
||||
rect_t optRect = {0, grid.getWindowHeight(), window->width(), 0};
|
||||
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) {
|
||||
// delete any options potentially accessing
|
||||
// the old custom screen
|
||||
|
||||
@@ -58,7 +58,7 @@ class ScreenSetupPage: public PageTab {
|
||||
class SetupWidgetsPageSlot: public Button
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -164,7 +164,7 @@ void ViewMain::updateTopbarVisibility()
|
||||
int leftScroll = getScrollPositionX() % pageWidth;
|
||||
if (leftScroll == 0) {
|
||||
setTopbarVisible(hasTopbar(g_model.view));
|
||||
customScreens[g_model.view]->decorate();
|
||||
customScreens[g_model.view]->adjustLayout();
|
||||
}
|
||||
else {
|
||||
int leftIdx = getScrollPositionX() / pageWidth;
|
||||
@@ -185,8 +185,8 @@ void ViewMain::updateTopbarVisibility()
|
||||
}
|
||||
|
||||
setTopbarVisible(ratio);
|
||||
customScreens[leftIdx]->decorate();
|
||||
customScreens[leftIdx+1]->decorate();
|
||||
customScreens[leftIdx]->adjustLayout();
|
||||
customScreens[leftIdx+1]->adjustLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,22 +24,13 @@
|
||||
#include "widgets_container.h"
|
||||
|
||||
template<int N, int O>
|
||||
class WidgetsContainer: public WidgetsContainerInterface
|
||||
class WidgetsContainerImpl: public WidgetsContainer
|
||||
{
|
||||
public:
|
||||
// struct ZonePersistentData {
|
||||
// char widgetName[WIDGET_NAME_LEN];
|
||||
// Widget::PersistentData widgetData;
|
||||
// };
|
||||
|
||||
// struct PersistentData {
|
||||
// ZonePersistentData zones[N];
|
||||
// ZoneOptionValueTyped options[O];
|
||||
// };
|
||||
typedef WidgetsContainerPersistentData<N,O> PersistentData;
|
||||
|
||||
WidgetsContainer(const rect_t & rect, PersistentData * persistentData):
|
||||
WidgetsContainerInterface(nullptr, rect, FORM_FORWARD_FOCUS),
|
||||
WidgetsContainerImpl(const rect_t & rect, PersistentData * persistentData):
|
||||
WidgetsContainer(nullptr, rect, FORM_FORWARD_FOCUS),
|
||||
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;
|
||||
|
||||
class WidgetsContainerInterface: public FormGroup
|
||||
class WidgetsContainer: public FormGroup
|
||||
{
|
||||
public:
|
||||
using FormGroup::FormGroup;
|
||||
@@ -74,10 +74,7 @@ class WidgetsContainerInterface: public FormGroup
|
||||
virtual Widget * createWidget(unsigned int index, const WidgetFactory * factory) = 0;
|
||||
virtual Widget * getWidget(unsigned int index) = 0;
|
||||
virtual void removeWidget(unsigned int index) = 0;
|
||||
|
||||
// this should go away...
|
||||
virtual const LayoutFactory * getFactory() const = 0;
|
||||
virtual void decorate() = 0;
|
||||
virtual void adjustLayout() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user