From 9cf812f77a879d5394a9158ce290f9d7e858de7d Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 10 Nov 2018 22:11:05 +0800 Subject: Refactor layout invalidation system. --- src/ui/window.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/ui/window.cpp') diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 2737b70b..41104924 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -429,10 +429,32 @@ namespace cru::ui } + void Window::WindowInvalidateLayout() + { + if (is_layout_invalid_) + return; + + is_layout_invalid_ = true; + InvokeLater([this] + { + if (is_layout_invalid_) + Relayout(); + }); + } + void Window::Relayout() { OnMeasureCore(GetSize()); OnLayoutCore(Rect(Point::Zero(), GetSize())); + is_layout_invalid_ = false; + } + + void Window::SetSizeFitContent(const Size& max_size) + { + OnMeasureCore(max_size); + SetClientSize(GetDesiredSize()); + OnLayoutCore(Rect(Point::Zero(), GetSize())); + is_layout_invalid_ = false; } void Window::RefreshControlList() { @@ -597,7 +619,7 @@ namespace cru::ui void Window::OnResizeInternal(const int new_width, const int new_height) { render_target_->ResizeBuffer(new_width, new_height); if (!(new_width == 0 && new_height == 0)) - InvalidateLayout(); + WindowInvalidateLayout(); } void Window::OnSetFocusInternal() -- cgit v1.2.3