diff options
author | crupest <crupest@outlook.com> | 2018-09-21 23:20:44 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-21 23:20:44 +0800 |
commit | f9d3795e6dbb33fa5ffc0cb6e990462c4dd4974c (patch) | |
tree | d7c7deb89c10944ccbdeafb4dd89ca492e4608b6 /CruUI/ui/controls | |
parent | 82a45e611a2638cff7e3fffc09ba4569ca53a274 (diff) | |
download | cru-f9d3795e6dbb33fa5ffc0cb6e990462c4dd4974c.tar.gz cru-f9d3795e6dbb33fa5ffc0cb6e990462c4dd4974c.tar.bz2 cru-f9d3795e6dbb33fa5ffc0cb6e990462c4dd4974c.zip |
Move alignment property into layout params.
Diffstat (limited to 'CruUI/ui/controls')
-rw-r--r-- | CruUI/ui/controls/linear_layout.cpp | 7 | ||||
-rw-r--r-- | CruUI/ui/controls/linear_layout.h | 13 | ||||
-rw-r--r-- | CruUI/ui/controls/text_block.cpp | 4 | ||||
-rw-r--r-- | CruUI/ui/controls/toggle_button.cpp | 2 |
4 files changed, 7 insertions, 19 deletions
diff --git a/CruUI/ui/controls/linear_layout.cpp b/CruUI/ui/controls/linear_layout.cpp index 66005b2e..116802ba 100644 --- a/CruUI/ui/controls/linear_layout.cpp +++ b/CruUI/ui/controls/linear_layout.cpp @@ -25,7 +25,7 @@ namespace cru::ui::controls if (!layout_params->Validate()) throw std::runtime_error("LayoutParams is not valid. Please check it."); - auto&& get_available_length_for_child = [](const MeasureLength& layout_length, const float available_length) -> float + auto&& get_available_length_for_child = [](const LayoutLength& layout_length, const float available_length) -> float { switch (layout_length.mode) { @@ -119,7 +119,7 @@ namespace cru::ui::controls actual_size_for_children.height -= rest_available_size_for_children.height; } - auto&& calculate_final_length = [](const MeasureLength& layout_length, const float length_for_children, const float max_child_length) -> float + auto&& calculate_final_length = [](const LayoutLength& layout_length, const float length_for_children, const float max_child_length) -> float { switch (layout_length.mode) { @@ -144,8 +144,9 @@ namespace cru::ui::controls float current_anchor_length = 0; ForeachChild([this, ¤t_anchor_length, rect](Control* control) { + const auto layout_params = control->GetLayoutParams(); const auto size = control->GetDesiredSize(); - const auto alignment = GetAlignment(control); + const auto alignment = orientation_ == Orientation::Horizontal ? layout_params->height.alignment : layout_params->width.alignment; auto&& calculate_anchor = [alignment](const float layout_length, const float control_length) -> float { diff --git a/CruUI/ui/controls/linear_layout.h b/CruUI/ui/controls/linear_layout.h index 7c1fb2a8..ead56081 100644 --- a/CruUI/ui/controls/linear_layout.h +++ b/CruUI/ui/controls/linear_layout.h @@ -6,20 +6,7 @@ namespace cru::ui::controls { class LinearLayout : public Control { - private: - constexpr static auto alignment_key = L"linear_layout_alignment"; - public: - static Alignment GetAlignment(Control* control) - { - return control->GetAdditionalProperty<Alignment>(alignment_key).value_or(Alignment::Center); - } - - static void SetAlignment(Control* control, Alignment alignment) - { - control->SetAdditionalProperty(alignment_key, alignment); - } - enum class Orientation { Horizontal, diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp index 45f0d574..fa5e6903 100644 --- a/CruUI/ui/controls/text_block.cpp +++ b/CruUI/ui/controls/text_block.cpp @@ -206,7 +206,7 @@ namespace cru if (layout_params->width.mode == MeasureMode::Stretch && layout_params->height.mode == MeasureMode::Stretch) return available_size; - auto&& get_measure_length = [](const MeasureLength& layout_length, const float available_length) -> float + auto&& get_measure_length = [](const LayoutLength& layout_length, const float available_length) -> float { switch (layout_length.mode) { @@ -236,7 +236,7 @@ namespace cru const Size measure_result(metrics.width, metrics.height); - auto&& calculate_final_length = [](const MeasureLength& layout_length, const float measure_length, const float measure_result_length) -> float + auto&& calculate_final_length = [](const LayoutLength& layout_length, const float measure_length, const float measure_result_length) -> float { if ((layout_length.mode == MeasureMode::Stretch || layout_length.mode == MeasureMode::Exactly) diff --git a/CruUI/ui/controls/toggle_button.cpp b/CruUI/ui/controls/toggle_button.cpp index 94685b6e..9812a6f4 100644 --- a/CruUI/ui/controls/toggle_button.cpp +++ b/CruUI/ui/controls/toggle_button.cpp @@ -112,7 +112,7 @@ namespace cru::ui::controls { const auto layout_params = GetLayoutParams(); - auto&& get_measure_length = [](const MeasureLength& layout_length, const float available_length, const float fix_length) -> float + auto&& get_measure_length = [](const LayoutLength& layout_length, const float available_length, const float fix_length) -> float { switch (layout_length.mode) { |