aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/scroll_control.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/controls/scroll_control.cpp')
-rw-r--r--src/ui/controls/scroll_control.cpp30
1 files changed, 8 insertions, 22 deletions
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();