Fix element reshape caching

This commit is contained in:
Nikita Lisitsa 2022-03-01 14:17:56 +03:00
parent 512e9b51b7
commit 98ab4ee39d

View file

@ -9,13 +9,8 @@ namespace psemek::ui
void element::set_parent(element * parent) void element::set_parent(element * parent)
{ {
if (parent && reshape_posted_) if (!parent_ && parent && reshape_posted_)
{ parent->post_reshape();
parent->root()->reshape_posted_ = true;
reshape_posted_ = false;
}
else if (!parent && parent_)
reshape_posted_ |= parent_->root()->reshape_posted_;
parent_ = parent; parent_ = parent;
if (loop()) if (loop())
@ -138,16 +133,19 @@ namespace psemek::ui
void element::post_reshape() void element::post_reshape()
{ {
if (root()->reshape_posted_) auto r = root();
if (r->reshape_posted_)
return; return;
root()->reshape_posted_ = true; r->reshape_posted_ = true;
auto weak_self = weak_from_this(); auto weak_root = r->weak_from_this();
post([weak_self]{ post([weak_root]{
if (auto self = weak_self.lock()) if (auto root = weak_root.lock())
{ {
self->root()->reshape(); root->reshape_posted_ = false;
self->root()->reshape_posted_ = false; if (!root->parent())
root->reshape();
} }
}); });
} }