aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-18 21:40:23 +0800
committercrupest <crupest@outlook.com>2020-10-18 21:40:23 +0800
commitf90650efb7175957892d18097954ffd3aa59dc95 (patch)
tree136bde01edf8c4f2c36f2aa0c7b8aecfc6577483
parentc072432e68d7a3d7659add0994b2f8caf387ddf2 (diff)
downloadcru-f90650efb7175957892d18097954ffd3aa59dc95.tar.gz
cru-f90650efb7175957892d18097954ffd3aa59dc95.tar.bz2
cru-f90650efb7175957892d18097954ffd3aa59dc95.zip
...
-rw-r--r--include/cru/ui/UiHost.hpp7
-rw-r--r--src/ui/UiHost.cpp16
2 files changed, 22 insertions, 1 deletions
diff --git a/include/cru/ui/UiHost.hpp b/include/cru/ui/UiHost.hpp
index b1658ef6..01791de6 100644
--- a/include/cru/ui/UiHost.hpp
+++ b/include/cru/ui/UiHost.hpp
@@ -59,6 +59,11 @@ class UiHost : public Object, public SelfResolvable<UiHost> {
return &after_layout_event_;
}
+ // If true, preferred size of root render object is set to window size when
+ // measure. Default is true.
+ bool IsLayoutPreferToFillWindow() const;
+ void SetLayoutPreferToFillWindow(bool value);
+
void Relayout();
// Get current control that mouse hovers on. This ignores the mouse-capture
@@ -168,5 +173,7 @@ class UiHost : public Object, public SelfResolvable<UiHost> {
Control* focus_control_; // "focus_control_" can't be nullptr
Control* mouse_captured_control_;
+
+ bool layout_prefer_to_fill_window_ = true;
};
} // namespace cru::ui
diff --git a/src/ui/UiHost.cpp b/src/ui/UiHost.cpp
index 48a4e06e..cd09907f 100644
--- a/src/ui/UiHost.cpp
+++ b/src/ui/UiHost.cpp
@@ -7,6 +7,7 @@
#include "cru/platform/native/UiApplication.hpp"
#include "cru/platform/native/Window.hpp"
#include "cru/ui/Window.hpp"
+#include "cru/ui/render/MeasureRequirement.hpp"
#include "cru/ui/render/WindowRenderObject.hpp"
namespace cru::ui {
@@ -168,14 +169,27 @@ void UiHost::InvalidateLayout() {
}
}
+bool UiHost::IsLayoutPreferToFillWindow() const {
+ return layout_prefer_to_fill_window_;
+}
+
+void UiHost::SetLayoutPreferToFillWindow(bool value) {
+ if (value == layout_prefer_to_fill_window_) return;
+ layout_prefer_to_fill_window_ = value;
+ InvalidateLayout();
+}
+
void UiHost::Relayout() {
const auto native_window = native_window_resolver_->Resolve();
const auto client_size = native_window
? native_window->GetClientSize()
: Size{100, 100}; // a reasonable assumed size
+
root_render_object_->Measure(
render::MeasureRequirement{client_size,
- render::MeasureSize::NotSpecified()},
+ IsLayoutPreferToFillWindow()
+ ? render::MeasureSize(client_size)
+ : render::MeasureSize::NotSpecified()},
render::MeasureSize::NotSpecified());
root_render_object_->Layout(Point{});
after_layout_event_.Raise(AfterLayoutEventArgs{});