From 98ab4ee39dfb3579d83cb8b3b3f801a86158be8c Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 1 Mar 2022 14:17:56 +0300 Subject: [PATCH] Fix element reshape caching --- libs/ui/source/element.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/libs/ui/source/element.cpp b/libs/ui/source/element.cpp index b7363de8..b64be9ea 100644 --- a/libs/ui/source/element.cpp +++ b/libs/ui/source/element.cpp @@ -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(); } }); }