fix some lvgl lifetime management issues
This commit is contained in:
committed by
Raphael Coeffic
parent
ee1cfdf987
commit
af575f20f1
@@ -76,6 +76,8 @@ void Button::checkEvents()
|
||||
checkHandler();
|
||||
}
|
||||
|
||||
lv_style_t style_btn;
|
||||
|
||||
|
||||
LvglWidgetFactory textButtonFactory = LvglWidgetFactory(
|
||||
[](lv_obj_t *parent) {
|
||||
|
||||
-1
@@ -124,7 +124,6 @@ class TextButton: public Button
|
||||
|
||||
protected:
|
||||
lv_obj_t * label = nullptr;
|
||||
lv_style_t style_btn;
|
||||
|
||||
std::string text;
|
||||
std::function<LcdFlags(void)> bgColorHandler = nullptr;
|
||||
|
||||
+34
-12
@@ -84,6 +84,7 @@ Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, Lc
|
||||
lv_obj_add_style(lvobj, &windowFactory.style, LV_PART_MAIN);
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
lv_obj_set_size(lvobj, rect.w, rect.h);
|
||||
lv_obj_set_user_data(lvobj, this);
|
||||
|
||||
lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLL_MOMENTUM);
|
||||
@@ -97,28 +98,34 @@ Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, Lc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern lv_obj_t * canvas;
|
||||
Window::~Window()
|
||||
{
|
||||
TRACE_WINDOWS("Destroy %p %s", this, getWindowDebugString().c_str());
|
||||
if (lvobj != nullptr)
|
||||
if (focusWindow == this) {
|
||||
focusWindow = nullptr;
|
||||
}
|
||||
|
||||
if(children.size() > 0)
|
||||
deleteChildren();
|
||||
if (lvobj != nullptr && lvobj != canvas)
|
||||
{
|
||||
lv_obj_del(lvobj);
|
||||
lvobj = nullptr;
|
||||
}
|
||||
|
||||
if (focusWindow == this) {
|
||||
focusWindow = nullptr;
|
||||
}
|
||||
|
||||
deleteChildren();
|
||||
}
|
||||
|
||||
void Window::attach(Window * newParent)
|
||||
{
|
||||
if (parent) detach();
|
||||
parent = newParent;
|
||||
if (newParent) newParent->addChild(this);
|
||||
if (newParent)
|
||||
{
|
||||
newParent->addChild(this);
|
||||
if(lvobj != nullptr)
|
||||
lv_obj_set_parent(lvobj, newParent->lvobj);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::detach()
|
||||
@@ -126,6 +133,8 @@ void Window::detach()
|
||||
if (parent) {
|
||||
parent->removeChild(this);
|
||||
parent = nullptr;
|
||||
if(lvobj != nullptr)
|
||||
lv_obj_set_parent(lvobj, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,15 +156,15 @@ void Window::deleteLater(bool detach, bool trash)
|
||||
else
|
||||
parent = nullptr;
|
||||
|
||||
if (trash) {
|
||||
Window::trash.push_back(this);
|
||||
}
|
||||
|
||||
deleteChildren();
|
||||
|
||||
if (closeHandler) {
|
||||
closeHandler();
|
||||
}
|
||||
|
||||
if (trash) {
|
||||
Window::trash.push_back(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::clear()
|
||||
@@ -168,9 +177,20 @@ void Window::clear()
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void Window::clearLvgl()
|
||||
{
|
||||
for (auto window: children)
|
||||
{
|
||||
if(lvobj != nullptr && window->lvobj != nullptr && window->lvobj->parent == lvobj)
|
||||
window->clearLvgl();
|
||||
}
|
||||
lvobj = nullptr;
|
||||
}
|
||||
|
||||
void Window::deleteChildren()
|
||||
{
|
||||
for (auto window: children) {
|
||||
window->clearLvgl();
|
||||
window->deleteLater(false);
|
||||
}
|
||||
children.clear();
|
||||
@@ -300,6 +320,8 @@ bool Window::hasOpaqueRect(const rect_t & testRect) const
|
||||
|
||||
void Window::fullPaint(BitmapBuffer * dc)
|
||||
{
|
||||
if(lvobj != nullptr)
|
||||
lv_obj_invalidate(lvobj);
|
||||
bool paintNeeded = true;
|
||||
std::list<Window *>::iterator firstChild;
|
||||
|
||||
|
||||
+1
@@ -162,6 +162,7 @@ class Window
|
||||
virtual void deleteLater(bool detach = true, bool trash = true);
|
||||
|
||||
void clear();
|
||||
void clearLvgl();
|
||||
|
||||
void deleteChildren();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user