diff options
author | crupest <crupest@outlook.com> | 2022-02-16 22:42:34 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-16 22:42:34 +0800 |
commit | f75ab0bd662c73d15057d746347d09bf94a992a6 (patch) | |
tree | 91efc33de481edf5304001d80b914b69cc0fb338 /src/ui/render | |
parent | 2711b7032cafdc9bdbd6ae06db0325c91e6e7f63 (diff) | |
download | cru-f75ab0bd662c73d15057d746347d09bf94a992a6.tar.gz cru-f75ab0bd662c73d15057d746347d09bf94a992a6.tar.bz2 cru-f75ab0bd662c73d15057d746347d09bf94a992a6.zip |
...
Diffstat (limited to 'src/ui/render')
-rw-r--r-- | src/ui/render/FlexLayoutRenderObject.cpp | 10 | ||||
-rw-r--r-- | src/ui/render/RenderObject.cpp | 13 | ||||
-rw-r--r-- | src/ui/render/TextRenderObject.cpp | 3 |
3 files changed, 24 insertions, 2 deletions
diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index 6475d005..0699768a 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -181,6 +181,10 @@ Size FlexLayoutMeasureContentImpl( total_shrink_factor += layout_data[i].shrink_factor; } + if (total_shrink_factor == 0.0f) { + break; + } + for (Index i : shrink_list) { const auto child = children[i]; const float shrink_length = layout_data[i].shrink_factor / @@ -208,7 +212,7 @@ Size FlexLayoutMeasureContentImpl( const Size new_size = child->GetDesiredSize(); const float new_main_length = GetMain(new_size, direction_tag); - if (new_main_length > new_measure_length) { + if (new_main_length >= new_measure_length) { to_remove.push_back(i); } } @@ -269,7 +273,7 @@ Size FlexLayoutMeasureContentImpl( const Size new_size = child->GetDesiredSize(); const float new_main_length = GetMain(new_size, direction_tag); - if (new_main_length < new_measure_length) { + if (new_main_length <= new_measure_length) { to_remove.push_back(i); } } @@ -309,6 +313,8 @@ Size FlexLayoutMeasureContentImpl( std::max(preferred_cross_length.GetLengthOr0(), child_max_cross_length); child_max_cross_length = std::max(min_cross_length.GetLengthOr0(), child_max_cross_length); + child_max_cross_length = + std::min(max_cross_length.GetLengthOrMax(), child_max_cross_length); for (Index i = 0; i < child_count; i++) { auto child_layout_data = layout_data[i]; diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index 67bbae12..6c09ce99 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -6,6 +6,19 @@ #include "cru/ui/host/WindowHost.h" namespace cru::ui::render { + +void RenderObject::SetParent(RenderObject* new_parent) { +#ifdef CRU_DEBUG + // In case there is a cycle. + auto parent = new_parent; + while (parent) { + assert(parent != this); + parent = parent->GetParent(); + } +#endif + parent_ = new_parent; +} + void RenderObject::SetAttachedControl(controls::Control* new_control) { auto old_control = control_; control_ = new_control; diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index a64c96d2..82f314bd 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -216,10 +216,13 @@ Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement, result.width = std::max(result.width, preferred_size.width.GetLengthOr0()); result.width = std::max(result.width, requirement.min.width.GetLengthOr0()); + result.width = std::min(result.width, requirement.max.width.GetLengthOrMax()); result.height = std::max(result.height, preferred_size.height.GetLengthOr0()); result.height = std::max(result.height, requirement.min.height.GetLengthOr0()); + result.height = + std::min(result.height, requirement.max.height.GetLengthOrMax()); return result; } |