widget preview while setting up
This commit is contained in:
@@ -155,23 +155,21 @@ class SetupWidgetsPageSlot: public Button
|
|||||||
screen(screen),
|
screen(screen),
|
||||||
slotIndex(slotIndex)
|
slotIndex(slotIndex)
|
||||||
{
|
{
|
||||||
|
widget = screen->getWidget(slotIndex);
|
||||||
setPressHandler([=](){
|
setPressHandler([=](){
|
||||||
Menu * menu = new Menu(this);
|
Menu * menu = new Menu(this);
|
||||||
menu->addLine("Select a widget", [=]() {
|
menu->addLine("Select a widget", [=]() {
|
||||||
Menu * menu = new Menu(this);
|
Menu * menu = new Menu(this);
|
||||||
for (auto factory: getRegisteredWidgets()) {
|
for (auto factory: getRegisteredWidgets()) {
|
||||||
menu->addLine(factory->getName(), [=]() {
|
menu->addLine(factory->getName(), [=]() {
|
||||||
if (widget) {
|
if (widget) widget->deleteLater();
|
||||||
widget->deleteLater();
|
widget = screen->createWidget(slotIndex, factory);
|
||||||
}
|
|
||||||
// widget = factory->create(this, {1, 1, width() - 2, height() - 2}, &g_model.screenData[pageIndex].layoutData.zones[slotIndex].widgetData, true);
|
|
||||||
screen->createWidget(slotIndex, factory);
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
if (widget /*g_model.screenData[pageIndex].layoutData.zones[slotIndex].widgetName[0]*/) {
|
if (widget) {
|
||||||
menu->addLine(STR_DELETE, [=]() {
|
menu->addLine(STR_DELETE, [=]() {
|
||||||
widget->deleteLater();
|
widget->deleteLater();
|
||||||
widget = nullptr;
|
widget = nullptr;
|
||||||
@@ -190,12 +188,14 @@ class SetupWidgetsPageSlot: public Button
|
|||||||
else {
|
else {
|
||||||
dc->drawRect(0, 0, width(), height(), 1, DOTTED, DEFAULT_COLOR);
|
dc->drawRect(0, 0, width(), height(), 1, DOTTED, DEFAULT_COLOR);
|
||||||
}
|
}
|
||||||
|
if (widget)
|
||||||
|
widget->paint(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Layout * screen;
|
Layout * screen;
|
||||||
uint8_t slotIndex;
|
uint8_t slotIndex;
|
||||||
Window * widget = nullptr;
|
Widget * widget = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetupWidgetsPage: public FormWindow
|
class SetupWidgetsPage: public FormWindow
|
||||||
|
|||||||
@@ -71,6 +71,16 @@ class Widget : public FormField
|
|||||||
return &persistentData->options[index].value;
|
return &persistentData->options[index].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline PersistentData * getPersistentData()
|
||||||
|
{
|
||||||
|
return persistentData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint(BitmapBuffer * dc) override
|
||||||
|
{
|
||||||
|
FormField::paint(dc);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void background()
|
virtual void background()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ class WidgetsContainerInterface
|
|||||||
public:
|
public:
|
||||||
virtual unsigned int getZonesCount() const = 0;
|
virtual unsigned int getZonesCount() const = 0;
|
||||||
virtual rect_t getZone(unsigned int index) 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
|
#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));
|
memset(persistentData->zones[index].widgetName, 0, sizeof(persistentData->zones[index].widgetName));
|
||||||
if (factory) {
|
if (factory) {
|
||||||
strncpy(persistentData->zones[index].widgetName, factory->getName(), sizeof(persistentData->zones[index].widgetName));
|
strncpy(persistentData->zones[index].widgetName, factory->getName(), sizeof(persistentData->zones[index].widgetName));
|
||||||
widgets[index] = factory->create(this, getZone(index), &persistentData->zones[index].widgetData);
|
widget = factory->create(this, getZone(index), &persistentData->zones[index].widgetData);
|
||||||
}
|
|
||||||
else {
|
|
||||||
widgets[index] = nullptr;
|
|
||||||
}
|
}
|
||||||
|
widgets[index] = widget;
|
||||||
|
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget * getWidget(unsigned int index) override
|
||||||
|
{
|
||||||
|
if (index < N)
|
||||||
|
return widgets[index];
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void create()
|
virtual void create()
|
||||||
|
|||||||
Reference in New Issue
Block a user