From 01ab4511d3006e9f65ff96ae63b21de14b41bc48 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 4 Oct 2018 01:47:49 +0800 Subject: ... --- src/ui/window.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ui/window.cpp') diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 39528550..5e0dd694 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -354,8 +354,8 @@ namespace cru void Window::Relayout() { - OnMeasure(GetSize()); - OnLayout(Rect(Point::Zero(), GetSize())); + OnMeasureContent(GetSize()); + OnLayoutContent(Rect(Point::Zero(), GetSize())); } void Window::RefreshControlList() { @@ -462,7 +462,7 @@ namespace cru return ::PeekMessageW(&msg, hwnd_, message, message, PM_NOREMOVE) != 0; } - Size Window::OnMeasure(const Size& available_size) + Size Window::OnMeasureContent(const Size& available_size) { ForeachChild([available_size](Control* control) { -- cgit v1.2.3 From 4312df1a13b182ed3f00838b5300a8f848f6c2fa Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 5 Oct 2018 00:00:19 +0800 Subject: Only relayout window when new size is not zero. --- src/ui/window.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/ui/window.cpp') diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 5e0dd694..ca19e8ee 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -498,9 +498,10 @@ namespace cru ValidateRect(hwnd_, nullptr); } - void Window::OnResizeInternal(int new_width, int new_height) { + void Window::OnResizeInternal(const int new_width, const int new_height) { render_target_->ResizeBuffer(new_width, new_height); - Relayout(); + if (!(new_width == 0 && new_height == 0)) + Relayout(); } void Window::OnSetFocusInternal() -- cgit v1.2.3 From c5384d496e9ed429ca2baa3ca5e586ff255235eb Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 5 Oct 2018 00:50:38 +0800 Subject: Fix several headache bugs. --- src/ui/control.cpp | 23 +++++++++++++++-------- src/ui/controls/linear_layout.cpp | 2 +- src/ui/window.cpp | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) (limited to 'src/ui/window.cpp') 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() { -- cgit v1.2.3