aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/ui/render/RenderObject.hpp2
-rw-r--r--src/ui/WindowHost.cpp6
-rw-r--r--src/ui/render/RenderObject.cpp6
3 files changed, 13 insertions, 1 deletions
diff --git a/include/cru/ui/render/RenderObject.hpp b/include/cru/ui/render/RenderObject.hpp
index 4e5c9060..20e095fa 100644
--- a/include/cru/ui/render/RenderObject.hpp
+++ b/include/cru/ui/render/RenderObject.hpp
@@ -74,6 +74,8 @@ class RenderObject : public Object {
void AddChild(RenderObject* render_object, Index position);
void RemoveChild(Index position);
+ void TraverseDescendants(const std::function<void(RenderObject*)>& action);
+
// Offset from parent's lefttop to lefttop of this render object. Margin is
// accounted for.
Point GetOffset() const { return offset_; }
diff --git a/src/ui/WindowHost.cpp b/src/ui/WindowHost.cpp
index 12eb746a..8c61d27d 100644
--- a/src/ui/WindowHost.cpp
+++ b/src/ui/WindowHost.cpp
@@ -184,8 +184,12 @@ void WindowHost::Relayout(const Size& available_size) {
render::MeasureSize::NotSpecified());
root_render_object_->Layout(Point{});
for (auto& action : after_layout_stable_action_) action();
- after_layout_stable_action_.clear();
after_layout_event_.Raise(AfterLayoutEventArgs{});
+ root_render_object_->TraverseDescendants(
+ [](render::RenderObject* render_object) {
+ render_object->OnAfterLayout();
+ });
+ after_layout_stable_action_.clear();
if constexpr (debug_flags::layout)
log::TagDebug(log_tag, u"A relayout is finished.");
}
diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp
index fd0c7712..57929a21 100644
--- a/src/ui/render/RenderObject.cpp
+++ b/src/ui/render/RenderObject.cpp
@@ -41,6 +41,12 @@ void RenderObject::RemoveChild(const Index position) {
OnRemoveChild(removed_child, position);
}
+void RenderObject::TraverseDescendants(
+ const std::function<void(RenderObject*)>& action) {
+ action(this);
+ for (auto child : children_) child->TraverseDescendants(action);
+}
+
Point RenderObject::GetTotalOffset() const {
Point result{};
const RenderObject* render_object = this;