widget preview while setting up

This commit is contained in:
Raphael Coeffic
2021-04-04 15:46:05 +02:00
parent f389d364d6
commit aff897550e
3 changed files with 33 additions and 13 deletions
+7 -7
View File
@@ -155,23 +155,21 @@ class SetupWidgetsPageSlot: public Button
screen(screen),
slotIndex(slotIndex)
{
widget = screen->getWidget(slotIndex);
setPressHandler([=](){
Menu * menu = new Menu(this);
menu->addLine("Select a widget", [=]() {
Menu * menu = new Menu(this);
for (auto factory: getRegisteredWidgets()) {
menu->addLine(factory->getName(), [=]() {
if (widget) {
widget->deleteLater();
}
// widget = factory->create(this, {1, 1, width() - 2, height() - 2}, &g_model.screenData[pageIndex].layoutData.zones[slotIndex].widgetData, true);
screen->createWidget(slotIndex, factory);
if (widget) widget->deleteLater();
widget = screen->createWidget(slotIndex, factory);
return 0;
});
}
return 0;
});
if (widget /*g_model.screenData[pageIndex].layoutData.zones[slotIndex].widgetName[0]*/) {
if (widget) {
menu->addLine(STR_DELETE, [=]() {
widget->deleteLater();
widget = nullptr;
@@ -190,12 +188,14 @@ class SetupWidgetsPageSlot: public Button
else {
dc->drawRect(0, 0, width(), height(), 1, DOTTED, DEFAULT_COLOR);
}
if (widget)
widget->paint(dc);
}
protected:
Layout * screen;
uint8_t slotIndex;
Window * widget = nullptr;
Widget * widget = nullptr;
};
class SetupWidgetsPage: public FormWindow
+10
View File
@@ -71,6 +71,16 @@ class Widget : public FormField
return &persistentData->options[index].value;
}
inline PersistentData * getPersistentData()
{
return persistentData;
}
void paint(BitmapBuffer * dc) override
{
FormField::paint(dc);
}
virtual void background()
{
}
+16 -6
View File
@@ -30,7 +30,8 @@ class WidgetsContainerInterface
public:
virtual unsigned int getZonesCount() const = 0;
virtual rect_t getZone(unsigned int index) const = 0;
virtual void 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;
};
#define WIDGET_NAME_LEN 10
@@ -55,16 +56,25 @@ class WidgetsContainer: public FormGroup, public WidgetsContainerInterface
{
}
void createWidget(unsigned int index, const WidgetFactory * factory) override
Widget * createWidget(unsigned int index, const WidgetFactory * factory) override
{
Widget * widget = nullptr;
memset(persistentData->zones[index].widgetName, 0, sizeof(persistentData->zones[index].widgetName));
if (factory) {
strncpy(persistentData->zones[index].widgetName, factory->getName(), sizeof(persistentData->zones[index].widgetName));
widgets[index] = factory->create(this, getZone(index), &persistentData->zones[index].widgetData);
}
else {
widgets[index] = nullptr;
widget = factory->create(this, getZone(index), &persistentData->zones[index].widgetData);
}
widgets[index] = widget;
return widget;
}
Widget * getWidget(unsigned int index) override
{
if (index < N)
return widgets[index];
return nullptr;
}
virtual void create()