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