chore(color): refactor window close / delete logic (#7804)

Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
philmoz
2026-09-25 13:44:46 +10:00
committed by GitHub
co-authored by Peter Feerick Claude Opus 5.5
parent 6a1cf34079
commit 598255e1d1
103 changed files with 539 additions and 390 deletions
+1 -1
View File
@@ -797,7 +797,7 @@ void checkAll(bool isBootCheck)
MainWindow::instance()->blockUntilClose(true, [=]() { MainWindow::instance()->blockUntilClose(true, [=]() {
if (dlg->deleted()) return true; if (dlg->deleted()) return true;
if ((tgtime < get_tmr10ms()) || !keyDown()) { if ((tgtime < get_tmr10ms()) || !keyDown()) {
dlg->deleteLater(); dlg->closeWindow();
return true; return true;
} }
return false; return false;
@@ -240,7 +240,7 @@ class BarColorType : public ColorType
~BarColorType() override ~BarColorType() override
{ {
for (int i = 0; i < MAX_BARS; i++) { for (int i = 0; i < MAX_BARS; i++) {
bars[i]->deleteLater(); bars[i]->closeWindow();
} }
}; };
@@ -70,7 +70,7 @@ class ColorEditorPopup : public BaseDialog
void onCancel() override void onCancel() override
{ {
if (setValue) setValue(origColor); if (setValue) setValue(origColor);
this->deleteLater(); this->closeWindow();
} }
public: public:
@@ -164,7 +164,7 @@ class ColorEditorPopup : public BaseDialog
new TextButton(hbox, rect_t{0, 0, BTN_W, 0}, STR_SAVE, [=]() -> int8_t { new TextButton(hbox, rect_t{0, 0, BTN_W, 0}, STR_SAVE, [=]() -> int8_t {
if (setValue) setValue(m_color); if (setValue) setValue(m_color);
this->deleteLater(); this->closeWindow();
return 0; return 0;
}); });
} }
@@ -205,7 +205,7 @@ void SourceChoice::openMenu()
// fillMenu(menu); - called by MenuToolbar // fillMenu(menu); - called by MenuToolbar
menu->setCloseHandler([=]() { setEditMode(false); }); menu->onClosing([=]() { setEditMode(false); });
} }
SourceChoice::SourceChoice(Window *parent, const rect_t &rect, int16_t vmin, SourceChoice::SourceChoice(Window *parent, const rect_t &rect, int16_t vmin,
@@ -38,7 +38,7 @@ void SwitchWarnDialog::checkEvents()
uint16_t bad_pots; uint16_t bad_pots;
if (!isSwitchWarningRequired(bad_pots)) { if (!isSwitchWarningRequired(bad_pots)) {
deleteLater(); closeWindow();
return; return;
}; };
@@ -92,5 +92,5 @@ void ThrottleWarnDialog::checkEvents()
extern bool isThrottleWarningAlertNeeded(); extern bool isThrottleWarningAlertNeeded();
if (!isThrottleWarningAlertNeeded()) if (!isThrottleWarningAlertNeeded())
deleteLater(); closeWindow();
} }
@@ -156,7 +156,7 @@ void SwitchChoice::openMenu()
// fillMenu(menu); - called by MenuToolbar // fillMenu(menu); - called by MenuToolbar
menu->setCloseHandler([=]() { setEditMode(false); }); menu->onClosing([=]() { setEditMode(false); });
} }
SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin, SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin,
+1
View File
@@ -25,6 +25,7 @@
#include "bitmapbuffer.h" #include "bitmapbuffer.h"
#include "board.h" #include "board.h"
#include "debug.h"
#include "etx_lv_theme.h" #include "etx_lv_theme.h"
#if !LV_USE_GPU_STM32_DMA2D && !defined(SIMU) #if !LV_USE_GPU_STM32_DMA2D && !defined(SIMU)
#include "dma2d.h" #include "dma2d.h"
+1 -1
View File
@@ -65,7 +65,7 @@ ButtonBase::ButtonBase(Window* parent, const rect_t& rect,
void ButtonBase::check(bool checked) void ButtonBase::check(bool checked)
{ {
if (!_deleted) { if (!deleted()) {
if (checked != this->checked()) { if (checked != this->checked()) {
if (checked) if (checked)
lv_obj_add_state(lvobj, LV_STATE_CHECKED); lv_obj_add_state(lvobj, LV_STATE_CHECKED);
+12 -6
View File
@@ -84,21 +84,27 @@ ButtonMatrix::ButtonMatrix(Window* parent, const rect_t& r) :
setWindowFlag(NO_FOCUS); setWindowFlag(NO_FOCUS);
lv_obj_add_event_cb(lvobj, btn_matrix_event, LV_EVENT_VALUE_CHANGED, this); lv_obj_add_event_cb(lvobj, btn_matrix_event, LV_EVENT_VALUE_CHANGED, this);
}
ButtonMatrix::~ButtonMatrix() { deallocate(); } onClosing([=]() {
deallocate();
});
}
void ButtonMatrix::deallocate() void ButtonMatrix::deallocate()
{ {
if (txt_cnt == 0) return;
for (uint8_t i = 0; i < txt_cnt; i++) { for (uint8_t i = 0; i < txt_cnt; i++) {
char* txt = lv_btnm_map[i]; char* txt = lv_btnm_map[i];
if (txt != _filler && txt != _newline && txt != _map_end) free(txt); if (txt != _filler && txt != _newline && txt != _map_end) free(txt);
} }
free(lv_btnm_map); if (lv_btnm_map) {
free(txt_index); free(lv_btnm_map);
lv_btnm_map = nullptr;
}
if (txt_index) {
free(txt_index);
txt_index = nullptr;
}
txt_cnt = 0; txt_cnt = 0;
btn_cnt = 0; btn_cnt = 0;
@@ -29,7 +29,6 @@ class ButtonMatrix : public FormField
public: public:
ButtonMatrix(Window* parent, const rect_t& rect); ButtonMatrix(Window* parent, const rect_t& rect);
~ButtonMatrix();
virtual void onPress(uint8_t btn_id) {} virtual void onPress(uint8_t btn_id) {}
virtual bool isActive(uint8_t btn_id) { return false; } virtual bool isActive(uint8_t btn_id) { return false; }
+1 -1
View File
@@ -234,5 +234,5 @@ void Choice::openMenu()
fillMenu(menu); fillMenu(menu);
menu->setCloseHandler([=]() { setEditMode(false); }); menu->onClosing([=]() { setEditMode(false); });
} }
+7 -7
View File
@@ -94,7 +94,7 @@ void ProgressDialog::updateProgress(int percentage)
void ProgressDialog::closeDialog() void ProgressDialog::closeDialog()
{ {
deleteLater(); closeWindow();
onClose(); onClose();
} }
@@ -114,7 +114,7 @@ MessageDialog::MessageDialog(const char* title,
} }
} }
void MessageDialog::onClicked() { deleteLater(); } void MessageDialog::onClicked() { closeWindow(); }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -130,7 +130,7 @@ DynamicMessageDialog::DynamicMessageDialog(
textHandler, color, textFlags); textHandler, color, textFlags);
} }
void DynamicMessageDialog::onClicked() { deleteLater(); } void DynamicMessageDialog::onClicked() { closeWindow(); }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -158,7 +158,7 @@ ConfirmDialog::ConfirmDialog(const char* title,
}); });
new TextButton(box, rect_t{0, 0, 96, 0}, STR_YES, [=]() -> int8_t { new TextButton(box, rect_t{0, 0, 96, 0}, STR_YES, [=]() -> int8_t {
this->deleteLater(); this->closeWindow();
this->confirmHandler(); this->confirmHandler();
return 0; return 0;
}); });
@@ -166,7 +166,7 @@ ConfirmDialog::ConfirmDialog(const char* title,
void ConfirmDialog::onCancel() void ConfirmDialog::onCancel()
{ {
deleteLater(); closeWindow();
if (cancelHandler) cancelHandler(); if (cancelHandler) cancelHandler();
} }
@@ -209,12 +209,12 @@ LabelDialog::LabelDialog(const char *label, int length, const char* title,
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_BETWEEN); LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_BETWEEN);
new TextButton(box, rect_t{0, 0, 96, 0}, STR_CANCEL, [=]() { new TextButton(box, rect_t{0, 0, 96, 0}, STR_CANCEL, [=]() {
deleteLater(); closeWindow();
return 0; return 0;
}); });
new TextButton(box, rect_t{0, 0, 96, 0}, STR_SAVE, [=]() { new TextButton(box, rect_t{0, 0, 96, 0}, STR_SAVE, [=]() {
deleteLater(); closeWindow();
if (saveHandler != nullptr) saveHandler(this->label); if (saveHandler != nullptr) saveHandler(this->label);
return 0; return 0;
}); });
+2 -2
View File
@@ -44,7 +44,7 @@ class BaseDialog : public ModalWindow
Window* form = nullptr; Window* form = nullptr;
StaticText* header = nullptr; StaticText* header = nullptr;
void onCancel() override { deleteLater(); } void onCancel() override { closeWindow(); }
void onEvent(event_t event) override {} void onEvent(event_t event) override {}
}; };
@@ -139,7 +139,7 @@ class LabelDialog : public ModalWindow
static constexpr int MAX_LABEL_LENGTH = 255; static constexpr int MAX_LABEL_LENGTH = 255;
void onCancel() override { deleteLater(); } void onCancel() override { closeWindow(); }
protected: protected:
std::function<void(std::string)> saveHandler; std::function<void(std::string)> saveHandler;
+1 -1
View File
@@ -191,7 +191,7 @@ void FileChoice::openMenu()
// fillMenu(menu); - called by MenuToolbar // fillMenu(menu); - called by MenuToolbar
menu->setCloseHandler([=]() { setEditMode(false); }); menu->onClosing([=]() { setEditMode(false); });
} else { } else {
new MessageDialog(STR_SDCARD, STR_NO_FILES_ON_SD); new MessageDialog(STR_SDCARD, STR_NO_FILES_ON_SD);
} }
+4 -8
View File
@@ -44,6 +44,10 @@ FormField::FormField(Window* parent, const rect_t& rect, LvglCreate objConstruct
{ {
setTextFlag(textFlags); setTextFlag(textFlags);
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); lv_obj_add_flag(lvobj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
onClosing([=]() {
if (isEditMode()) setEditMode(false);
});
} }
void FormField::setEditMode(bool newEditMode) void FormField::setEditMode(bool newEditMode)
@@ -73,14 +77,6 @@ void FormField::onCancel()
} }
} }
void FormField::deleteLater()
{
if (_deleted) return;
if (isEditMode()) setEditMode(false);
Window::deleteLater();
}
FormLine::FormLine(Window* parent, FlexGridLayout& layout) : FormLine::FormLine(Window* parent, FlexGridLayout& layout) :
Window(parent, rect_t{}), layout(layout) Window(parent, rect_t{}), layout(layout)
{ {
-1
View File
@@ -95,7 +95,6 @@ class FormField : public Window
void onClicked() override; void onClicked() override;
void onCancel() override; void onCancel() override;
void deleteLater() override;
protected: protected:
bool editMode = false; bool editMode = false;
@@ -103,7 +103,7 @@ void FullScreenDialog::build()
auto btn = new TextButton( auto btn = new TextButton(
this, {LCD_W / 3 - TWOBTN_W / 2, LCD_H - TWOBTN_H - PAD_LARGE, TWOBTN_W, TWOBTN_H}, STR_CANCEL, this, {LCD_W / 3 - TWOBTN_W / 2, LCD_H - TWOBTN_H - PAD_LARGE, TWOBTN_W, TWOBTN_H}, STR_CANCEL,
[=]() { [=]() {
deleteLater(); closeWindow();
return 0; return 0;
}); });
etx_bg_color(btn->getLvObj(), COLOR_THEME_SECONDARY3_INDEX); etx_bg_color(btn->getLvObj(), COLOR_THEME_SECONDARY3_INDEX);
@@ -123,7 +123,7 @@ void FullScreenDialog::build()
void FullScreenDialog::closeDialog() void FullScreenDialog::closeDialog()
{ {
if (confirmHandler) confirmHandler(); if (confirmHandler) confirmHandler();
deleteLater(); closeWindow();
} }
bool FullScreenDialog::onLongPress() bool FullScreenDialog::onLongPress()
@@ -181,7 +181,7 @@ bool confirmationDialog(const char* title, const char* msg, bool checkPwr,
if (dialog->deleted()) return true; if (dialog->deleted()) return true;
if (closeCondition && closeCondition()) { if (closeCondition && closeCondition()) {
confirmed = true; confirmed = true;
dialog->deleteLater(); dialog->closeWindow();
} }
return confirmed; return confirmed;
}); });
@@ -44,7 +44,7 @@ class FullScreenDialog : public NavWindow
void setMessage(const char* text); void setMessage(const char* text);
bool onLongPress() override; bool onLongPress() override;
void onCancel() override { deleteLater(); } void onCancel() override { closeWindow(); }
void closeDialog(); void closeDialog();
+9 -12
View File
@@ -109,18 +109,15 @@ Keyboard::Keyboard(coord_t height) :
// TODO: really needed ??? // TODO: really needed ???
lv_obj_clear_flag(keyboard, LV_OBJ_FLAG_HIDDEN); lv_obj_clear_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
}
Keyboard::~Keyboard() onClosing([=]() {
{ // Can't use hide() here, it ignores a keyboard already marked as deleted
if (group) lv_group_del(group); if (activeKeyboard == this) {
} clearField(false);
activeKeyboard = nullptr;
void Keyboard::deleteLater() }
{ if (group) lv_group_del(group);
if (!_deleted) });
hide(false);
NavWindow::deleteLater();
} }
void Keyboard::clearField(bool wasCancelled) void Keyboard::clearField(bool wasCancelled)
@@ -160,7 +157,7 @@ void Keyboard::clearField(bool wasCancelled)
void Keyboard::hide(bool wasCancelled) void Keyboard::hide(bool wasCancelled)
{ {
if (activeKeyboard && !activeKeyboard->_deleted) { if (activeKeyboard && !activeKeyboard->deleted()) {
activeKeyboard->clearField(wasCancelled); activeKeyboard->clearField(wasCancelled);
lv_obj_add_flag(activeKeyboard->lvobj, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(activeKeyboard->lvobj, LV_OBJ_FLAG_HIDDEN);
activeKeyboard = nullptr; activeKeyboard = nullptr;
@@ -26,7 +26,6 @@ class Keyboard : public NavWindow
{ {
public: public:
explicit Keyboard(coord_t height); explicit Keyboard(coord_t height);
~Keyboard();
void clearField(bool wasCancelled); void clearField(bool wasCancelled);
static void hide(bool wasCancelled); static void hide(bool wasCancelled);
@@ -47,5 +46,4 @@ class Keyboard : public NavWindow
void setField(FormField* newField); void setField(FormField* newField);
bool attachKeyboard(); bool attachKeyboard();
void deleteLater() override;
}; };
@@ -130,9 +130,11 @@ NumberKeyboard::NumberKeyboard() : Keyboard(KEYBOARD_HEIGHT)
(const char**)number_kb_map, number_kb_ctrl_map); (const char**)number_kb_map, number_kb_ctrl_map);
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_USER_1); lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_USER_1);
}
NumberKeyboard::~NumberKeyboard() { _instance = nullptr; } onClosing([=]() {
_instance = nullptr;
});
}
void NumberKeyboard::open(FormField* field) void NumberKeyboard::open(FormField* field)
{ {
@@ -24,7 +24,6 @@ class NumberKeyboard : public Keyboard
{ {
public: public:
NumberKeyboard(); NumberKeyboard();
~NumberKeyboard() override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "NumberKeyboard"; } std::string getName() const override { return "NumberKeyboard"; }
@@ -23,9 +23,12 @@
constexpr coord_t KEYBOARD_HEIGHT = LCD_H * 2 / 5; constexpr coord_t KEYBOARD_HEIGHT = LCD_H * 2 / 5;
TextKeyboard* TextKeyboard::_instance = nullptr; TextKeyboard* TextKeyboard::_instance = nullptr;
TextKeyboard::TextKeyboard() : Keyboard(KEYBOARD_HEIGHT) {} TextKeyboard::TextKeyboard() : Keyboard(KEYBOARD_HEIGHT)
{
TextKeyboard::~TextKeyboard() { _instance = nullptr; } onClosing([=]() {
_instance = nullptr;
});
}
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
@@ -39,7 +39,6 @@ class TextKeyboard : public Keyboard
{ {
public: public:
TextKeyboard(); TextKeyboard();
~TextKeyboard() override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "TextKeyboard"; } std::string getName() const override { return "TextKeyboard"; }
@@ -67,11 +67,10 @@ InputMixButtonBase::InputMixButtonBase(Window* parent, uint8_t index) :
setWidth(BTN_W); setWidth(BTN_W);
setHeight(ListLineButton::BTN_H); setHeight(ListLineButton::BTN_H);
padAll(PAD_ZERO); padAll(PAD_ZERO);
}
InputMixButtonBase::~InputMixButtonBase() onClosing([=]() {
{ if (fm_buffer) free(fm_buffer);
if (fm_buffer) free(fm_buffer); });
} }
void InputMixButtonBase::setWeight(gvar_t value, gvar_t min, gvar_t max) void InputMixButtonBase::setWeight(gvar_t value, gvar_t min, gvar_t max)
@@ -196,7 +195,7 @@ void InputMixButtonBase::setFlightModes(uint16_t modes)
void InputMixButtonBase::checkEvents() void InputMixButtonBase::checkEvents()
{ {
ListLineButton::checkEvents(); ListLineButton::checkEvents();
if (!_deleted) { if (!deleted()) {
if (fm_canvas) { if (fm_canvas) {
bool chkd = lv_obj_get_state(fm_canvas) & LV_STATE_CHECKED; bool chkd = lv_obj_get_state(fm_canvas) & LV_STATE_CHECKED;
if (chkd != this->checked()) { if (chkd != this->checked()) {
@@ -50,7 +50,6 @@ class InputMixButtonBase : public ListLineButton
{ {
public: public:
InputMixButtonBase(Window* parent, uint8_t index); InputMixButtonBase(Window* parent, uint8_t index);
~InputMixButtonBase();
void setWeight(gvar_t value, gvar_t min, gvar_t max); void setWeight(gvar_t value, gvar_t min, gvar_t max);
void setSource(mixsrc_t idx); void setSource(mixsrc_t idx);
+4 -1
View File
@@ -97,7 +97,7 @@ void MainWindow::shutdown()
// clear layer stack first // clear layer stack first
for (Window* w = Window::topWindow(); w; w = Window::topWindow()) for (Window* w = Window::topWindow(); w; w = Window::topWindow())
w->deleteLater(); w->closeWindow();
clear(); clear();
emptyTrash(); emptyTrash();
@@ -126,6 +126,9 @@ bool MainWindow::setBackgroundImage(std::string& fileName)
return false; return false;
} }
// Note: windows closed while blocked are not destroyed until control returns
// to the top-level loop. Callers poll the closed window (e.g. dialog->deleted())
// and outer stack frames may still reference it.
void MainWindow::blockUntilClose(bool checkPwr, std::function<bool(void)> closeCondition, bool isError) void MainWindow::blockUntilClose(bool checkPwr, std::function<bool(void)> closeCondition, bool isError)
{ {
// reset input devices to avoid // reset input devices to avoid
+2 -2
View File
@@ -190,7 +190,7 @@ class MenuBody : public TableField
} else { } else {
// delete menu first to avoid // delete menu first to avoid
// focus issues with onPress() // focus issues with onPress()
menu->deleteLater(); menu->closeWindow();
lines[row]->onPress(); lines[row]->onPress();
} }
} }
@@ -422,7 +422,7 @@ void Menu::removeLines()
void Menu::onCancel() void Menu::onCancel()
{ {
if (cancelHandler) cancelHandler(); if (cancelHandler) cancelHandler();
deleteLater(); closeWindow();
} }
void Menu::setCancelHandler(std::function<void()> handler) void Menu::setCancelHandler(std::function<void()> handler)
+4 -2
View File
@@ -87,9 +87,11 @@ MenuToolbar::MenuToolbar(Choice* choice, Menu* menu, const int columns) :
else else
prevFilter(); prevFilter();
}); });
}
MenuToolbar::~MenuToolbar() { lv_group_del(group); } onClosing([=]() {
lv_group_del(group);
});
}
void MenuToolbar::resetFilter() void MenuToolbar::resetFilter()
{ {
@@ -37,7 +37,6 @@ class MenuToolbar : public Window
{ {
public: public:
MenuToolbar(Choice* choice, Menu* menu, const int columns); MenuToolbar(Choice* choice, Menu* menu, const int columns);
~MenuToolbar();
void resetFilter(); void resetFilter();
+1
View File
@@ -36,6 +36,7 @@ class Messaging
MENU_CHANGE_FILTER, MENU_CHANGE_FILTER,
REFRESH, REFRESH,
REFRESH_OUTPUTS_WIDGET, REFRESH_OUTPUTS_WIDGET,
ON_CLOSE,
}; };
Messaging() {} Messaging() {}
@@ -60,6 +60,6 @@ void ModalWindow::onClicked()
if (children.size() > 0) if (children.size() > 0)
children.front()->onCancel(); children.front()->onCancel();
else else
deleteLater(); closeWindow();
} }
} }
+1 -2
View File
@@ -113,8 +113,7 @@ Page::Page(EdgeTxIcon icon, PaddingSize padding, bool pauseRefresh) :
void Page::onCancel() void Page::onCancel()
{ {
if (!_deleted) closeWindow();
deleteLater();
} }
void Page::onClicked() { Keyboard::hide(false); } void Page::onClicked() { Keyboard::hide(false); }
+1 -1
View File
@@ -138,7 +138,7 @@ class BubbleDialog : public Window
void checkEvents() override void checkEvents() override
{ {
if (lv_tick_elaps(startTime) >= timeout) { if (lv_tick_elaps(startTime) >= timeout) {
deleteLater(); closeWindow();
} }
} }
+4 -9
View File
@@ -43,6 +43,9 @@ SliderBase::SliderBase(Window* parent, coord_t width, coord_t height, int32_t vm
_getValue(std::move(getValue)), _getValue(std::move(getValue)),
_setValue(std::move(setValue)) _setValue(std::move(setValue))
{ {
onClosing([=]() {
if (tickPts) delete tickPts;
});
} }
void SliderBase::update() void SliderBase::update()
@@ -58,14 +61,6 @@ void SliderBase::update()
} }
} }
void SliderBase::deleteLater()
{
if (!deleted()) {
if (tickPts) delete tickPts;
Window::deleteLater();
}
}
void SliderBase::setValue(int value) void SliderBase::setValue(int value)
{ {
if (_setValue != nullptr) if (_setValue != nullptr)
@@ -84,7 +79,7 @@ void SliderBase::checkEvents()
void SliderBase::enable(bool enabled) void SliderBase::enable(bool enabled)
{ {
if (!_deleted && slider) { if (!deleted() && slider) {
if (lv_obj_has_state(slider, LV_STATE_DISABLED) == enabled) { if (lv_obj_has_state(slider, LV_STATE_DISABLED) == enabled) {
if (enabled) if (enabled)
lv_obj_clear_state(slider, LV_STATE_DISABLED); lv_obj_clear_state(slider, LV_STATE_DISABLED);
-1
View File
@@ -42,7 +42,6 @@ class SliderBase : public Window
std::function<int()> _getValue; std::function<int()> _getValue;
std::function<void(int)> _setValue; std::function<void(int)> _setValue;
void deleteLater() override;
void checkEvents() override; void checkEvents() override;
static void slider_changed_cb(lv_event_t* e); static void slider_changed_cb(lv_event_t* e);
+11 -18
View File
@@ -176,14 +176,11 @@ StaticIcon::StaticIcon(Window* parent, coord_t x, coord_t y, const char* filenam
} }
etx_img_color(lvobj, currentColor, LV_PART_MAIN); etx_img_color(lvobj, currentColor, LV_PART_MAIN);
}
void StaticIcon::deleteLater() onClosing([=]() {
{ if (mask) free(mask);
if (_deleted) return; mask = nullptr;
if (mask) free(mask); });
mask = nullptr;
Window::deleteLater();
} }
void StaticIcon::setColor(LcdColorIndex color) void StaticIcon::setColor(LcdColorIndex color)
@@ -279,6 +276,11 @@ StaticBitmap::StaticBitmap(Window* parent, const rect_t& rect,
setWindowFlag(NO_FOCUS | NO_CLICK); setWindowFlag(NO_FOCUS | NO_CLICK);
setSource(filename); setSource(filename);
onClosing([=]() {
if (img) delete img;
img = nullptr;
});
} }
void StaticBitmap::setSource(const char *filename) void StaticBitmap::setSource(const char *filename)
@@ -302,11 +304,6 @@ void StaticBitmap::clearSource()
img = nullptr; img = nullptr;
} }
StaticBitmap::~StaticBitmap()
{
if (img) delete img;
}
bool StaticBitmap::hasImage() const bool StaticBitmap::hasImage() const
{ {
return img; return img;
@@ -345,15 +342,11 @@ StaticLZ4Image::StaticLZ4Image(Window* parent, coord_t x, coord_t y,
} }
lv_canvas_set_buffer(lvobj, imgData, w, h, LV_IMG_CF_TRUE_COLOR_ALPHA); lv_canvas_set_buffer(lvobj, imgData, w, h, LV_IMG_CF_TRUE_COLOR_ALPHA);
}
void StaticLZ4Image::deleteLater() onClosing([=]() {
{
if (!deleted()) {
if (imgData) lv_mem_free(imgData); if (imgData) lv_mem_free(imgData);
imgData = nullptr; imgData = nullptr;
Window::deleteLater(); });
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
-5
View File
@@ -126,8 +126,6 @@ class StaticIcon : public Window
StaticIcon(Window *parent, coord_t x, coord_t y, const char* filename, StaticIcon(Window *parent, coord_t x, coord_t y, const char* filename,
LcdColorIndex color); LcdColorIndex color);
void deleteLater() override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "StaticIcon"; } std::string getName() const override { return "StaticIcon"; }
#endif #endif
@@ -171,7 +169,6 @@ class StaticBitmap : public Window
public: public:
StaticBitmap(Window *parent, const rect_t &rect, StaticBitmap(Window *parent, const rect_t &rect,
const char *filename = nullptr); const char *filename = nullptr);
~StaticBitmap();
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "StaticBitmap"; } std::string getName() const override { return "StaticBitmap"; }
@@ -199,8 +196,6 @@ class StaticLZ4Image : public Window
protected: protected:
uint8_t *imgData = nullptr; uint8_t *imgData = nullptr;
void deleteLater() override;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
+10 -14
View File
@@ -180,6 +180,16 @@ TableField::TableField(Window* parent, const rect_t& rect) :
setWindowFlag(OPAQUE); setWindowFlag(OPAQUE);
lv_table_set_col_cnt(lvobj, 1); lv_table_set_col_cnt(lvobj, 1);
onClosing([=]() {
if (autoedit) {
lv_group_del(group);
if (oldGroup)
assignLvGroup(oldGroup, true);
else
lv_group_set_default(nullptr);
}
});
} }
void TableField::setRowCount(uint16_t rows) void TableField::setRowCount(uint16_t rows)
@@ -281,17 +291,3 @@ void TableField::setAutoEdit()
} }
}); });
} }
void TableField::deleteLater()
{
if (!deleted()) {
if (autoedit) {
lv_group_del(group);
if (oldGroup)
assignLvGroup(oldGroup, true);
else
lv_group_set_default(nullptr);
}
Window::deleteLater();
}
}
-2
View File
@@ -64,7 +64,5 @@ class TableField : public Window
bool onLongPress() override; bool onLongPress() override;
void deleteLater() override;
static void force_editing(lv_group_t* g) { lv_group_set_editing(g, true); } static void force_editing(lv_group_t* g) { lv_group_set_editing(g, true); }
}; };
+38 -33
View File
@@ -253,19 +253,6 @@ Window::Window(Window *parent, const rect_t &rect, LvglCreate objConstruct) :
} }
} }
Window::~Window()
{
TRACE_WINDOWS("Destroy %p %s", this, getWindowDebugString().c_str());
if (children.size() > 0) deleteChildren();
if (lvobj != nullptr) {
lv_obj_set_user_data(lvobj, nullptr);
lv_obj_del(lvobj);
lvobj = nullptr;
}
}
void Window::delayLoader(lv_event_t* e) void Window::delayLoader(lv_event_t* e)
{ {
auto w = (Window*)lv_obj_get_user_data(lv_event_get_target(e)); auto w = (Window*)lv_obj_get_user_data(lv_event_get_target(e));
@@ -370,9 +357,9 @@ void Window::clearTextFlag(LcdFlags flag) { textFlags &= ~flag; }
void Window::attach(Window *newParent) void Window::attach(Window *newParent)
{ {
if (parent) detach(); detach();
parent = newParent;
if (newParent) { if (newParent) {
parent = newParent;
newParent->addChild(this); newParent->addChild(this);
} }
} }
@@ -385,27 +372,45 @@ void Window::detach()
} }
} }
void Window::deleteLater() void Window::onClosing(CloseHandler h)
{ {
if (_deleted) return; closeHandlers.push_back(std::move(h));
_deleted = true; }
TRACE_WINDOWS("Delete %p %s", this, getWindowDebugString().c_str()); // Close the window, and all its children.
// Remove from LVGL and save the window pointer for later destruction.
void Window::closeWindow()
{
TRACE_WINDOWS("Close %p %s %s", this, getWindowDebugString().c_str(), deleted() ? "DELETED" : "");
if (!deleted()) {
_deleted = true;
detach(); // Recursively delete child objects
deleteChildren(); deleteChildren();
popLayer(); // Remove from parent
detach();
if (closeHandler) // Remove layer (if needed) before calling handlers, so any windows
closeHandler(); // created by a handler are added to the restored lv_group
popLayer();
Window::trash.push_back(this); // Call onClosing handler functions (reverse order of creation)
for (auto it = closeHandlers.rbegin(); it != closeHandlers.rend(); ++it) {
(*it)();
}
closeHandlers.clear();
if (lvobj != nullptr) { // Save for destructor call
auto obj = lvobj; trash.push_back(this);
lvobj = nullptr;
lv_obj_del(obj); // Remove from LVGL
if (lvobj != nullptr) {
auto obj = lvobj;
lvobj = nullptr;
lv_obj_set_user_data(obj, nullptr);
lv_obj_del(obj);
}
} }
} }
@@ -421,7 +426,7 @@ void Window::clear()
void Window::deleteChildren() void Window::deleteChildren()
{ {
while (!children.empty()) while (!children.empty())
children.back()->deleteLater(); children.back()->closeWindow();
} }
bool Window::hasFocus() const bool Window::hasFocus() const
@@ -516,7 +521,7 @@ FormLine *Window::newLine(FlexGridLayout &layout)
void Window::show(bool visible) void Window::show(bool visible)
{ {
if (!_deleted && lvobj) { if (!deleted() && lvobj) {
if (lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN) == visible) { if (lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN) == visible) {
if (visible) if (visible)
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_HIDDEN); lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
@@ -528,7 +533,7 @@ void Window::show(bool visible)
bool Window::isVisible() bool Window::isVisible()
{ {
return !_deleted && lvobj && !lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN); return !deleted() && lvobj && !lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
} }
bool Window::isOnScreen() bool Window::isOnScreen()
@@ -542,7 +547,7 @@ bool Window::isOnScreen()
void Window::enable(bool enabled) void Window::enable(bool enabled)
{ {
if (!_deleted && lvobj) { if (!deleted() && lvobj) {
if (lv_obj_has_state(lvobj, LV_STATE_DISABLED) == enabled) { if (lv_obj_has_state(lvobj, LV_STATE_DISABLED) == enabled) {
if (enabled) if (enabled)
lv_obj_clear_state(lvobj, LV_STATE_DISABLED); lv_obj_clear_state(lvobj, LV_STATE_DISABLED);
+5 -4
View File
@@ -53,7 +53,7 @@ class Window
Window(const rect_t &rect); Window(const rect_t &rect);
Window(Window *parent, const rect_t &rect, LvglCreate objConstruct = nullptr); Window(Window *parent, const rect_t &rect, LvglCreate objConstruct = nullptr);
virtual ~Window(); virtual ~Window() {}
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
virtual std::string getName() const; virtual std::string getName() const;
@@ -75,7 +75,7 @@ class Window
LcdFlags getTextFlags() const { return textFlags; } LcdFlags getTextFlags() const { return textFlags; }
typedef std::function<void()> CloseHandler; typedef std::function<void()> CloseHandler;
void setCloseHandler(CloseHandler h) { closeHandler = std::move(h); } void onClosing(CloseHandler h);
typedef std::function<void(bool)> FocusHandler; typedef std::function<void(bool)> FocusHandler;
void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); } void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); }
@@ -84,7 +84,6 @@ class Window
void setScrollHandler(ScrollHandler h) { scrollHandler = std::move(h); } void setScrollHandler(ScrollHandler h) { scrollHandler = std::move(h); }
virtual void clear(); virtual void clear();
virtual void deleteLater();
bool hasFocus() const; bool hasFocus() const;
@@ -189,8 +188,11 @@ class Window
void assignLvGroup(lv_group_t* g, bool setDefault); void assignLvGroup(lv_group_t* g, bool setDefault);
void closeWindow();
protected: protected:
static std::list<Window *> trash; static std::list<Window *> trash;
std::list<CloseHandler> closeHandlers;
rect_t rect; rect_t rect;
@@ -208,7 +210,6 @@ class Window
bool layerCreated = false; bool layerCreated = false;
bool parentHidden = false; bool parentHidden = false;
CloseHandler closeHandler;
FocusHandler focusHandler; FocusHandler focusHandler;
ScrollHandler scrollHandler; ScrollHandler scrollHandler;
+3 -3
View File
@@ -111,7 +111,7 @@ void LayoutFactory::deleteCustomScreens()
{ {
for (auto& screen : customScreens) { for (auto& screen : customScreens) {
if (screen) { if (screen) {
screen->deleteLater(); screen->closeWindow();
screen = nullptr; screen = nullptr;
} }
} }
@@ -200,7 +200,7 @@ WidgetsContainer* LayoutFactory::createCustomScreen(
auto& screen = customScreens[customScreenIndex]; auto& screen = customScreens[customScreenIndex];
if (screen != nullptr) if (screen != nullptr)
screen->deleteLater(); screen->closeWindow();
auto viewMain = ViewMain::instance(); auto viewMain = ViewMain::instance();
screen = create(viewMain, customScreenIndex); screen = create(viewMain, customScreenIndex);
@@ -417,7 +417,7 @@ void Layout::load()
for (unsigned int i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++) {
// remove old widget // remove old widget
if (widgets[i]) { if (widgets[i]) {
widgets[i]->deleteLater(); widgets[i]->closeWindow();
widgets[i] = nullptr; widgets[i] = nullptr;
} }
} }
@@ -73,9 +73,8 @@ class LayoutChoice : public Button
menu->select( menu->select(
std::distance(LayoutFactory::getRegisteredLayouts().begin(), it)); std::distance(LayoutFactory::getRegisteredLayouts().begin(), it));
menu->setCloseHandler([=]() { menu->onClosing([=]() {
if (!menu->deleted()) update();
update();
}); });
} }
@@ -181,7 +180,7 @@ void ScreenSetupPage::build(Window* window)
btn = new TextButton(line, rect_t{}, STR_SETUP_WIDGETS, btn = new TextButton(line, rect_t{}, STR_SETUP_WIDGETS,
[=]() -> uint8_t { [=]() -> uint8_t {
auto idx = customScreenIndex; auto idx = customScreenIndex;
window->getParent()->deleteLater(); window->getParent()->closeWindow();
new SetupWidgetsPage(idx); new SetupWidgetsPage(idx);
return 0; return 0;
}); });
@@ -302,7 +301,7 @@ void ScreenSetupPage::addScreen()
TRACE("Add screen: add screen: LayoutId = %s", g_model.getScreenLayoutId(newIdx)); TRACE("Add screen: add screen: LayoutId = %s", g_model.getScreenLayoutId(newIdx));
#if VERSION_MAJOR == 2 #if VERSION_MAJOR == 2
Window::pageGroup()->deleteLater(); Window::pageGroup()->closeWindow();
#endif #endif
QuickMenu::openPage((QMPage)(QM_UI_SCREEN1 + newIdx)); QuickMenu::openPage((QMPage)(QM_UI_SCREEN1 + newIdx));
@@ -62,7 +62,7 @@ void ScreenUserInterfacePage::build(Window* window)
new TextButton(line, rect_t{}, STR_SETUP_WIDGETS, new TextButton(line, rect_t{}, STR_SETUP_WIDGETS,
[=]() -> uint8_t { [=]() -> uint8_t {
window->getParent()->deleteLater(); window->getParent()->closeWindow();
new SetupTopBarWidgetsPage(); new SetupTopBarWidgetsPage();
return 0; return 0;
}); });
+2 -2
View File
@@ -103,7 +103,7 @@ void SetupTopBarWidgetsPage::onClicked()
void SetupTopBarWidgetsPage::onCancel() void SetupTopBarWidgetsPage::onCancel()
{ {
deleteLater(); closeWindow();
// restore screen setting tab on top // restore screen setting tab on top
QuickMenu::openPage(QM_UI_SETUP); QuickMenu::openPage(QM_UI_SETUP);
} }
@@ -210,7 +210,7 @@ void TopBar::load()
for (unsigned int i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++) {
// remove old widget // remove old widget
if (widgets[i]) { if (widgets[i]) {
widgets[i]->deleteLater(); widgets[i]->closeWindow();
widgets[i] = nullptr; widgets[i] = nullptr;
} }
} }
@@ -104,9 +104,11 @@ ViewMain::ViewMain() :
// create last to be on top // create last to be on top
topbar = new TopBar(this); topbar = new TopBar(this);
}
ViewMain::~ViewMain() { _instance = nullptr; } onClosing([=]() {
_instance = nullptr;
});
}
void ViewMain::addMainView(WidgetsContainer* view, uint32_t viewId) void ViewMain::addMainView(WidgetsContainer* view, uint32_t viewId)
{ {
@@ -370,7 +372,7 @@ void ViewMain::hideTopBarEdgeTxButton()
void ViewMain::_refreshWidgets() void ViewMain::_refreshWidgets()
{ {
if (!_deleted) { if (!deleted()) {
topbar->refreshWidgets(isVisible && hasTopbar()); topbar->refreshWidgets(isVisible && hasTopbar());
for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) { for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) {
if (customScreens[i]) if (customScreens[i])
@@ -32,8 +32,6 @@ class ViewMain : public NavWindow
explicit ViewMain(); explicit ViewMain();
public: public:
~ViewMain() override;
static ViewMain* instance(); static ViewMain* instance();
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
-2
View File
@@ -75,8 +75,6 @@ class Widget : public ButtonBase
Widget(const WidgetFactory* factory, Window* parent, const rect_t& rect, Widget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
int screenNum, int zoneNum); int screenNum, int zoneNum);
~Widget() override = default;
const WidgetFactory* getFactory() const { return factory; } const WidgetFactory* getFactory() const { return factory; }
const WidgetOption* getOptionDefinitions() const; const WidgetOption* getOptionDefinitions() const;
@@ -221,5 +221,5 @@ WidgetSettings::WidgetSettings(Widget* w) :
void WidgetSettings::onCancel() void WidgetSettings::onCancel()
{ {
widget->updateWithoutRefresh(); widget->updateWithoutRefresh();
deleteLater(); closeWindow();
} }
@@ -27,16 +27,13 @@ WidgetsContainer::WidgetsContainer(Window* parent, const rect_t& rect, uint8_t z
{ {
widgets = new Widget*[zoneCount]; widgets = new Widget*[zoneCount];
for (int i = 0; i < zoneCount; i += 1) widgets[i] = nullptr; for (int i = 0; i < zoneCount; i += 1) widgets[i] = nullptr;
}
void WidgetsContainer::deleteLater() onClosing([=]() {
{ for (int i = 0; i < zoneCount; i += 1)
if (deleted()) return; if (widgets[i]) widgets[i]->closeWindow();
for (int i = 0; i < zoneCount; i += 1) if (widgets) delete[] widgets;
if (widgets[i]) widgets[i]->deleteLater(); widgets = nullptr;
if (widgets) delete[] widgets; });
widgets = nullptr;
Window::deleteLater();
} }
Widget* WidgetsContainer::getWidget(unsigned int index) Widget* WidgetsContainer::getWidget(unsigned int index)
@@ -51,7 +48,7 @@ void WidgetsContainer::removeWidget(unsigned int index)
if (index >= zoneCount) return; if (index >= zoneCount) return;
if (widgets[index]) { if (widgets[index]) {
widgets[index]->deleteLater(); widgets[index]->closeWindow();
} }
widgets[index] = nullptr; widgets[index] = nullptr;
@@ -85,9 +82,9 @@ void WidgetsContainer::showWidgets(bool visible)
void WidgetsContainer::refreshWidgets(bool inForeground) void WidgetsContainer::refreshWidgets(bool inForeground)
{ {
if (!_deleted) { if (!deleted()) {
for (int i = 0; i < zoneCount; i++) { for (int i = 0; i < zoneCount; i++) {
if (widgets[i]) { if (widgets[i] && !widgets[i]->deleted()) {
if ((inForeground && widgets[i]->isOnScreen()) || widgets[i]->isFullscreen()) if ((inForeground && widgets[i]->isOnScreen()) || widgets[i]->isFullscreen())
widgets[i]->foreground(); widgets[i]->foreground();
else else
@@ -46,8 +46,6 @@ class WidgetsContainer: public Window
virtual bool isLayout() { return false; } virtual bool isLayout() { return false; }
virtual bool isAppMode() const { return false; } virtual bool isAppMode() const { return false; }
void deleteLater() override;
protected: protected:
uint8_t zoneCount = 0; uint8_t zoneCount = 0;
Widget** widgets = nullptr; Widget** widgets = nullptr;
@@ -150,7 +150,7 @@ void SetupWidgetsPage::onClicked()
void SetupWidgetsPage::onCancel() void SetupWidgetsPage::onCancel()
{ {
deleteLater(); closeWindow();
QuickMenu::openPage((QMPage)(QM_UI_SCREEN1 + customScreenIdx)); QuickMenu::openPage((QMPage)(QM_UI_SCREEN1 + customScreenIdx));
+1 -1
View File
@@ -234,7 +234,7 @@ void InputEditWindow::buildBody(Window* form)
void InputEditWindow::checkEvents() void InputEditWindow::checkEvents()
{ {
if (_deleted) return; if (deleted()) return;
ExpoData* input = expoAddress(index); ExpoData* input = expoAddress(index);
@@ -124,7 +124,7 @@ void ModelCurvesPage::rebuild(Window *window)
void ModelCurvesPage::editCurve(Window *window, uint8_t curve) void ModelCurvesPage::editCurve(Window *window, uint8_t curve)
{ {
Window *editWindow = new CurveEditWindow(curve); Window *editWindow = new CurveEditWindow(curve);
editWindow->setCloseHandler([=]() { rebuild(window); }); editWindow->onClosing([=]() { rebuild(window); });
} }
void ModelCurvesPage::presetMenu(Window *window, uint8_t index) void ModelCurvesPage::presetMenu(Window *window, uint8_t index)
@@ -486,7 +486,7 @@ void ModelFlightModesPage::build(Window* form)
btn->setWidth(ListLineButton::GRP_W); btn->setWidth(ListLineButton::GRP_W);
btn->setPressHandler([=]() { btn->setPressHandler([=]() {
(new FlightModeEdit(i))->setCloseHandler([=]() { btn->refresh(); }); (new FlightModeEdit(i))->onClosing([=]() { btn->refresh(); });
return btn->isActive(); return btn->isActive();
}); });
} }
+2 -2
View File
@@ -519,7 +519,7 @@ ModelGVarsPage::ModelGVarsPage(const PageDef& pageDef) :
void ModelGVarsPage::cleanup() void ModelGVarsPage::cleanup()
{ {
if (hdr) if (hdr)
hdr->deleteLater(); hdr->closeWindow();
hdr = nullptr; hdr = nullptr;
} }
@@ -549,7 +549,7 @@ void ModelGVarsPage::build(Window* window)
Menu* menu = new Menu(); Menu* menu = new Menu();
menu->addLine(STR_EDIT, [=]() { menu->addLine(STR_EDIT, [=]() {
Window* editWindow = new GVarEditWindow(index); Window* editWindow = new GVarEditWindow(index);
editWindow->setCloseHandler([=]() { rebuild(window); }); editWindow->onClosing([=]() { rebuild(window); });
}); });
menu->addLine(STR_CLEAR, [=]() { menu->addLine(STR_CLEAR, [=]() {
for (auto& flightMode : g_model.flightModeData) for (auto& flightMode : g_model.flightModeData)
@@ -331,7 +331,7 @@ void ModelInputsPage::editInput(uint8_t input, uint8_t index)
if (!line) return; if (!line) return;
auto edit = new InputEditWindow(input, index); auto edit = new InputEditWindow(input, index);
edit->setCloseHandler([=]() { edit->onClosing([=]() {
Messaging::send(Messaging::REFRESH); Messaging::send(Messaging::REFRESH);
group->refresh(); group->refresh();
group->adjustHeight(); group->adjustHeight();
@@ -368,10 +368,10 @@ void ModelInputsPage::deleteInput(uint8_t index)
group->removeLine(line); group->removeLine(line);
if (group->getLineCount() == 0) { if (group->getLineCount() == 0) {
group->deleteLater(); group->closeWindow();
removeGroup(group); removeGroup(group);
} else { } else {
line->deleteLater(); line->closeWindow();
} }
removeLine(line); removeLine(line);
@@ -552,7 +552,7 @@ void ModelLogicalSwitchesPage::newLS(Window* window, bool pasteLS)
rebuild(window); rebuild(window);
} else { } else {
Window* lsWindow = new LogicalSwitchEditPage(i); Window* lsWindow = new LogicalSwitchEditPage(i);
lsWindow->setCloseHandler([=]() { lsWindow->onClosing([=]() {
if (ls->func != LS_FUNC_NONE) { if (ls->func != LS_FUNC_NONE) {
focusIndex = i; focusIndex = i;
rebuild(window); rebuild(window);
@@ -597,7 +597,7 @@ void ModelLogicalSwitchesPage::build(Window* window)
Menu* menu = new Menu(); Menu* menu = new Menu();
menu->addLine(STR_EDIT, [=]() { menu->addLine(STR_EDIT, [=]() {
Window* lsWindow = new LogicalSwitchEditPage(i); Window* lsWindow = new LogicalSwitchEditPage(i);
lsWindow->setCloseHandler([=]() { lsWindow->onClosing([=]() {
if (ls->func == LS_FUNC_NONE) if (ls->func == LS_FUNC_NONE)
rebuild(window); rebuild(window);
else else
@@ -306,5 +306,5 @@ void ModelMixerScriptsPage::build(Window* window, int8_t focusIdx)
void ModelMixerScriptsPage::editLine(Window* window, uint8_t idx) void ModelMixerScriptsPage::editLine(Window* window, uint8_t idx)
{ {
Window* editWindow = new ScriptEditWindow(idx); Window* editWindow = new ScriptEditWindow(idx);
editWindow->setCloseHandler([=]() { rebuild(window, idx); }); editWindow->onClosing([=]() { rebuild(window, idx); });
} }
+8 -9
View File
@@ -82,13 +82,12 @@ class MixLineButton : public InputMixButtonBase
{ {
mplex = new MPlexIcon(parent, index); mplex = new MPlexIcon(parent, index);
delayLoad(); // mplex is a sibling (not a child) so must be closed explicitly
} onClosing([=]() {
mplex->closeWindow();
});
void deleteLater() override delayLoad();
{
if (mplex) mplex->deleteLater();
InputMixButtonBase::deleteLater();
} }
void delayedInit() override void delayedInit() override
@@ -350,7 +349,7 @@ void ModelMixesPage::editMix(uint8_t channel, uint8_t index)
if (!line) return; if (!line) return;
auto edit = new MixEditWindow(channel, index); auto edit = new MixEditWindow(channel, index);
edit->setCloseHandler([=]() { edit->onClosing([=]() {
MixData* mix = mixAddress(index); MixData* mix = mixAddress(index);
if (is_memclear(mix, sizeof(MixData))) { if (is_memclear(mix, sizeof(MixData))) {
deleteMix(index); deleteMix(index);
@@ -395,10 +394,10 @@ void ModelMixesPage::deleteMix(uint8_t index)
group->removeLine(line); group->removeLine(line);
if (group->getLineCount() == 0) { if (group->getLineCount() == 0) {
group->deleteLater(); group->closeWindow();
removeGroup(group); removeGroup(group);
} else { } else {
line->deleteLater(); line->closeWindow();
} }
removeLine(line); removeLine(line);
} }
@@ -287,5 +287,5 @@ void ModelOutputsPage::build(Window* window)
void ModelOutputsPage::editOutput(uint8_t channel, OutputLineButton* btn) void ModelOutputsPage::editOutput(uint8_t channel, OutputLineButton* btn)
{ {
(new OutputEditWindow(channel))->setCloseHandler([=]() { btn->refresh(); }); (new OutputEditWindow(channel))->onClosing([=]() { btn->refresh(); });
} }
@@ -360,8 +360,6 @@ class ModelsPageBody : public Window
} }
} }
closeHandler();
// Skip reloading model if re-selecting the active model // Skip reloading model if re-selecting the active model
if (model != modelCellManager.getCurrentModel()) { if (model != modelCellManager.getCurrentModel()) {
// store changes (if any) and load selected model // store changes (if any) and load selected model
@@ -392,6 +390,8 @@ class ModelsPageBody : public Window
storageDirty(EE_GENERAL); storageDirty(EE_GENERAL);
storageCheck(true); storageCheck(true);
} }
Messaging::send(Messaging::ON_CLOSE);
} }
void duplicateModel(ModelCell *model) void duplicateModel(ModelCell *model)
@@ -445,7 +445,7 @@ class ModelsPageBody : public Window
if (labels.size()) { if (labels.size()) {
auto menu = new Menu(true); auto menu = new Menu(true);
menu->setTitle(model->modelName); menu->setTitle(model->modelName);
menu->setCloseHandler([=]() { menu->onClosing([=]() {
if (isDirty) { if (isDirty) {
isDirty = false; isDirty = false;
update(); update();
@@ -701,7 +701,6 @@ void ModelLabelsWindow::buildBody(Window *window)
{ {
// Models List // Models List
mdlselector = new ModelsPageBody(window, {MDLS_X, MDLS_Y, MDLS_W, MDLS_H}); mdlselector = new ModelsPageBody(window, {MDLS_X, MDLS_Y, MDLS_W, MDLS_H});
mdlselector->setCloseHandler([=]() { onCancel(); });
mdlselector->setLblRefreshFunc([=]() { labelRefreshRequest(); }); mdlselector->setLblRefreshFunc([=]() { labelRefreshRequest(); });
auto mdl_obj = mdlselector->getLvObj(); auto mdl_obj = mdlselector->getLvObj();
lv_obj_set_style_max_width(mdl_obj, MDLS_W, LV_PART_MAIN); lv_obj_set_style_max_width(mdl_obj, MDLS_W, LV_PART_MAIN);
@@ -711,6 +710,8 @@ void ModelLabelsWindow::buildBody(Window *window)
if (mdlselector->getSortOrder() == NO_SORT) if (mdlselector->getSortOrder() == NO_SORT)
mdlselector->setSortOrder(NAME_ASC); mdlselector->setSortOrder(NAME_ASC);
closeMessage.subscribe(Messaging::ON_CLOSE, [=](uint32_t) { onCancel(); });
// Labels // Labels
lblselector = lblselector =
new ListBox(window, rect_t{LABELS_X, LABELS_Y, LABELS_WIDTH, LABELS_HEIGHT}, getLabels()); new ListBox(window, rect_t{LABELS_X, LABELS_Y, LABELS_WIDTH, LABELS_HEIGHT}, getLabels());
@@ -55,6 +55,7 @@ class ModelLabelsWindow : public Page
ModelsPageBody *mdlselector; ModelsPageBody *mdlselector;
ModelLayoutButton *mdlLayout; ModelLayoutButton *mdlLayout;
std::string currentLabel; std::string currentLabel;
Messaging closeMessage;
LabelsVector getLabels() LabelsVector getLabels()
{ {
@@ -784,7 +784,7 @@ void ModelTelemetryPage::editSensor(uint8_t index)
{ {
lastKnownIndex = -1; lastKnownIndex = -1;
Window* editWindow = new SensorEditWindow(index); Window* editWindow = new SensorEditWindow(index);
editWindow->setCloseHandler([=]() { buildSensorList(index); }); editWindow->onClosing([=]() { buildSensorList(index); });
} }
void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex) void ModelTelemetryPage::buildSensorList(int8_t focusSensorIndex)
@@ -128,7 +128,7 @@ class SelectTemplate : public TemplatePage
auto tb = new TextButton( auto tb = new TextButton(
listWindow, rect_t{0, 0, lv_pct(100), EdgeTxStyles::STD_FONT_HEIGHT * 2}, name, listWindow, rect_t{0, 0, lv_pct(100), EdgeTxStyles::STD_FONT_HEIGHT * 2}, name,
[=]() -> uint8_t { [=]() -> uint8_t {
deleteLater(); closeWindow();
templateFolderPage->doUpdate(folder, name); templateFolderPage->doUpdate(folder, name);
return 0; return 0;
}); });
@@ -55,7 +55,7 @@ class SelectTemplateFolder : public TemplatePage
SelectTemplateFolder(std::function<void(std::string, std::string)> update); SelectTemplateFolder(std::function<void(std::string, std::string)> update);
void doUpdate(std::string folder, std::string name) { void doUpdate(std::string folder, std::string name) {
deleteLater(); closeWindow();
if (update) if (update)
update(folder, name); update(folder, name);
} }
@@ -580,5 +580,5 @@ void ModelUSBJoystickPage::editChannel(uint8_t channel,
USBChannelLineButton* btn) USBChannelLineButton* btn)
{ {
auto chedit = new USBChannelEditWindow(channel); auto chedit = new USBChannelEditWindow(channel);
chedit->setCloseHandler([=]() { this->update(); btn->refresh(); }); chedit->onClosing([=]() { this->update(); btn->refresh(); });
} }
@@ -768,7 +768,7 @@ void FunctionsPage::editSpecialFunction(Window *window, uint8_t index,
FunctionLineButton *button) FunctionLineButton *button)
{ {
auto edit = editPage(index); auto edit = editPage(index);
edit->setCloseHandler([=]() { edit->onClosing([=]() {
CustomFunctionData *cfn = customFunctionData(index); CustomFunctionData *cfn = customFunctionData(index);
if (cfn->swtch != 0) { if (cfn->swtch != 0) {
focusIndex = index; focusIndex = index;
@@ -125,7 +125,7 @@ void BluetoothTrainerWindow::refresh()
} else if (bluetooth.state == BLUETOOTH_STATE_DISCOVER_START) { } else if (bluetooth.state == BLUETOOTH_STATE_DISCOVER_START) {
if(reusableBuffer.moduleSetup.bt.devicesCount && !menuopened) { // On first item found, open menu if(reusableBuffer.moduleSetup.bt.devicesCount && !menuopened) { // On first item found, open menu
auto btdm = new BTDiscoverMenu(); auto btdm = new BTDiscoverMenu();
btdm->setCloseHandler([=]() { btdm->onClosing([=]() {
menuopened = false; menuopened = false;
if(bluetooth.state != BLUETOOTH_STATE_BIND_REQUESTED) if(bluetooth.state != BLUETOOTH_STATE_BIND_REQUESTED)
bluetooth.state = BLUETOOTH_STATE_IDLE; bluetooth.state = BLUETOOTH_STATE_IDLE;
@@ -55,7 +55,7 @@ class BindWaitDialog : public BaseDialog
{ {
new StaticText(form, rect_t{}, STR_WAITING_FOR_RX); new StaticText(form, rect_t{}, STR_WAITING_FOR_RX);
setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; }); onClosing([=]() { if (resetOnClose) moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; });
} }
void checkEvents() override void checkEvents() override
@@ -66,7 +66,7 @@ class BindWaitDialog : public BaseDialog
// returned to normal after bind // returned to normal after bind
if (bindInfo.step > BIND_INIT) { if (bindInfo.step > BIND_INIT) {
removePXX2ReceiverIfEmpty(moduleIdx, receiverIdx); removePXX2ReceiverIfEmpty(moduleIdx, receiverIdx);
deleteLater(); closeWindow();
if (bindInfo.step == BIND_OK) { if (bindInfo.step == BIND_OK) {
POPUP_INFORMATION(STR_REG_OK); POPUP_INFORMATION(STR_REG_OK);
setPXX2ReceiverUsed(moduleIdx, receiverIdx); setPXX2ReceiverUsed(moduleIdx, receiverIdx);
@@ -103,8 +103,8 @@ class BindWaitDialog : public BaseDialog
if (bindInfo.step == BIND_INIT && bindInfo.candidateReceiversCount > 0) { if (bindInfo.step == BIND_INIT && bindInfo.candidateReceiversCount > 0) {
// prevent module mode being reset to NORMAL before exiting // prevent module mode being reset to NORMAL before exiting
setCloseHandler(nullptr); resetOnClose = false;
deleteLater(); closeWindow();
// ... and create RX choice dialog // ... and create RX choice dialog
new BindRxChoiceMenu(moduleIdx, receiverIdx); new BindRxChoiceMenu(moduleIdx, receiverIdx);
@@ -117,6 +117,7 @@ class BindWaitDialog : public BaseDialog
protected: protected:
uint8_t moduleIdx; uint8_t moduleIdx;
uint8_t receiverIdx; uint8_t receiverIdx;
bool resetOnClose = true;
}; };
class RxOptions : public BaseDialog class RxOptions : public BaseDialog
@@ -284,7 +285,7 @@ uint8_t ReceiverButton::pressBind()
}); });
return 0; return 0;
}); });
menu->setCloseHandler( menu->onClosing(
[=]() { removePXX2ReceiverIfEmpty(moduleIdx, receiverIdx); }); [=]() { removePXX2ReceiverIfEmpty(moduleIdx, receiverIdx); });
} }
return 0; return 0;
@@ -375,7 +376,7 @@ RegisterDialog::RegisterDialog(uint8_t moduleIdx) :
box->padAll(PAD_MEDIUM); box->padAll(PAD_MEDIUM);
new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t { new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t {
this->deleteLater(); this->closeWindow();
return 0; return 0;
}); });
@@ -385,7 +386,7 @@ RegisterDialog::RegisterDialog(uint8_t moduleIdx) :
}); });
btn_ok->hide(); btn_ok->hide();
setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; }); onClosing([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; });
} }
void RegisterDialog::start() void RegisterDialog::start()
@@ -419,7 +420,7 @@ void RegisterDialog::checkEvents()
// status->hide(); // status->hide();
rx_name->update(); rx_name->update();
} else if (modSetup.registerStep == REGISTER_OK) { } else if (modSetup.registerStep == REGISTER_OK) {
deleteLater(); closeWindow();
POPUP_INFORMATION(STR_REG_OK); POPUP_INFORMATION(STR_REG_OK);
// pop-up call garbage collector, // pop-up call garbage collector,
// so that the dialog is alread destroyed // so that the dialog is alread destroyed
@@ -442,7 +443,7 @@ ModuleOptions::ModuleOptions(uint8_t moduleIdx) :
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
state = MO_ReadModuleSettings; state = MO_ReadModuleSettings;
#endif #endif
setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; }); onClosing([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; });
} }
void ModuleOptions::checkEvents() void ModuleOptions::checkEvents()
@@ -481,12 +482,12 @@ void ModuleOptions::checkEvents()
case MO_WritingSettings: case MO_WritingSettings:
#if defined(SIMU) #if defined(SIMU)
statusText.clear(); statusText.clear();
deleteLater(); closeWindow();
#else #else
if (moduleState[moduleIdx].mode == MODULE_MODE_NORMAL && if (moduleState[moduleIdx].mode == MODULE_MODE_NORMAL &&
hwSettings.moduleSettings.state == PXX2_SETTINGS_OK) { hwSettings.moduleSettings.state == PXX2_SETTINGS_OK) {
statusText.clear(); statusText.clear();
deleteLater(); closeWindow();
} }
#endif #endif
break; break;
@@ -605,7 +606,7 @@ void ModuleOptions::update()
box->padAll(PAD_MEDIUM); box->padAll(PAD_MEDIUM);
new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t { new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t {
this->deleteLater(); this->closeWindow();
return 0; return 0;
}); });
@@ -645,7 +646,7 @@ RxOptions::RxOptions(uint8_t moduleIdx, uint8_t rxIdx) :
hwSettings.receiverSettings.outputsMapping[i] = i; hwSettings.receiverSettings.outputsMapping[i] = i;
} }
#endif #endif
setCloseHandler([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; }); onClosing([=]() { moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; });
} }
void RxOptions::checkEvents() void RxOptions::checkEvents()
@@ -705,12 +706,12 @@ void RxOptions::checkEvents()
case RO_WritingSettings: case RO_WritingSettings:
#if defined(SIMU) #if defined(SIMU)
statusText.clear(); statusText.clear();
deleteLater(); closeWindow();
#else #else
if (moduleState[moduleIdx].mode == MODULE_MODE_NORMAL && if (moduleState[moduleIdx].mode == MODULE_MODE_NORMAL &&
hwSettings.receiverSettings.state == PXX2_SETTINGS_OK) { hwSettings.receiverSettings.state == PXX2_SETTINGS_OK) {
statusText.clear(); statusText.clear();
deleteLater(); closeWindow();
} }
#endif #endif
break; break;
@@ -961,7 +962,7 @@ void RxOptions::update()
box->padAll(PAD_MEDIUM); box->padAll(PAD_MEDIUM);
new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t { new TextButton(box, rect_t{}, STR_CANCEL, [=]() -> int8_t {
this->deleteLater(); this->closeWindow();
return 0; return 0;
}); });
@@ -534,7 +534,7 @@ class ModuleWindow : public Window
getRxStatLabels()->label, 50, getRxStatLabels()->label, 50,
COLOR_THEME_SECONDARY1_INDEX, CENTERED | FONT(XL)); COLOR_THEME_SECONDARY1_INDEX, CENTERED | FONT(XL));
rssiDialog->setCloseHandler([this, closeHandler]() { rssiDialog->onClosing([this, closeHandler]() {
rangeButton->check(false); rangeButton->check(false);
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
if (closeHandler) closeHandler(); if (closeHandler) closeHandler();
@@ -719,7 +719,7 @@ class ModuleSubTypeChoice : public Choice
auto menu = new Menu(); auto menu = new Menu();
if (menuTitle) menu->setTitle(menuTitle); if (menuTitle) menu->setTitle(menuTitle);
menu->setCloseHandler([=]() { setEditMode(false); }); menu->onClosing([=]() { setEditMode(false); });
setEditMode(true); setEditMode(true);
+1 -1
View File
@@ -126,7 +126,7 @@ HWPots::HWPots(Window* parent) :
potsChanged = false; potsChanged = false;
setCloseHandler([=]() { onClosing([=]() {
if (potsChanged) if (potsChanged)
LayoutFactory::loadCustomScreens(); LayoutFactory::loadCustomScreens();
}); });
@@ -236,7 +236,7 @@ void RadioCalibrationPage::nextStep()
menuCalibrationState++; menuCalibrationState++;
if (menuCalibrationState == CALIB_FINISHED) if (menuCalibrationState == CALIB_FINISHED)
deleteLater(); closeWindow();
if (menuCalibrationState == CALIB_STORE) if (menuCalibrationState == CALIB_STORE)
adcCalibStore(); adcCalibStore();
@@ -240,6 +240,13 @@ class AnaCalibratedViewWindow : public AnaViewWindow
#endif // defined(HARDWARE_TOUCH) #endif // defined(HARDWARE_TOUCH)
setHeight(parent->height()); setHeight(parent->height());
#if defined(HARDWARE_TOUCH)
onClosing([=]() {
lv_obj_del(touchLines[0]);
lv_obj_del(touchLines[1]);
});
#endif
} }
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
@@ -263,26 +270,16 @@ class AnaCalibratedViewWindow : public AnaViewWindow
lv_obj_add_flag(touchLines[1], LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(touchLines[1], LV_OBJ_FLAG_HIDDEN);
} }
} }
void deleteLater() override
{
if (!deleted()) {
// Attached to parent->parent window
lv_obj_del(touchLines[0]);
lv_obj_del(touchLines[1]);
AnaViewWindow::deleteLater();
}
}
#endif #endif
static LAYOUT_SIZE(TSI2CEventsCol, 5, 0) static LAYOUT_SIZE(TSI2CEventsCol, 5, 0)
protected: protected:
int16_t column3(int i) override { return anaIn(i); }
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
lv_point_t touchPts[4]; lv_point_t touchPts[4];
lv_obj_t* touchLines[2]; lv_obj_t* touchLines[2];
#endif #endif
int16_t column3(int i) override { return anaIn(i); }
}; };
class AnaFilteredDevViewWindow : public AnaViewWindow class AnaFilteredDevViewWindow : public AnaViewWindow
@@ -169,7 +169,7 @@ void RadioGhostModuleConfig::onLongPressRTN()
reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_CLOSE; reusableBuffer.ghostMenu.menuAction = GHST_MENU_CTRL_CLOSE;
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL; moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
sleep_ms(10); sleep_ms(10);
deleteLater(); closeWindow();
#if defined(TRIMS_EMULATE_BUTTONS) #if defined(TRIMS_EMULATE_BUTTONS)
setHatsAsKeys(false); // switch trims back to normal setHatsAsKeys(false); // switch trims back to normal
#endif #endif
@@ -187,7 +187,7 @@ void RadioGhostModuleConfig::checkEvents()
moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL; moduleState[EXTERNAL_MODULE].counter = GHST_MENU_CONTROL;
} else if (reusableBuffer.ghostMenu.menuStatus == GHST_MENU_STATUS_CLOSING) { } else if (reusableBuffer.ghostMenu.menuStatus == GHST_MENU_STATUS_CLOSING) {
sleep_ms(10); sleep_ms(10);
deleteLater(); closeWindow();
#if defined(TRIMS_EMULATE_BUTTONS) #if defined(TRIMS_EMULATE_BUTTONS)
setHatsAsKeys(false); // switch trims back to normal setHatsAsKeys(false); // switch trims back to normal
#endif #endif
@@ -393,17 +393,12 @@ RadioMicRecorder::RadioMicRecorder() :
buildHeader(header); buildHeader(header);
buildBody(body); buildBody(body);
enterIdle(); enterIdle();
}
void RadioMicRecorder::deleteLater() onClosing([=]() {
{
if (!deleted()) {
if (recorder.isRecording()) recorder.stop(); if (recorder.isRecording()) recorder.stop();
if (isPlayingTake()) audioQueue.stopAll(); if (isPlayingTake()) audioQueue.stopAll();
pdmStop(); pdmStop();
});
Page::deleteLater();
}
} }
void RadioMicRecorder::buildHeader(Window* window) void RadioMicRecorder::buildHeader(Window* window)
@@ -75,7 +75,6 @@ class RadioMicRecorder : public Page
void buildHeader(Window* window); void buildHeader(Window* window);
void buildBody(Window* window); void buildBody(Window* window);
void checkEvents() override; void checkEvents() override;
void deleteLater() override;
void onActionPressed(); void onActionPressed();
void onPlayPressed(); void onPlayPressed();
@@ -69,7 +69,7 @@ class FlashDialog: public FullScreenDialog
progress->setValue(total > 0 ? count * 100 / total : 0); progress->setValue(total > 0 ? count * 100 / total : 0);
lv_refr_now(nullptr); lv_refr_now(nullptr);
}); });
deleteLater(); closeWindow();
} }
protected: protected:
@@ -104,7 +104,7 @@ class FrskyOtaFlashDialog : public BaseDialog
reusableBuffer.sdManager.otaUpdateInformation.module = module; reusableBuffer.sdManager.otaUpdateInformation.module = module;
moduleState[reusableBuffer.sdManager.otaUpdateInformation.module].startBind(&reusableBuffer.sdManager.otaUpdateInformation, onUpdateStateChangedCallbackFor(this)); moduleState[reusableBuffer.sdManager.otaUpdateInformation.module].startBind(&reusableBuffer.sdManager.otaUpdateInformation, onUpdateStateChangedCallbackFor(this));
setCloseHandler([=]() { moduleState[reusableBuffer.sdManager.otaUpdateInformation.module].mode = MODULE_MODE_NORMAL; }); onClosing([=]() { moduleState[reusableBuffer.sdManager.otaUpdateInformation.module].mode = MODULE_MODE_NORMAL; });
} }
void onUpdateConfirmation() void onUpdateConfirmation()
@@ -113,7 +113,7 @@ class FrskyOtaFlashDialog : public BaseDialog
Pxx2OtaUpdate otaUpdate(reusableBuffer.sdManager.otaUpdateInformation.module, destination->candidateReceiversNames[destination->selectedReceiverIndex]); Pxx2OtaUpdate otaUpdate(reusableBuffer.sdManager.otaUpdateInformation.module, destination->candidateReceiversNames[destination->selectedReceiverIndex]);
auto dialog = new FlashDialog<Pxx2OtaUpdate>(otaUpdate); auto dialog = new FlashDialog<Pxx2OtaUpdate>(otaUpdate);
dialog->flash(destination->filename); dialog->flash(destination->filename);
deleteLater(); closeWindow();
} }
void onUpdateStateChanged() void onUpdateStateChanged()
@@ -136,9 +136,9 @@ class FrskyOtaFlashDialog : public BaseDialog
updateConfirmDialog = new ConfirmDialog(getPXX2ReceiverName(modelId), updateConfirmDialog = new ConfirmDialog(getPXX2ReceiverName(modelId),
std::string(reusableBuffer.sdManager.otaReceiverVersion).c_str(), std::string(reusableBuffer.sdManager.otaReceiverVersion).c_str(),
[=]() { onUpdateConfirmation(); }, [=]() { onUpdateConfirmation(); },
[=]() { deleteLater(); }); [=]() { closeWindow(); });
} else { } else {
deleteLater(); closeWindow();
POPUP_WARNING(STR_OTA_UPDATE_ERROR, STR_UNSUPPORTED_RX); POPUP_WARNING(STR_OTA_UPDATE_ERROR, STR_UNSUPPORTED_RX);
} }
} }
@@ -156,8 +156,8 @@ class FrskyOtaFlashDialog : public BaseDialog
rxChoiceMenu->setCancelHandler([=]() { rxChoiceMenu->setCancelHandler([=]() {
// Seems menu didn't delete itself before call cancelHandler(). // Seems menu didn't delete itself before call cancelHandler().
// Delete the menu explicity to ensure menu is deleted before dialog. // Delete the menu explicity to ensure menu is deleted before dialog.
rxChoiceMenu->deleteLater(); rxChoiceMenu->closeWindow();
deleteLater(); closeWindow();
}); });
} else { } else {
rxChoiceMenu->removeLines(); rxChoiceMenu->removeLines();
@@ -323,7 +323,7 @@ class SpectrumWindow : public Window
RadioSpectrumAnalyser::RadioSpectrumAnalyser(uint8_t moduleIdx) : RadioSpectrumAnalyser::RadioSpectrumAnalyser(uint8_t moduleIdx) :
Page(ICON_RADIO_TOOLS, PAD_ZERO), moduleIdx(moduleIdx) Page(ICON_RADIO_TOOLS, PAD_ZERO), moduleIdx(moduleIdx)
{ {
setCloseHandler([=]() { stop(); }); onClosing([=]() { stop(); });
init(); init();
buildHeader(header); buildHeader(header);
buildBody(body); buildBody(body);
+9 -11
View File
@@ -148,7 +148,7 @@ class ThemeDetailsDialog : public BaseDialog
auto button = auto button =
new TextButton(line, rect_t{0, 0, lv_pct(30), 0}, STR_CANCEL, [=]() { new TextButton(line, rect_t{0, 0, lv_pct(30), 0}, STR_CANCEL, [=]() {
deleteLater(); closeWindow();
return 0; return 0;
}); });
lv_obj_set_grid_cell(button->getLvObj(), LV_GRID_ALIGN_CENTER, 0, 1, lv_obj_set_grid_cell(button->getLvObj(), LV_GRID_ALIGN_CENTER, 0, 1,
@@ -163,7 +163,7 @@ class ThemeDetailsDialog : public BaseDialog
if (!saveHandler(this->theme)) if (!saveHandler(this->theme))
return 0; return 0;
} }
deleteLater(); closeWindow();
return 0; return 0;
}); });
lv_obj_set_grid_cell(button->getLvObj(), LV_GRID_ALIGN_CENTER, 1, 1, lv_obj_set_grid_cell(button->getLvObj(), LV_GRID_ALIGN_CENTER, 1, 1,
@@ -190,6 +190,10 @@ class ColorEditPage : public Page
{ {
buildHead(header); buildHead(header);
buildBody(body); buildBody(body);
onClosing([=]() {
if (_updateHandler != nullptr) _updateHandler();
});
} }
void setActiveColorBar(int activeTab) void setActiveColorBar(int activeTab)
@@ -221,12 +225,6 @@ class ColorEditPage : public Page
ColorSwatch *_colorSquare = nullptr; ColorSwatch *_colorSquare = nullptr;
StaticText *_hexBox = nullptr; StaticText *_hexBox = nullptr;
void deleteLater() override
{
if (_updateHandler != nullptr) _updateHandler();
Page::deleteLater();
}
void setHexStr(uint32_t rgb) void setHexStr(uint32_t rgb)
{ {
if (_hexBox) { if (_hexBox) {
@@ -347,11 +345,11 @@ class ThemeEditPage : public Page
if (saveHandler != nullptr) { if (saveHandler != nullptr) {
saveHandler(_theme); saveHandler(_theme);
} }
deleteLater(); closeWindow();
}, },
[=]() { deleteLater(); }); [=]() { closeWindow(); });
} else { } else {
deleteLater(); closeWindow();
} }
} }
@@ -154,6 +154,12 @@ PageGroupHeaderBase::PageGroupHeaderBase(Window* parent, coord_t height, EdgeTxI
selectedIcon = new SelectedTabIcon(carousel); selectedIcon = new SelectedTabIcon(carousel);
#endif #endif
onClosing([=]() {
for (uint8_t i = 0; i < pages.size(); i += 1)
delete pages[i];
pages.clear();
});
} }
#if VERSION_MAJOR == 2 #if VERSION_MAJOR == 2
@@ -233,17 +239,6 @@ bool PageGroupHeaderBase::hasSubMenu(QMPage qmPage)
return false; return false;
} }
void PageGroupHeaderBase::deleteLater()
{
if (deleted()) return;
for (uint8_t i = 0; i < pages.size(); i += 1)
delete pages[i];
pages.clear();
Window::deleteLater();
}
#if VERSION_MAJOR == 2 #if VERSION_MAJOR == 2
void PageGroupHeaderBase::checkEvents() void PageGroupHeaderBase::checkEvents()
{ {
@@ -323,9 +318,7 @@ void PageGroupBase::onClicked() { Keyboard::hide(false); }
void PageGroupBase::onCancel() void PageGroupBase::onCancel()
{ {
if (!_deleted) { closeWindow();
deleteLater();
}
} }
uint8_t PageGroupBase::tabCount() const uint8_t PageGroupBase::tabCount() const
@@ -349,7 +342,7 @@ void PageGroupBase::setCurrentTab(unsigned index)
PageGroupItem* tab = header->pageTab(index); PageGroupItem* tab = header->pageTab(index);
if (tab != currentTab && !deleted()) { if (tab != currentTab) {
header->setTitle(tab->getTitle().c_str()); header->setTitle(tab->getTitle().c_str());
#if VERSION_MAJOR > 2 #if VERSION_MAJOR > 2
header->setIcon(tab->getIcon()); header->setIcon(tab->getIcon());
@@ -453,7 +446,7 @@ PageGroup::PageGroup(EdgeTxIcon icon, const char* title, const PageDef* pages) :
#endif #endif
#endif #endif
setCloseHandler([]{ onClosing([=]{
storageCheck(true); storageCheck(true);
ViewMain::instance()->updateTopbarVisibility(); ViewMain::instance()->updateTopbarVisibility();
}); });
@@ -122,8 +122,6 @@ class PageGroupHeaderBase : public Window
bool isCurrent(uint8_t idx) const { return currentIndex == idx; } bool isCurrent(uint8_t idx) const { return currentIndex == idx; }
uint8_t tabCount() const { return pages.size(); } uint8_t tabCount() const { return pages.size(); }
void deleteLater() override;
#if VERSION_MAJOR == 2 #if VERSION_MAJOR == 2
static LAYOUT_VAL_SCALED(ICON_EXTRA_H, 10) static LAYOUT_VAL_SCALED(ICON_EXTRA_H, 10)
static LAYOUT_VAL_SCALED(MENU_HEADER_BUTTON_WIDTH, 33) static LAYOUT_VAL_SCALED(MENU_HEADER_BUTTON_WIDTH, 33)
@@ -66,5 +66,5 @@ void QMPageChoice::openMenu()
// fillMenu(menu); - called by MenuToolbar // fillMenu(menu); - called by MenuToolbar
menu->setCloseHandler([=]() { setEditMode(false); }); menu->onClosing([=]() { setEditMode(false); });
} }
@@ -211,7 +211,7 @@ class QuickSubMenu
void clearSubMenu() void clearSubMenu()
{ {
if (subMenu) { if (subMenu) {
subMenu->deleteLater(); subMenu->closeWindow();
subMenu = nullptr; subMenu = nullptr;
} }
} }
@@ -249,7 +249,7 @@ void QuickMenu::openQuickMenu()
void QuickMenu::shutdownQuickMenu() void QuickMenu::shutdownQuickMenu()
{ {
if (instance) instance->deleteLater(); if (instance) instance->closeWindow();
} }
QuickMenu::QuickMenu() : QuickMenu::QuickMenu() :
@@ -298,14 +298,10 @@ QuickMenu::QuickMenu() :
#endif #endif
} }
} }
}
void QuickMenu::deleteLater() onClosing([=] () {
{
if (!_deleted) {
instance = nullptr; instance = nullptr;
NavWindow::deleteLater(); });
}
} }
void QuickMenu::openQM(PageGroupBase* newPageGroup, QMPage newCurPage) void QuickMenu::openQM(PageGroupBase* newPageGroup, QMPage newCurPage)
@@ -163,8 +163,6 @@ class QuickMenu : public NavWindow
void focusMainMenu(); void focusMainMenu();
void deleteLater() override;
static void selected(); static void selected();
static void topMenuAction(int n); static void topMenuAction(int n);
@@ -144,6 +144,10 @@ QuickMenuGroup::QuickMenuGroup(Window* parent) :
{ {
padAll(PAD_OUTLINE); padAll(PAD_OUTLINE);
group = lv_group_create(); group = lv_group_create();
onClosing([=]() {
if (group) lv_group_del(group);
});
} }
ButtonBase* QuickMenuGroup::addButton(EdgeTxIcon icon, const char* title, ButtonBase* QuickMenuGroup::addButton(EdgeTxIcon icon, const char* title,
@@ -179,14 +183,6 @@ void QuickMenuGroup::setGroup()
} }
} }
void QuickMenuGroup::deleteLater()
{
if (_deleted) return;
if (group) lv_group_del(group);
Window::deleteLater();
}
void QuickMenuGroup::setFocus() void QuickMenuGroup::setFocus()
{ {
if (!curBtn && btns.size() > 0) if (!curBtn && btns.size() > 0)
@@ -55,8 +55,6 @@ class QuickMenuGroup : public Window
void prevEntry(); void prevEntry();
ButtonBase* getFocusedButton(); ButtonBase* getFocusedButton();
void deleteLater() override;
static LAYOUT_VAL_SCALED(QM_ICON_SIZE, 30) static LAYOUT_VAL_SCALED(QM_ICON_SIZE, 30)
static LAYOUT_ORIENTATION(QM_ICON_PAD, PAD_MEDIUM, PAD_SMALL) static LAYOUT_ORIENTATION(QM_ICON_PAD, PAD_MEDIUM, PAD_SMALL)
+28 -33
View File
@@ -175,6 +175,31 @@ StandaloneLuaWindow::StandaloneLuaWindow(bool useLvgl, int initFn, int runFn) :
#if defined(USE_HATS_AS_KEYS) #if defined(USE_HATS_AS_KEYS)
setTransposeHatsForLUA(true); setTransposeHatsForLUA(true);
#endif #endif
onClosing([=]() {
luaL_unref(lsStandalone, LUA_REGISTRYINDEX, initFunction);
luaL_unref(lsStandalone, LUA_REGISTRYINDEX, runFunction);
luaLcdBuffer = nullptr;
luaClose(&lsStandalone);
if (lcdBuffer) delete lcdBuffer;
lcdBuffer = nullptr;
luaScriptManager = nullptr;
_instance = nullptr;
#if defined(USE_HATS_AS_KEYS)
setTransposeHatsForLUA(false);
#endif
luaState = prevLuaState;
luaEmptyEventBuffer();
MainWindow::instance()->enableWidgetRefresh(true);
});
} }
void StandaloneLuaWindow::setup(bool useLvgl, int initFn, int runFn) void StandaloneLuaWindow::setup(bool useLvgl, int initFn, int runFn)
@@ -188,36 +213,6 @@ StandaloneLuaWindow* StandaloneLuaWindow::instance()
return _instance; return _instance;
} }
void StandaloneLuaWindow::deleteLater()
{
if (_deleted) return;
luaL_unref(lsStandalone, LUA_REGISTRYINDEX, initFunction);
luaL_unref(lsStandalone, LUA_REGISTRYINDEX, runFunction);
luaLcdBuffer = nullptr;
luaClose(&lsStandalone);
if (lcdBuffer) delete lcdBuffer;
lcdBuffer = nullptr;
luaScriptManager = nullptr;
_instance = nullptr;
#if defined(USE_HATS_AS_KEYS)
setTransposeHatsForLUA(false);
#endif
luaState = prevLuaState;
luaEmptyEventBuffer();
MainWindow::instance()->enableWidgetRefresh(true);
Window::deleteLater();
}
void StandaloneLuaWindow::checkEvents() void StandaloneLuaWindow::checkEvents()
{ {
Window::checkEvents(); Window::checkEvents();
@@ -241,7 +236,7 @@ void StandaloneLuaWindow::checkEvents()
luaNextEvent(&evt); luaNextEvent(&evt);
if (evt.event == EVT_KEY_LONG(KEY_EXIT)) { if (evt.event == EVT_KEY_LONG(KEY_EXIT)) {
killEvents(evt.event); killEvents(evt.event);
deleteLater(); closeWindow();
} else { } else {
if (runFunction != LUA_REFNIL) { if (runFunction != LUA_REFNIL) {
lua_rawgeti(lsStandalone, LUA_REGISTRYINDEX, runFunction); lua_rawgeti(lsStandalone, LUA_REGISTRYINDEX, runFunction);
@@ -263,7 +258,7 @@ void StandaloneLuaWindow::checkEvents()
int scriptResult = lua_tointeger(lsStandalone, -1); int scriptResult = lua_tointeger(lsStandalone, -1);
lua_pop(lsStandalone, 1); /* pop returned value */ lua_pop(lsStandalone, 1); /* pop returned value */
if (scriptResult != 0) { if (scriptResult != 0) {
deleteLater(); closeWindow();
} else { } else {
if (useLvglLayout() && !hasError) { if (useLvglLayout() && !hasError) {
PROTECT_LUA() { PROTECT_LUA() {
@@ -284,7 +279,7 @@ void StandaloneLuaWindow::checkEvents()
nextScript[FF_MAX_LFN] = '\0'; nextScript[FF_MAX_LFN] = '\0';
_instance = nullptr; _instance = nullptr;
lua_settop(lsStandalone, 0); lua_settop(lsStandalone, 0);
deleteLater(); closeWindow();
luaExecStandalone(nextScript); luaExecStandalone(nextScript);
} }
} }
-2
View File
@@ -39,8 +39,6 @@ public:
static StandaloneLuaWindow* instance(); static StandaloneLuaWindow* instance();
static void setup(bool useLvgl, int initFn, int runFn); static void setup(bool useLvgl, int initFn, int runFn);
void deleteLater() override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "StandaloneLuaWindow"; } std::string getName() const override { return "StandaloneLuaWindow"; }
#endif #endif
+2 -2
View File
@@ -98,7 +98,7 @@ void startSplash()
void cancelSplash() void cancelSplash()
{ {
if (splashScreen) { if (splashScreen) {
splashScreen->deleteLater(); splashScreen->closeWindow();
splashScreen = nullptr; splashScreen = nullptr;
splashStartTime = 0; splashStartTime = 0;
} }
@@ -172,7 +172,7 @@ void drawSleepBitmap()
void cancelShutdownAnimation() void cancelShutdownAnimation()
{ {
if (shutdownWindow) { if (shutdownWindow) {
shutdownWindow->deleteLater(); shutdownWindow->closeWindow();
shutdownWindow = nullptr; shutdownWindow = nullptr;
for (int i = 0; i < 4; i += 1) shutdownAnim[i] = nullptr; for (int i = 0; i < 4; i += 1) shutdownAnim[i] = nullptr;
} }
+2 -2
View File
@@ -82,7 +82,7 @@ class GaugeWidget : public Widget
void update() override void update() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
@@ -107,7 +107,7 @@ class GaugeWidget : public Widget
void foreground() override void foreground() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
auto newValue = getGuageValue(); auto newValue = getGuageValue();
if (lastValue != newValue) { if (lastValue != newValue) {
+2 -2
View File
@@ -55,7 +55,7 @@ class ModelBitmapWidget : public Widget
void foreground() override void foreground() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
if (getHash() != deps_hash) { if (getHash() != deps_hash) {
update(); update();
@@ -68,7 +68,7 @@ class ModelBitmapWidget : public Widget
void update() override void update() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
+1 -1
View File
@@ -95,7 +95,7 @@ class ChannelValue : public Window
void refresh() void refresh()
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
int16_t value = channelOutputs[channel]; int16_t value = channelOutputs[channel];
@@ -104,7 +104,7 @@ class RadioInfoWidget : public Widget
void update() override void update() override
{ {
if (_deleted) return; if (deleted()) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
@@ -116,7 +116,7 @@ class RadioInfoWidget : public Widget
void foreground() override void foreground() override
{ {
if (_deleted) return; if (deleted()) return;
usbIcon->show(usbPlugged()); usbIcon->show(usbPlugged());
if (getSelectedUsbMode() == USB_UNSELECTED_MODE) if (getSelectedUsbMode() == USB_UNSELECTED_MODE)
@@ -246,14 +246,14 @@ class DateTimeWidget : public Widget
void foreground() override void foreground() override
{ {
if (_deleted) return; if (deleted()) return;
Widget::checkEvents(); Widget::checkEvents();
} }
void update() override void update() override
{ {
if (_deleted) return; if (deleted()) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
@@ -302,7 +302,7 @@ class InternalGPSWidget : public Widget
void foreground() override void foreground() override
{ {
if (_deleted) return; if (deleted()) return;
bool hasGPS = serialGetModePort(UART_MODE_GPS) >= 0; bool hasGPS = serialGetModePort(UART_MODE_GPS) >= 0;
+1 -1
View File
@@ -60,7 +60,7 @@ class TextWidget : public Widget
void update() override void update() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
+2 -2
View File
@@ -107,7 +107,7 @@ class TimerWidget : public Widget
void foreground() override void foreground() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
@@ -236,7 +236,7 @@ class TimerWidget : public Widget
void update() override void update() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
+2 -2
View File
@@ -78,7 +78,7 @@ class ValueWidget : public Widget
void foreground() override void foreground() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
bool changed = false; bool changed = false;
@@ -187,7 +187,7 @@ class ValueWidget : public Widget
void update() override void update() override
{ {
if (!loaded || _deleted) return; if (!loaded || deleted()) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
+5 -6
View File
@@ -263,13 +263,12 @@ LuaWidget::LuaWidget(const WidgetFactory* factory, Window* parent,
lv_obj_add_event_cb(lvobj, LuaWidget::redraw_cb, LV_EVENT_DRAW_MAIN, lv_obj_add_event_cb(lvobj, LuaWidget::redraw_cb, LV_EVENT_DRAW_MAIN,
nullptr); nullptr);
} }
}
LuaWidget::~LuaWidget() onClosing([=]() {
{ luaL_unref(lsWidgets, LUA_REGISTRYINDEX, zoneRectDataRef);
luaL_unref(lsWidgets, LUA_REGISTRYINDEX, zoneRectDataRef); if (errorMessage)
if (errorMessage) free(errorMessage);
free(errorMessage); });
} }
void LuaWidget::onClicked() void LuaWidget::onClicked()
-1
View File
@@ -108,7 +108,6 @@ class LuaWidget : public Widget, public LuaScriptManager
LuaWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect, LuaWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
int screenNum, int zoneNum, int zoneRectDataRef, int screenNum, int zoneNum, int zoneRectDataRef,
int optionsDataRef, int createFunctionRef, const std::string& path); int optionsDataRef, int createFunctionRef, const std::string& path);
~LuaWidget() override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "LuaWidget"; } std::string getName() const override { return "LuaWidget"; }

Some files were not shown because too many files have changed in this diff Show More