aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/linear_layout.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-05 20:54:48 +0800
committercrupest <crupest@outlook.com>2018-11-05 20:54:48 +0800
commit1dab244aaad8694ba37ef43caedd8c8ba0310c00 (patch)
treef70f6489a0f88520a0bdc095cd9713d03f83687b /src/ui/controls/linear_layout.cpp
parent252519effe30881825dd02e26dc41bd9cde34782 (diff)
downloadcru-1dab244aaad8694ba37ef43caedd8c8ba0310c00.tar.gz
cru-1dab244aaad8694ba37ef43caedd8c8ba0310c00.tar.bz2
cru-1dab244aaad8694ba37ef43caedd8c8ba0310c00.zip
...
Diffstat (limited to 'src/ui/controls/linear_layout.cpp')
-rw-r--r--src/ui/controls/linear_layout.cpp50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/ui/controls/linear_layout.cpp b/src/ui/controls/linear_layout.cpp
index 7921745a..fb5d3db7 100644
--- a/src/ui/controls/linear_layout.cpp
+++ b/src/ui/controls/linear_layout.cpp
@@ -1,5 +1,7 @@
#include "linear_layout.h"
+#include <algorithm>
+
namespace cru::ui::controls
{
LinearLayout::LinearLayout(const Orientation orientation)
@@ -28,33 +30,33 @@ namespace cru::ui::controls
// First measure Content and Exactly and count Stretch.
if (orientation_ == Orientation::Horizontal)
- ForeachChild([&](Control* const control)
- {
- const auto mode = control->GetLayoutParams()->width.mode;
- if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
+ for(auto control: GetChildren())
{
- control->Measure(AtLeast0(rest_available_size_for_children));
- const auto size = control->GetDesiredSize();
- rest_available_size_for_children.width -= size.width;
- secondary_side_child_max_length = std::max(size.height, secondary_side_child_max_length);
+ const auto mode = control->GetLayoutParams()->width.mode;
+ if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
+ {
+ control->Measure(AtLeast0(rest_available_size_for_children));
+ const auto size = control->GetDesiredSize();
+ rest_available_size_for_children.width -= size.width;
+ secondary_side_child_max_length = std::max(size.height, secondary_side_child_max_length);
+ }
+ else
+ stretch_control_list.push_back(control);
}
- else
- stretch_control_list.push_back(control);
- });
else
- ForeachChild([&](Control* const control)
- {
- const auto mode = control->GetLayoutParams()->height.mode;
- if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
+ for(auto control: GetChildren())
{
- control->Measure(AtLeast0(rest_available_size_for_children));
- const auto size = control->GetDesiredSize();
- rest_available_size_for_children.height -= size.height;
- secondary_side_child_max_length = std::max(size.width, secondary_side_child_max_length);
+ const auto mode = control->GetLayoutParams()->height.mode;
+ if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
+ {
+ control->Measure(AtLeast0(rest_available_size_for_children));
+ const auto size = control->GetDesiredSize();
+ rest_available_size_for_children.height -= size.height;
+ secondary_side_child_max_length = std::max(size.width, secondary_side_child_max_length);
+ }
+ else
+ stretch_control_list.push_back(control);
}
- else
- stretch_control_list.push_back(control);
- });
if (orientation_ == Orientation::Horizontal)
{
@@ -97,7 +99,7 @@ namespace cru::ui::controls
void LinearLayout::OnLayoutContent(const Rect& rect)
{
float current_main_side_anchor = 0;
- ForeachChild([this, &current_main_side_anchor, rect](Control* control)
+ for(auto control: GetChildren())
{
const auto layout_params = control->GetLayoutParams();
const auto size = control->GetDesiredSize();
@@ -133,6 +135,6 @@ namespace cru::ui::controls
control->Layout(calculate_rect(calculate_secondary_side_anchor(rect.width, size.width), current_main_side_anchor));
current_main_side_anchor += size.height;
}
- });
+ }
}
}