From 43fe5dfe001f25870788742333d141f406b07364 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 29 Jan 2022 22:19:36 +0800 Subject: ... --- src/ui/controls/RootControl.cpp | 1 + src/ui/render/FlexLayoutRenderObject.cpp | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ui/controls/RootControl.cpp b/src/ui/controls/RootControl.cpp index a7366155..dbf037fc 100644 --- a/src/ui/controls/RootControl.cpp +++ b/src/ui/controls/RootControl.cpp @@ -20,6 +20,7 @@ RootControl::RootControl(Control* attached_control) render_object_->SetDefaultVertialAlignment(Alignment::Stretch); SetContainerRenderObject(render_object_.get()); window_host_ = std::make_unique(this); + window_host_->SetLayoutPreferToFillWindow(true); } RootControl::~RootControl() {} diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index 6d1f9c26..0e76995b 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -2,7 +2,9 @@ #include "cru/common/Logger.hpp" #include "cru/platform/graphics/util/Painter.hpp" +#include "cru/ui/Base.hpp" #include "cru/ui/render/LayoutHelper.hpp" +#include "cru/ui/render/MeasureRequirement.hpp" #include #include @@ -91,7 +93,8 @@ template & children, - const std::vector& layout_data, StringView log_tag) { + const std::vector& layout_data, + Alignment item_cross_align, StringView log_tag) { Expects(children.size() == layout_data.size()); direction_tag_t direction_tag; @@ -311,6 +314,17 @@ Size FlexLayoutMeasureContentImpl( child_max_cross_length = std::max(min_cross_length.GetLengthOr0(), child_max_cross_length); + for (Index i = 0; i < child_count; i++) { + auto child_layout_data = layout_data[i]; + auto child = children[i]; + if (child_layout_data.cross_alignment.value_or(item_cross_align) == + Alignment::Stretch) { + auto size = child->GetSize(); + GetCross(size, direction_tag) = child_max_cross_length; + child->Measure({size, size}, MeasureSize::NotSpecified()); + } + } + return CreateTSize(total_length, child_max_cross_length, direction_tag); } } // namespace @@ -322,11 +336,11 @@ Size FlexLayoutRenderObject::OnMeasureContent( if (horizontal) { return FlexLayoutMeasureContentImpl( requirement, preferred_size, GetChildren(), GetChildLayoutDataList(), - log_tag); + item_cross_align_, log_tag); } else { return FlexLayoutMeasureContentImpl( requirement, preferred_size, GetChildren(), GetChildLayoutDataList(), - log_tag); + item_cross_align_, log_tag); } } -- cgit v1.2.3