diff options
Diffstat (limited to 'src/ui/controls')
-rw-r--r-- | src/ui/controls/linear_layout.cpp | 16 | ||||
-rw-r--r-- | src/ui/controls/linear_layout.hpp | 4 | ||||
-rw-r--r-- | src/ui/controls/scroll_control.cpp | 30 | ||||
-rw-r--r-- | src/ui/controls/scroll_control.hpp | 6 | ||||
-rw-r--r-- | src/ui/controls/text_control.cpp | 17 | ||||
-rw-r--r-- | src/ui/controls/text_control.hpp | 4 | ||||
-rw-r--r-- | src/ui/controls/toggle_button.cpp | 2 | ||||
-rw-r--r-- | src/ui/controls/toggle_button.hpp | 2 |
8 files changed, 34 insertions, 47 deletions
diff --git a/src/ui/controls/linear_layout.cpp b/src/ui/controls/linear_layout.cpp index 8fb91513..2b8f3e43 100644 --- a/src/ui/controls/linear_layout.cpp +++ b/src/ui/controls/linear_layout.cpp @@ -17,7 +17,7 @@ namespace cru::ui::controls return control_type; } - Size LinearLayout::OnMeasureContent(const Size& available_size) + Size LinearLayout::OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo& additional_info) { auto actual_size_for_children = Size::Zero(); @@ -33,7 +33,7 @@ namespace cru::ui::controls if (mode == MeasureMode::Content || mode == MeasureMode::Exactly) { Size current_available_size(AtLeast0(available_size.width - actual_size_for_children.width), available_size.height); - control->Measure(current_available_size); + control->Measure(current_available_size, additional_info); const auto size = control->GetDesiredSize(); actual_size_for_children.width += size.width; secondary_side_child_max_length = std::max(size.height, secondary_side_child_max_length); @@ -48,7 +48,7 @@ namespace cru::ui::controls if (mode == MeasureMode::Content || mode == MeasureMode::Exactly) { Size current_available_size(available_size.width, AtLeast0(available_size.height - actual_size_for_children.height)); - control->Measure(current_available_size); + control->Measure(current_available_size, additional_info); const auto size = control->GetDesiredSize(); actual_size_for_children.height += size.height; secondary_side_child_max_length = std::max(size.width, secondary_side_child_max_length); @@ -62,7 +62,7 @@ namespace cru::ui::controls const auto available_width = AtLeast0(available_size.width - actual_size_for_children.width) / stretch_control_list.size(); for (const auto control : stretch_control_list) { - control->Measure(Size(available_width, available_size.height)); + control->Measure(Size(available_width, available_size.height), additional_info); const auto size = control->GetDesiredSize(); actual_size_for_children.width += size.width; secondary_side_child_max_length = std::max(size.height, secondary_side_child_max_length); @@ -73,7 +73,7 @@ namespace cru::ui::controls const auto available_height = AtLeast0(available_size.height - actual_size_for_children.height) / stretch_control_list.size(); for (const auto control : stretch_control_list) { - control->Measure(Size(available_size.width, available_height)); + control->Measure(Size(available_size.width, available_height), additional_info); const auto size = control->GetDesiredSize(); actual_size_for_children.height += size.height; secondary_side_child_max_length = std::max(size.width, secondary_side_child_max_length); @@ -107,7 +107,7 @@ namespace cru::ui::controls return actual_size_for_children; } - void LinearLayout::OnLayoutContent(const Rect& rect) + void LinearLayout::OnLayoutContent(const Rect& rect, const AdditionalLayoutInfo& additional_info) { float current_main_side_anchor = 0; for(auto control: GetChildren()) @@ -138,12 +138,12 @@ namespace cru::ui::controls if (orientation_ == Orientation::Horizontal) { - control->Layout(calculate_rect(current_main_side_anchor, calculate_secondary_side_anchor(rect.height, size.height))); + control->Layout(calculate_rect(current_main_side_anchor, calculate_secondary_side_anchor(rect.height, size.height)), additional_info); current_main_side_anchor += size.width; } else { - control->Layout(calculate_rect(calculate_secondary_side_anchor(rect.width, size.width), current_main_side_anchor)); + control->Layout(calculate_rect(calculate_secondary_side_anchor(rect.width, size.width), current_main_side_anchor), additional_info); current_main_side_anchor += size.height; } } diff --git a/src/ui/controls/linear_layout.hpp b/src/ui/controls/linear_layout.hpp index deb51bd1..96becc6f 100644 --- a/src/ui/controls/linear_layout.hpp +++ b/src/ui/controls/linear_layout.hpp @@ -41,8 +41,8 @@ namespace cru::ui::controls StringView GetControlType() const override final; protected: - Size OnMeasureContent(const Size& available_size) override; - void OnLayoutContent(const Rect& rect) override; + Size OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo& additional_info) override; + void OnLayoutContent(const Rect& rect, const AdditionalLayoutInfo& additional_info) override; private: Orientation orientation_; diff --git a/src/ui/controls/scroll_control.cpp b/src/ui/controls/scroll_control.cpp index 9681924d..8358abc5 100644 --- a/src/ui/controls/scroll_control.cpp +++ b/src/ui/controls/scroll_control.cpp @@ -224,7 +224,7 @@ namespace cru::ui::controls view_height_ = length; } - Size ScrollControl::OnMeasureContent(const Size& available_size) + Size ScrollControl::OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo& additional_info) { const auto layout_params = GetLayoutParams(); @@ -234,13 +234,6 @@ namespace cru::ui::controls if (layout_params->width.mode == MeasureMode::Content) debug::DebugMessage(L"ScrollControl: Width measure mode is Content and horizontal scroll is enabled. So Stretch is used instead."); - for (auto child : GetChildren()) - { - const auto child_layout_params = child->GetLayoutParams(); - if (child_layout_params->width.mode == MeasureMode::Stretch) - throw std::runtime_error(Format("ScrollControl: Horizontal scroll is enabled but a child {} 's width measure mode is Stretch which may cause infinite length.", ToUtf8String(child->GetControlType()))); - } - available_size_for_children.width = std::numeric_limits<float>::max(); } @@ -249,20 +242,13 @@ namespace cru::ui::controls if (layout_params->height.mode == MeasureMode::Content) debug::DebugMessage(L"ScrollControl: Height measure mode is Content and vertical scroll is enabled. So Stretch is used instead."); - for (auto child : GetChildren()) - { - const auto child_layout_params = child->GetLayoutParams(); - if (child_layout_params->height.mode == MeasureMode::Stretch) - throw std::runtime_error(Format("ScrollControl: Vertical scroll is enabled but a child {} 's height measure mode is Stretch which may cause infinite length.", ToUtf8String(child->GetControlType()))); - } - available_size_for_children.height = std::numeric_limits<float>::max(); } auto max_child_size = Size::Zero(); for (auto control: GetChildren()) { - control->Measure(available_size_for_children); + control->Measure(available_size_for_children, AdditionalMeasureInfo{false, false}); const auto&& size = control->GetDesiredSize(); if (max_child_size.width < size.width) max_child_size.width = size.width; @@ -270,7 +256,7 @@ namespace cru::ui::controls max_child_size.height = size.height; } - // coerce size fro stretch. + // coerce size for stretch. for (auto control: GetChildren()) { auto size = control->GetDesiredSize(); @@ -297,7 +283,7 @@ namespace cru::ui::controls return result; } - void ScrollControl::OnLayoutContent(const Rect& rect) + void ScrollControl::OnLayoutContent(const Rect& rect, const AdditionalLayoutInfo& additional_info) { auto layout_rect = rect; @@ -318,11 +304,11 @@ namespace cru::ui::controls control->Layout(Rect(Point( calculate_anchor(rect.left, layout_rect.width, size.width, offset_x_), calculate_anchor(rect.top, layout_rect.height, size.height, offset_y_) - ), size)); + ), size), additional_info); } } - void ScrollControl::AfterLayoutSelf() + void ScrollControl::OnRectChange(const Rect& old_rect, const Rect& new_rect) { UpdateScrollBarBorderInfo(); CoerceAndSetOffsets(offset_x_, offset_y_, false); @@ -344,10 +330,10 @@ namespace cru::ui::controls for (auto child : GetChildren()) { const auto old_position = child->GetPositionRelative(); - child->SetPositionRelative(Point( + child->SetRect(Rect(Point( old_position.x + old_offset_x - offset_x_, old_position.y + old_offset_y - offset_y_ - )); + ), child->GetSize())); } } InvalidateDraw(); diff --git a/src/ui/controls/scroll_control.hpp b/src/ui/controls/scroll_control.hpp index 4eabc605..db29b141 100644 --- a/src/ui/controls/scroll_control.hpp +++ b/src/ui/controls/scroll_control.hpp @@ -117,10 +117,10 @@ namespace cru::ui::controls void SetViewWidth(float length); void SetViewHeight(float length); - Size OnMeasureContent(const Size& available_size) override final; - void OnLayoutContent(const Rect& rect) override final; + Size OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo& additional_info) override final; + void OnLayoutContent(const Rect& rect, const AdditionalLayoutInfo& additional_info) override final; - void AfterLayoutSelf() override; + void OnRectChange(const Rect& old_rect, const Rect& new_rect) override; private: void CoerceAndSetOffsets(float offset_x, float offset_y, bool update_children = true); diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp index f32c068f..6412eec9 100644 --- a/src/ui/controls/text_control.cpp +++ b/src/ui/controls/text_control.cpp @@ -56,14 +56,6 @@ namespace cru::ui::controls SetClipContent(true); - size_changed_event.AddHandler([this](events::SizeChangedEventArgs& args) - { - const auto content = GetRect(RectRange::Content); - ThrowIfFailed(text_layout_->SetMaxWidth(content.width)); - ThrowIfFailed(text_layout_->SetMaxHeight(content.height)); - InvalidateDraw(); - }); - draw_content_event.AddHandler([this](events::DrawEventArgs& args) { const auto device_context = args.GetDeviceContext(); @@ -177,7 +169,7 @@ namespace cru::ui::controls } } - Size TextControl::OnMeasureContent(const Size& available_size) + Size TextControl::OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo&) { ThrowIfFailed(text_layout_->SetMaxWidth(available_size.width)); ThrowIfFailed(text_layout_->SetMaxHeight(available_size.height)); @@ -196,6 +188,13 @@ namespace cru::ui::controls } + void TextControl::OnRectChange(const Rect& old_rect, const Rect& new_rect) + { + const auto content = GetRect(RectRange::Content); + ThrowIfFailed(text_layout_->SetMaxWidth(content.width)); + ThrowIfFailed(text_layout_->SetMaxHeight(content.height)); + } + void TextControl::OnTextChangedCore(const String& old_text, const String& new_text) { RecreateTextLayout(); diff --git a/src/ui/controls/text_control.hpp b/src/ui/controls/text_control.hpp index 1e4c985d..9b83f4bb 100644 --- a/src/ui/controls/text_control.hpp +++ b/src/ui/controls/text_control.hpp @@ -62,10 +62,12 @@ namespace cru::ui::controls protected: void SetSelectable(bool is_selectable); - Size OnMeasureContent(const Size& available_size) override final; + Size OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo&) override final; virtual void RequestChangeCaretPosition(unsigned position); + void OnRectChange(const Rect& old_rect, const Rect& new_rect) override; + private: void OnTextChangedCore(const String& old_text, const String& new_text); diff --git a/src/ui/controls/toggle_button.cpp b/src/ui/controls/toggle_button.cpp index 874a245f..6eb0bc40 100644 --- a/src/ui/controls/toggle_button.cpp +++ b/src/ui/controls/toggle_button.cpp @@ -105,7 +105,7 @@ namespace cru::ui::controls SetState(!GetState()); } - Size ToggleButton::OnMeasureContent(const Size& available_size) + Size ToggleButton::OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo&) { const Size result_size( half_width * 2 + stroke_width, diff --git a/src/ui/controls/toggle_button.hpp b/src/ui/controls/toggle_button.hpp index 8b7402c8..091f908a 100644 --- a/src/ui/controls/toggle_button.hpp +++ b/src/ui/controls/toggle_button.hpp @@ -43,7 +43,7 @@ namespace cru::ui::controls Event<events::ToggleEventArgs> toggle_event; protected: - Size OnMeasureContent(const Size& available_size) override; + Size OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo&) override; private: bool state_ = false; |