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();
|
checkHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lv_style_t style_btn;
|
||||||
|
|
||||||
|
|
||||||
LvglWidgetFactory textButtonFactory = LvglWidgetFactory(
|
LvglWidgetFactory textButtonFactory = LvglWidgetFactory(
|
||||||
[](lv_obj_t *parent) {
|
[](lv_obj_t *parent) {
|
||||||
|
|||||||
-1
@@ -124,7 +124,6 @@ class TextButton: public Button
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
lv_obj_t * label = nullptr;
|
lv_obj_t * label = nullptr;
|
||||||
lv_style_t style_btn;
|
|
||||||
|
|
||||||
std::string text;
|
std::string text;
|
||||||
std::function<LcdFlags(void)> bgColorHandler = nullptr;
|
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_add_style(lvobj, &windowFactory.style, LV_PART_MAIN);
|
||||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||||
lv_obj_set_size(lvobj, rect.w, rect.h);
|
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_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
|
||||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLL_MOMENTUM);
|
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()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
TRACE_WINDOWS("Destroy %p %s", this, getWindowDebugString().c_str());
|
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);
|
lv_obj_del(lvobj);
|
||||||
lvobj = nullptr;
|
lvobj = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focusWindow == this) {
|
|
||||||
focusWindow = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteChildren();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::attach(Window * newParent)
|
void Window::attach(Window * newParent)
|
||||||
{
|
{
|
||||||
if (parent) detach();
|
if (parent) detach();
|
||||||
parent = newParent;
|
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()
|
void Window::detach()
|
||||||
@@ -126,6 +133,8 @@ void Window::detach()
|
|||||||
if (parent) {
|
if (parent) {
|
||||||
parent->removeChild(this);
|
parent->removeChild(this);
|
||||||
parent = nullptr;
|
parent = nullptr;
|
||||||
|
if(lvobj != nullptr)
|
||||||
|
lv_obj_set_parent(lvobj, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,15 +156,15 @@ void Window::deleteLater(bool detach, bool trash)
|
|||||||
else
|
else
|
||||||
parent = nullptr;
|
parent = nullptr;
|
||||||
|
|
||||||
|
if (trash) {
|
||||||
|
Window::trash.push_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
deleteChildren();
|
deleteChildren();
|
||||||
|
|
||||||
if (closeHandler) {
|
if (closeHandler) {
|
||||||
closeHandler();
|
closeHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trash) {
|
|
||||||
Window::trash.push_back(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::clear()
|
void Window::clear()
|
||||||
@@ -168,9 +177,20 @@ void Window::clear()
|
|||||||
invalidate();
|
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()
|
void Window::deleteChildren()
|
||||||
{
|
{
|
||||||
for (auto window: children) {
|
for (auto window: children) {
|
||||||
|
window->clearLvgl();
|
||||||
window->deleteLater(false);
|
window->deleteLater(false);
|
||||||
}
|
}
|
||||||
children.clear();
|
children.clear();
|
||||||
@@ -300,6 +320,8 @@ bool Window::hasOpaqueRect(const rect_t & testRect) const
|
|||||||
|
|
||||||
void Window::fullPaint(BitmapBuffer * dc)
|
void Window::fullPaint(BitmapBuffer * dc)
|
||||||
{
|
{
|
||||||
|
if(lvobj != nullptr)
|
||||||
|
lv_obj_invalidate(lvobj);
|
||||||
bool paintNeeded = true;
|
bool paintNeeded = true;
|
||||||
std::list<Window *>::iterator firstChild;
|
std::list<Window *>::iterator firstChild;
|
||||||
|
|
||||||
|
|||||||
+1
@@ -162,6 +162,7 @@ class Window
|
|||||||
virtual void deleteLater(bool detach = true, bool trash = true);
|
virtual void deleteLater(bool detach = true, bool trash = true);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
void clearLvgl();
|
||||||
|
|
||||||
void deleteChildren();
|
void deleteChildren();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user