feat(color): Skip "Select widget" popup when adding widget to an empty slot (#4356)
This commit is contained in:
@@ -20,16 +20,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "widgets_setup.h"
|
#include "widgets_setup.h"
|
||||||
#include "menu_screen.h"
|
|
||||||
#include "view_main.h"
|
|
||||||
#include "widget_settings.h"
|
|
||||||
#include "widget.h"
|
|
||||||
|
|
||||||
#include "layer.h"
|
|
||||||
#include "menu.h"
|
|
||||||
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include "layer.h"
|
||||||
|
#include "menu.h"
|
||||||
|
#include "menu_screen.h"
|
||||||
#include "translations.h"
|
#include "translations.h"
|
||||||
|
#include "view_main.h"
|
||||||
|
#include "widget.h"
|
||||||
|
#include "widget_settings.h"
|
||||||
|
|
||||||
SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormWindow* parent,
|
SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormWindow* parent,
|
||||||
const rect_t& rect,
|
const rect_t& rect,
|
||||||
@@ -37,41 +36,48 @@ SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormWindow* parent,
|
|||||||
uint8_t slotIndex) :
|
uint8_t slotIndex) :
|
||||||
Button(parent, rect)
|
Button(parent, rect)
|
||||||
{
|
{
|
||||||
setPressHandler([parent, container, slotIndex]() -> uint8_t {
|
setPressHandler([=]() -> uint8_t {
|
||||||
Menu* menu = new Menu(parent);
|
|
||||||
menu->addLine(STR_SELECT_WIDGET, [=]() {
|
|
||||||
Menu* menu = new Menu(parent);
|
|
||||||
for (auto factory : getRegisteredWidgets()) {
|
|
||||||
menu->addLine(factory->getDisplayName(), [=]() {
|
|
||||||
container->createWidget(slotIndex, factory);
|
|
||||||
auto widget = container->getWidget(slotIndex);
|
|
||||||
if (widget->getOptions() && widget->getOptions()->name)
|
|
||||||
new WidgetSettings(parent, widget);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (container->getWidget(slotIndex)) {
|
if (container->getWidget(slotIndex)) {
|
||||||
|
Menu* menu = new Menu(parent);
|
||||||
|
menu->addLine(STR_SELECT_WIDGET,
|
||||||
|
[=]() { addNewWidget(container, slotIndex); });
|
||||||
auto widget = container->getWidget(slotIndex);
|
auto widget = container->getWidget(slotIndex);
|
||||||
if (widget->getOptions() && widget->getOptions()->name)
|
if (widget->getOptions() && widget->getOptions()->name)
|
||||||
menu->addLine(STR_WIDGET_SETTINGS,
|
menu->addLine(STR_WIDGET_SETTINGS,
|
||||||
[=]() { new WidgetSettings(parent, widget); });
|
[=]() { new WidgetSettings(parent, widget); });
|
||||||
menu->addLine(STR_REMOVE_WIDGET,
|
menu->addLine(STR_REMOVE_WIDGET,
|
||||||
[=]() { container->removeWidget(slotIndex); });
|
[=]() { container->removeWidget(slotIndex); });
|
||||||
|
} else {
|
||||||
|
addNewWidget(container, slotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetupWidgetsPageSlot::addNewWidget(WidgetsContainer* container,
|
||||||
|
uint8_t slotIndex)
|
||||||
|
{
|
||||||
|
Menu* menu = new Menu(parent);
|
||||||
|
menu->setTitle(STR_SELECT_WIDGET);
|
||||||
|
for (auto factory : getRegisteredWidgets()) {
|
||||||
|
menu->addLine(factory->getDisplayName(), [=]() {
|
||||||
|
container->createWidget(slotIndex, factory);
|
||||||
|
auto widget = container->getWidget(slotIndex);
|
||||||
|
if (widget->getOptions() && widget->getOptions()->name)
|
||||||
|
new WidgetSettings(parent, widget);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetupWidgetsPageSlot::paint(BitmapBuffer* dc)
|
void SetupWidgetsPageSlot::paint(BitmapBuffer* dc)
|
||||||
{
|
{
|
||||||
dc->drawRect(0, 0, width(), height(), 2, hasFocus() ? STASHED : SOLID, COLOR_THEME_FOCUS);
|
dc->drawRect(0, 0, width(), height(), 2, hasFocus() ? STASHED : SOLID,
|
||||||
|
COLOR_THEME_FOCUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupWidgetsPage::SetupWidgetsPage(uint8_t customScreenIdx) :
|
SetupWidgetsPage::SetupWidgetsPage(uint8_t customScreenIdx) :
|
||||||
FormWindow(ViewMain::instance(), rect_t{}),
|
FormWindow(ViewMain::instance(), rect_t{}), customScreenIdx(customScreenIdx)
|
||||||
customScreenIdx(customScreenIdx)
|
|
||||||
{
|
{
|
||||||
Layer::push(this);
|
Layer::push(this);
|
||||||
|
|
||||||
@@ -98,20 +104,16 @@ SetupWidgetsPage::SetupWidgetsPage(uint8_t customScreenIdx) :
|
|||||||
this->deleteLater();
|
this->deleteLater();
|
||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
NO_FOCUS,
|
NO_FOCUS, 0, window_create);
|
||||||
0, window_create);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupWidgetsPage::onClicked()
|
void SetupWidgetsPage::onClicked()
|
||||||
{
|
{
|
||||||
// block event forwarding (window is transparent)
|
// block event forwarding (window is transparent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupWidgetsPage::onCancel()
|
void SetupWidgetsPage::onCancel() { deleteLater(); }
|
||||||
{
|
|
||||||
deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetupWidgetsPage::deleteLater(bool detach, bool trash)
|
void SetupWidgetsPage::deleteLater(bool detach, bool trash)
|
||||||
{
|
{
|
||||||
@@ -133,8 +135,9 @@ void SetupWidgetsPage::deleteLater(bool detach, bool trash)
|
|||||||
void SetupWidgetsPage::onEvent(event_t event)
|
void SetupWidgetsPage::onEvent(event_t event)
|
||||||
{
|
{
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
if (event == EVT_KEY_FIRST(KEY_PAGEUP) || event == EVT_KEY_FIRST(KEY_PAGEDN) ||
|
if (event == EVT_KEY_FIRST(KEY_PAGEUP) ||
|
||||||
event == EVT_KEY_FIRST(KEY_SYS) || event == EVT_KEY_FIRST(KEY_MODEL)) {
|
event == EVT_KEY_FIRST(KEY_PAGEDN) || event == EVT_KEY_FIRST(KEY_SYS) ||
|
||||||
|
event == EVT_KEY_FIRST(KEY_MODEL)) {
|
||||||
killEvents(event);
|
killEvents(event);
|
||||||
} else if (event == EVT_KEY_FIRST(KEY_TELE)) {
|
} else if (event == EVT_KEY_FIRST(KEY_TELE)) {
|
||||||
onCancel();
|
onCancel();
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "form.h"
|
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
#include "form.h"
|
||||||
|
|
||||||
class ScreenMenu;
|
class ScreenMenu;
|
||||||
class WidgetsContainer;
|
class WidgetsContainer;
|
||||||
@@ -46,7 +46,7 @@ class SetupWidgetsPage : public FormWindow
|
|||||||
protected:
|
protected:
|
||||||
uint8_t customScreenIdx;
|
uint8_t customScreenIdx;
|
||||||
unsigned savedView = 0;
|
unsigned savedView = 0;
|
||||||
void onEvent(event_t event) override;
|
void onEvent(event_t event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetupWidgetsPageSlot : public Button
|
class SetupWidgetsPageSlot : public Button
|
||||||
@@ -56,4 +56,7 @@ class SetupWidgetsPageSlot : public Button
|
|||||||
WidgetsContainer* container, uint8_t slotIndex);
|
WidgetsContainer* container, uint8_t slotIndex);
|
||||||
|
|
||||||
void paint(BitmapBuffer* dc) override;
|
void paint(BitmapBuffer* dc) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void addNewWidget(WidgetsContainer* container, uint8_t slotIndex);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user