aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/controls
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-22 22:57:44 +0800
committercrupest <crupest@outlook.com>2018-09-22 22:57:44 +0800
commit5d91d1e5594e37ca5c282e602407eaeb34c6d986 (patch)
tree0086bb88c152b8ea9eb31e86906afcd238309cda /CruUI/ui/controls
parentdc293cef8f25ba70c5d99d73aa472277484ca879 (diff)
downloadcru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.tar.gz
cru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.tar.bz2
cru-5d91d1e5594e37ca5c282e602407eaeb34c6d986.zip
Done 3 things:
1. Add some helper functions for create controls with layout params. 2. Fix a bug in measure of linear layout. 3. Fix a bug in exception.
Diffstat (limited to 'CruUI/ui/controls')
-rw-r--r--CruUI/ui/controls/button.h9
-rw-r--r--CruUI/ui/controls/linear_layout.cpp4
-rw-r--r--CruUI/ui/controls/linear_layout.h7
3 files changed, 14 insertions, 6 deletions
diff --git a/CruUI/ui/controls/button.h b/CruUI/ui/controls/button.h
index f9ad7726..bd3f6eb3 100644
--- a/CruUI/ui/controls/button.h
+++ b/CruUI/ui/controls/button.h
@@ -1,5 +1,7 @@
#pragma once
+#include <initializer_list>
+
#include "ui/control.h"
namespace cru::ui::controls
@@ -7,9 +9,12 @@ namespace cru::ui::controls
class Button : public Control
{
public:
- static Button* Create()
+ static Button* Create(const std::initializer_list<Control*>& children = std::initializer_list<Control*>())
{
- return new Button();
+ const auto button = new Button();
+ for (const auto control : children)
+ button->AddChild(control);
+ return button;
}
protected:
diff --git a/CruUI/ui/controls/linear_layout.cpp b/CruUI/ui/controls/linear_layout.cpp
index 116802ba..22bf26e9 100644
--- a/CruUI/ui/controls/linear_layout.cpp
+++ b/CruUI/ui/controls/linear_layout.cpp
@@ -89,7 +89,7 @@ namespace cru::ui::controls
const auto available_width = rest_available_size_for_children.width / stretch_control_list.size();
for (const auto control : stretch_control_list)
{
- control->Measure(Size(available_width, AtLeast0(rest_available_size_for_children.height)));
+ control->Measure(Size(AtLeast0(available_width), rest_available_size_for_children.height));
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);
@@ -100,7 +100,7 @@ namespace cru::ui::controls
const auto available_height = rest_available_size_for_children.height / stretch_control_list.size();
for (const auto control : stretch_control_list)
{
- control->Measure(Size(AtLeast0(rest_available_size_for_children.width), available_height));
+ control->Measure(Size(rest_available_size_for_children.width, AtLeast0(available_height)));
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);
diff --git a/CruUI/ui/controls/linear_layout.h b/CruUI/ui/controls/linear_layout.h
index ead56081..369824d4 100644
--- a/CruUI/ui/controls/linear_layout.h
+++ b/CruUI/ui/controls/linear_layout.h
@@ -13,9 +13,12 @@ namespace cru::ui::controls
Vertical
};
- static LinearLayout* Create(const Orientation orientation = Orientation::Vertical)
+ static LinearLayout* Create(const Orientation orientation = Orientation::Vertical, const std::initializer_list<Control*>& children = std::initializer_list<Control*>())
{
- return new LinearLayout(orientation);
+ const auto linear_layout = new LinearLayout(orientation);
+ for (const auto control : children)
+ linear_layout->AddChild(control);
+ return linear_layout;
}
protected: