feat(color): Convert theme save/delete dialogs to use ConfirmDialog popup (#3062)

* Convert theme save and delete dialogs to use ConfirmDialog popup instead of full screen alert.
Add strings for translation.

* Update translations.

* Update translations.

* Update translations.

* CZ translation

* chore: Formatting

* Call 'cancelHandler' if RTN button used to exit ConfirmDialog.

* Possible fix for 'save theme' dialog not working in the theme editor.
This commit is contained in:
philmoz
2023-01-28 10:48:23 +10:00
committed by GitHub
parent 7bbaa0909a
commit e9b8a23ba4
22 changed files with 89 additions and 36 deletions
+16 -9
View File
@@ -26,35 +26,42 @@
ConfirmDialog::ConfirmDialog(Window* parent, const char* title,
const char* message,
std::function<void(void)> confirmHandler) :
std::function<void(void)> confirmHandler,
std::function<void(void)> cancelHandler) :
Dialog(parent, title, rect_t{}),
confirmHandler(std::move(confirmHandler))
confirmHandler(std::move(confirmHandler)),
cancelHandler(std::move(cancelHandler))
{
auto form = &content->form;
auto msg = new StaticText(form, rect_t{}, message);
msg->padAll(lv_dpx(16));
lv_obj_set_style_bg_color(content->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0);
lv_obj_set_style_bg_color(content->getLvObj(),
makeLvColor(COLOR_THEME_SECONDARY3), 0);
auto box = new FormGroup(form, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW);
lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0);
auto box_obj = box->getLvObj();
lv_obj_set_style_flex_main_place(box_obj, LV_FLEX_ALIGN_SPACE_EVENLY, 0);
auto btn = new TextButton(box, rect_t{}, STR_NO, [=]() -> int8_t {
this->deleteLater();
onCancel();
return 0;
});
lv_obj_set_width(btn->getLvObj(), LV_DPI_DEF);
btn->setWidth(LV_DPI_DEF);
btn = new TextButton(box, rect_t{}, STR_YES, [=]() -> int8_t {
this->deleteLater();
this->confirmHandler();
return 0;
});
lv_obj_set_width(btn->getLvObj(), LV_DPI_DEF);
btn->setWidth(LV_DPI_DEF);
content->setWidth(LCD_W * 0.8);
content->updateSize();
}
void ConfirmDialog::onCancel()
{
deleteLater();
if (cancelHandler) cancelHandler();
}
+6 -2
View File
@@ -28,10 +28,14 @@ class ConfirmDialog : public Dialog
{
public:
ConfirmDialog(Window* parent, const char* title, const char* message,
std::function<void(void)> confirmHandler);
std::function<void(void)> confirmHandler,
std::function<void(void)> cancelHandler = nullptr);
protected:
std::function<void(void)> confirmHandler;
std::function<void(void)> cancelHandler;
void onCancel() override;
};
#endif // _CONFIRM_DIALOG_H_
#endif // _CONFIRM_DIALOG_H_
+3 -2
View File
@@ -31,7 +31,7 @@ PageHeader::PageHeader(Page * parent, uint8_t icon):
#if defined(HARDWARE_TOUCH)
new Button(this, { 0, 0, MENU_HEADER_BACK_BUTTON_WIDTH, MENU_HEADER_BACK_BUTTON_HEIGHT },
[=]() -> uint8_t {
parent->deleteLater();
parent->onCancel();
return 0;
}, NO_FOCUS | FORM_NO_BORDER);
#endif
@@ -76,7 +76,8 @@ void Page::paint(BitmapBuffer * dc)
void Page::onCancel()
{
deleteLater();
if (canCancel())
deleteLater();
}
void Page::onClicked()
+2
View File
@@ -58,6 +58,8 @@ class Page : public Window
void paint(BitmapBuffer* dc) override;
void deleteLater(bool detach = true, bool trash = true) override;
virtual bool canCancel() { return true; }
protected:
PageHeader header;
FormWindow body;
+24 -19
View File
@@ -368,17 +368,23 @@ class ThemeEditPage : public Page
buildHeader(&header);
}
void deleteLater(bool detach = true, bool trash = true) override
bool canCancel() override
{
if (_dirty) {
if (confirmationDialog("Save Theme?", _theme.getName())) {
if (saveHandler != nullptr) {
saveHandler(_theme);
}
}
new ConfirmDialog(
this, STR_SAVE_THEME, _theme.getName(),
[=]() {
if (saveHandler != nullptr) {
saveHandler(_theme);
}
deleteLater();
},
[=]() {
deleteLater();
});
return false;
}
Page::deleteLater(detach, trash);
return true;
}
void editColorPage()
@@ -401,10 +407,7 @@ class ThemeEditPage : public Page
}
// page title
new StaticText(window,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT,
PAGE_LINE_HEIGHT},
STR_EDIT_THEME, 0, COLOR_THEME_PRIMARY2 | flags);
header.setTitle(STR_EDIT_THEME);
_themeName = new StaticText(window,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP + PAGE_LINE_HEIGHT,
LCD_W - PAGE_TITLE_LEFT, PAGE_LINE_HEIGHT},
@@ -561,15 +564,17 @@ void ThemeSetupPage::displayThemeMenu(Window *window, ThemePersistance *tp)
});
});
// you cant delete the default theme or the currently active theme
// you can't delete the default theme or the currently active theme
if (listBox->getSelected() != 0 && listBox->getSelected() != tp->getThemeIndex()) {
menu->addLine(STR_DELETE, [=] () {
if (confirmationDialog("Delete Theme?", tp->getThemeByIndex(listBox->getSelected())->getName())) {
tp->deleteThemeByIndex(listBox->getSelected());
listBox->setNames(tp->getNames());
currentTheme = min<int>(currentTheme, tp->getNames().size() - 1);
listBox->setSelected(currentTheme);
}
new ConfirmDialog(
window, STR_DELETE_THEME,
tp->getThemeByIndex(listBox->getSelected())->getName(), [=] {
tp->deleteThemeByIndex(listBox->getSelected());
listBox->setNames(tp->getNames());
currentTheme = min<int>(currentTheme, tp->getNames().size() - 1);
listBox->setSelected(currentTheme);
});
});
}
}