aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/controls/Control.cpp2
-rw-r--r--src/ui/host/RoutedEventDispatch.h6
-rw-r--r--src/ui/host/WindowHost.cpp2
-rw-r--r--src/ui/render/FlexLayoutRenderObject.cpp10
-rw-r--r--src/ui/render/RenderObject.cpp13
-rw-r--r--src/ui/render/TextRenderObject.cpp3
6 files changed, 32 insertions, 4 deletions
diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp
index ba43b2b8..a66b605f 100644
--- a/src/ui/controls/Control.cpp
+++ b/src/ui/controls/Control.cpp
@@ -27,7 +27,7 @@ Control::Control() {
});
}
-Control::~Control() {}
+Control::~Control() { ReleaseMouse(); }
host::WindowHost* Control::GetWindowHost() const {
auto parent = GetParent();
diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h
index ae1421ee..2ab51645 100644
--- a/src/ui/host/RoutedEventDispatch.h
+++ b/src/ui/host/RoutedEventDispatch.h
@@ -25,6 +25,8 @@ void DispatchEvent(
controls::Control* const original_sender,
events::RoutedEvent<EventArgs>* (controls::Control::*event_ptr)(),
controls::Control* const last_receiver, Args&&... args) {
+ if (original_sender == nullptr) return;
+
CRU_UNUSED(event_name)
if (original_sender == last_receiver) {
@@ -41,7 +43,9 @@ void DispatchEvent(
auto parent = original_sender;
while (parent != last_receiver) {
receive_list.push_back(parent);
- parent = parent->GetParent();
+ auto p = parent->GetParent();
+ assert(!(p == nullptr && last_receiver != nullptr));
+ parent = p;
}
if constexpr (debug_flags::routed_event) {
diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp
index 6849d000..91b5f438 100644
--- a/src/ui/host/WindowHost.cpp
+++ b/src/ui/host/WindowHost.cpp
@@ -53,6 +53,8 @@ bool IsAncestor(controls::Control* control, controls::Control* ancestor) {
// Ancestor at last.
std::vector<controls::Control*> GetAncestorList(controls::Control* control) {
+ if (control == nullptr) return {};
+
std::vector<controls::Control*> l;
while (control != nullptr) {
l.push_back(control);
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;
}