aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2018-11-07 21:17:30 +0800
committerGitHub <noreply@github.com>2018-11-07 21:17:30 +0800
commit634dab6ad2c9e4675beacfb77ac02b2d43cab132 (patch)
treeb44d8cd6f8f4ffbbb6451d42ba9a6b4d98828aec /src/ui/controls
parentdf0d6e1e282c75d4d8154011715f0b74547b35db (diff)
parent6f76a0ad3df99ea0d99623347d019536cc07e920 (diff)
downloadcru-634dab6ad2c9e4675beacfb77ac02b2d43cab132.tar.gz
cru-634dab6ad2c9e4675beacfb77ac02b2d43cab132.tar.bz2
cru-634dab6ad2c9e4675beacfb77ac02b2d43cab132.zip
Merge pull request #1 from crupest/minmax-layout
Min max layout support.
Diffstat (limited to 'src/ui/controls')
-rw-r--r--src/ui/controls/linear_layout.cpp31
-rw-r--r--src/ui/controls/linear_layout.h2
-rw-r--r--src/ui/controls/text_block.cpp20
-rw-r--r--src/ui/controls/text_block.h2
4 files changed, 24 insertions, 31 deletions
diff --git a/src/ui/controls/linear_layout.cpp b/src/ui/controls/linear_layout.cpp
index c23957ed..ed445f4c 100644
--- a/src/ui/controls/linear_layout.cpp
+++ b/src/ui/controls/linear_layout.cpp
@@ -27,7 +27,7 @@ namespace cru::ui::controls
Size LinearLayout::OnMeasureContent(const Size& available_size)
{
- auto rest_available_size_for_children = available_size;
+ auto actual_size_for_children = Size::Zero();
float secondary_side_child_max_length = 0;
@@ -40,9 +40,10 @@ namespace cru::ui::controls
const auto mode = control->GetLayoutParams()->width.mode;
if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
{
- control->Measure(AtLeast0(rest_available_size_for_children));
+ Size current_available_size(AtLeast0(available_size.width - actual_size_for_children.width), available_size.height);
+ control->Measure(current_available_size);
const auto size = control->GetDesiredSize();
- rest_available_size_for_children.width -= size.width;
+ actual_size_for_children.width += size.width;
secondary_side_child_max_length = std::max(size.height, secondary_side_child_max_length);
}
else
@@ -54,9 +55,10 @@ namespace cru::ui::controls
const auto mode = control->GetLayoutParams()->height.mode;
if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
{
- control->Measure(AtLeast0(rest_available_size_for_children));
+ Size current_available_size(available_size.width, AtLeast0(available_size.height - actual_size_for_children.height));
+ control->Measure(current_available_size);
const auto size = control->GetDesiredSize();
- rest_available_size_for_children.height -= size.height;
+ actual_size_for_children.height += size.height;
secondary_side_child_max_length = std::max(size.width, secondary_side_child_max_length);
}
else
@@ -65,38 +67,31 @@ namespace cru::ui::controls
if (orientation_ == Orientation::Horizontal)
{
- const auto available_width = rest_available_size_for_children.width / stretch_control_list.size();
+ 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(AtLeast0(available_width), rest_available_size_for_children.height));
+ control->Measure(Size(available_width, available_size.height));
const auto size = control->GetDesiredSize();
- rest_available_size_for_children.width -= size.width;
+ actual_size_for_children.width += size.width;
secondary_side_child_max_length = std::max(size.height, secondary_side_child_max_length);
}
}
else
{
- const auto available_height = rest_available_size_for_children.height / stretch_control_list.size();
+ 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(rest_available_size_for_children.width, AtLeast0(available_height)));
+ control->Measure(Size(available_size.width, available_height));
const auto size = control->GetDesiredSize();
- rest_available_size_for_children.height -= size.height;
+ actual_size_for_children.height += size.height;
secondary_side_child_max_length = std::max(size.width, secondary_side_child_max_length);
}
}
- auto actual_size_for_children = available_size;
if (orientation_ == Orientation::Horizontal)
- {
- actual_size_for_children.width -= rest_available_size_for_children.width;
actual_size_for_children.height = secondary_side_child_max_length;
- }
else
- {
actual_size_for_children.width = secondary_side_child_max_length;
- actual_size_for_children.height -= rest_available_size_for_children.height;
- }
return actual_size_for_children;
}
diff --git a/src/ui/controls/linear_layout.h b/src/ui/controls/linear_layout.h
index 1c2232bb..021f4b7d 100644
--- a/src/ui/controls/linear_layout.h
+++ b/src/ui/controls/linear_layout.h
@@ -4,6 +4,8 @@
namespace cru::ui::controls
{
+ // Min length of main side in layout params is of no meaning.
+ // All children will layout from start and redundant length is blank.
class LinearLayout : public Control
{
public:
diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp
index 7c52684d..e6c7fd7e 100644
--- a/src/ui/controls/text_block.cpp
+++ b/src/ui/controls/text_block.cpp
@@ -2,22 +2,16 @@
#include "ui/window.h"
-namespace cru
+namespace cru::ui::controls
{
- namespace ui
+ TextBlock::TextBlock(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
+ const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : TextControl(init_text_format, init_brush)
{
- namespace controls
- {
- TextBlock::TextBlock(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : TextControl(init_text_format, init_brush)
- {
- }
+ }
- StringView TextBlock::GetControlType() const
- {
- return control_type;
- }
- }
+ StringView TextBlock::GetControlType() const
+ {
+ return control_type;
}
}
diff --git a/src/ui/controls/text_block.h b/src/ui/controls/text_block.h
index cd0af1cc..681dc47b 100644
--- a/src/ui/controls/text_block.h
+++ b/src/ui/controls/text_block.h
@@ -19,6 +19,8 @@ namespace cru::ui::controls
return text_block;
}
+ using TextControl::SetSelectable; // Make this public.
+
protected:
TextBlock(
const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,