diff options
author | crupest <crupest@outlook.com> | 2018-10-05 00:50:38 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-10-05 00:50:38 +0800 |
commit | c5384d496e9ed429ca2baa3ca5e586ff255235eb (patch) | |
tree | be2b26a42dc9fde97379f98f035113e08e0bc331 /src | |
parent | 4312df1a13b182ed3f00838b5300a8f848f6c2fa (diff) | |
download | cru-c5384d496e9ed429ca2baa3ca5e586ff255235eb.tar.gz cru-c5384d496e9ed429ca2baa3ca5e586ff255235eb.tar.bz2 cru-c5384d496e9ed429ca2baa3ca5e586ff255235eb.zip |
Fix several headache bugs.
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/control.cpp | 23 | ||||
-rw-r--r-- | src/ui/controls/linear_layout.cpp | 2 | ||||
-rw-r--r-- | src/ui/window.cpp | 4 |
3 files changed, 18 insertions, 11 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 1264b15f..4acdd8f1 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -286,7 +286,7 @@ namespace cru { rect.height -= thickness.GetVerticalTotal(); } - Rect Control::GetRect(RectRange range) + Rect Control::GetRect(const RectRange range) { if (GetSize() == Size::Zero()) return Rect(); @@ -400,9 +400,11 @@ namespace cru { #endif if (is_bordered_) + { + const auto border_rect = GetRect(RectRange::HalfBorder); device_context->DrawRoundedRectangle( D2D1::RoundedRect( - Convert(GetRect(RectRange::HalfBorder)), + Convert(border_rect), border_property_->GetRadiusX(), border_property_->GetRadiusY() ), @@ -410,6 +412,7 @@ namespace cru { border_property_->GetStrokeWidth(), border_property_->GetStrokeStyle().Get() ); + } } void Control::OnDrawContent(ID2D1DeviceContext * device_context) @@ -675,7 +678,7 @@ namespace cru { if (is_bordered_) { const auto border_width = border_property_->GetStrokeWidth(); - border_size = Size(border_width, border_width); + border_size = Size(border_width * 2.0f, border_width * 2.0f); } const auto outer_size = ThicknessToSize(layout_params->padding) + @@ -723,10 +726,12 @@ namespace cru { } }; - return Size( + const auto final_size = Size( calculate_final_length(layout_params->width, size_for_children.width, actual_size_for_children.width), calculate_final_length(layout_params->height, size_for_children.height, actual_size_for_children.height) ) + outer_size; + + return final_size; } void Control::OnLayoutCore(const Rect& rect) @@ -739,12 +744,14 @@ namespace cru { border_width = border_property_->GetStrokeWidth(); } - OnLayoutContent(Rect( + const Rect content_rect( rect.left + layout_params->padding.left + layout_params->margin.right + border_width, rect.top + layout_params->padding.top + layout_params->margin.top + border_width, - rect.width - layout_params->padding.GetHorizontalTotal() - layout_params->margin.GetHorizontalTotal() + border_width * 2.0f, - rect.height - layout_params->padding.GetVerticalTotal() - layout_params->margin.GetVerticalTotal() + border_width * 2.0f - )); + rect.width - layout_params->padding.GetHorizontalTotal() - layout_params->margin.GetHorizontalTotal() - border_width * 2.0f, + rect.height - layout_params->padding.GetVerticalTotal() - layout_params->margin.GetVerticalTotal() - border_width * 2.0f + ); + + OnLayoutContent(content_rect); } Size Control::OnMeasureContent(const Size& available_size) diff --git a/src/ui/controls/linear_layout.cpp b/src/ui/controls/linear_layout.cpp index 681ed087..7921745a 100644 --- a/src/ui/controls/linear_layout.cpp +++ b/src/ui/controls/linear_layout.cpp @@ -100,7 +100,7 @@ namespace cru::ui::controls ForeachChild([this, ¤t_main_side_anchor, rect](Control* control) { const auto layout_params = control->GetLayoutParams(); - const auto size = control->GetSize(); + const auto size = control->GetDesiredSize(); const auto alignment = orientation_ == Orientation::Horizontal ? layout_params->height.alignment : layout_params->width.alignment; auto&& calculate_secondary_side_anchor = [alignment](const float layout_length, const float control_length) -> float diff --git a/src/ui/window.cpp b/src/ui/window.cpp index ca19e8ee..9edbd398 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -354,8 +354,8 @@ namespace cru void Window::Relayout() { - OnMeasureContent(GetSize()); - OnLayoutContent(Rect(Point::Zero(), GetSize())); + OnMeasureCore(GetSize()); + OnLayoutCore(Rect(Point::Zero(), GetSize())); } void Window::RefreshControlList() { |