diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/control.cpp | 2 | ||||
-rw-r--r-- | src/ui/layout_base.cpp | 18 | ||||
-rw-r--r-- | src/ui/layout_base.hpp | 7 | ||||
-rw-r--r-- | src/ui/window.cpp | 24 | ||||
-rw-r--r-- | src/ui/window.hpp | 8 |
5 files changed, 31 insertions, 28 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp index ed904de1..2d09a382 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -238,7 +238,7 @@ namespace cru::ui void Control::InvalidateLayout() { if (const auto window = GetWindow()) - LayoutManager::GetInstance()->InvalidateWindowLayout(window); + window->WindowInvalidateLayout(); } void Control::Measure(const Size& available_size) diff --git a/src/ui/layout_base.cpp b/src/ui/layout_base.cpp index 5363c52b..40bb71b3 100644 --- a/src/ui/layout_base.cpp +++ b/src/ui/layout_base.cpp @@ -68,24 +68,6 @@ namespace cru::ui RefreshControlPositionCacheInternal(control, point); } - void LayoutManager::InvalidateWindowLayout(Window* window) - { - layout_invalid_windows_.insert(window); - - if (layout_invalid_windows_.size() == 1) - InvokeLater([this]() - { - this->RefreshInvalidWindowLayout(); - }); - } - - void LayoutManager::RefreshInvalidWindowLayout() - { - for (const auto window : layout_invalid_windows_) - window->Relayout(); - layout_invalid_windows_.clear(); - } - void LayoutManager::RefreshControlPositionCacheInternal(Control * control, const Point & parent_lefttop_absolute) { const auto position = control->GetPositionRelative(); diff --git a/src/ui/layout_base.hpp b/src/ui/layout_base.hpp index d8e4e2d1..7ae6f65c 100644 --- a/src/ui/layout_base.hpp +++ b/src/ui/layout_base.hpp @@ -132,13 +132,6 @@ namespace cru::ui //Refresh position cache of the control and its descendants immediately. static void RefreshControlPositionCache(Control* control); - - //*************** region: layout *************** - - void InvalidateWindowLayout(Window* window); - - void RefreshInvalidWindowLayout(); - private: static void RefreshControlPositionCacheInternal(Control* control, const Point& parent_lefttop_absolute); 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() diff --git a/src/ui/window.hpp b/src/ui/window.hpp index 963bff78..05b1a259 100644 --- a/src/ui/window.hpp +++ b/src/ui/window.hpp @@ -192,8 +192,12 @@ namespace cru::ui //*************** region: layout *************** + void WindowInvalidateLayout(); + void Relayout(); + void SetSizeFitContent(const Size& max_size = Size(1000, 1000)); + //*************** region: functions *************** //Refresh control list. @@ -319,7 +323,9 @@ namespace cru::ui Control* focus_control_ = this; // "focus_control_" can't be nullptr Control* mouse_capture_control_ = nullptr; - + + bool is_layout_invalid_ = false; + #ifdef CRU_DEBUG_LAYOUT bool debug_layout_ = false; #endif |