diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/control.cpp | 38 | ||||
-rw-r--r-- | src/ui/control.h | 5 | ||||
-rw-r--r-- | src/ui/controls/text_control.cpp | 3 | ||||
-rw-r--r-- | src/ui/window.cpp | 10 | ||||
-rw-r--r-- | src/ui/window.h | 12 |
5 files changed, 49 insertions, 19 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 4acdd8f1..3aa8c7e2 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -2,6 +2,7 @@ #include "window.h" #include "graph/graph.h" +#include "exception.h" namespace cru { namespace ui { @@ -390,12 +391,15 @@ namespace cru { void Control::OnDraw(ID2D1DeviceContext* device_context) { -#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER - if (GetWindow()->GetDebugDrawControlBorder()) +#ifdef CRU_DEBUG_LAYOUT + if (GetWindow()->IsDebugLayout()) { - auto brush = Application::GetInstance()->GetDebugBorderBrush(); - const auto size = GetSize(); - device_context->DrawRectangle(Convert(GetRect(RectRange::Margin)), brush.Get()); + const auto resource = Application::GetInstance()->GetDebugLayoutResource(); + if (padding_geometry_ != nullptr) + device_context->FillGeometry(padding_geometry_.Get(), resource->padding_brush.Get()); + if (margin_geometry_ != nullptr) + device_context->FillGeometry(margin_geometry_.Get(), resource->margin_brush.Get()); + device_context->DrawRectangle(Convert(GetRect(RectRange::Margin)), resource->out_border_brush.Get()); } #endif @@ -434,9 +438,31 @@ namespace cru { } - void Control::OnSizeChangedCore(SizeChangedEventArgs & args) + namespace { + Microsoft::WRL::ComPtr<ID2D1Geometry> CalculateSquareRingGeometry(const Rect& out, const Rect& in) + { + const auto d2d1_factory = graph::GraphManager::GetInstance()->GetD2D1Factory(); + Microsoft::WRL::ComPtr<ID2D1RectangleGeometry> out_geometry; + ThrowIfFailed(d2d1_factory->CreateRectangleGeometry(Convert(out), &out_geometry)); + Microsoft::WRL::ComPtr<ID2D1RectangleGeometry> in_geometry; + ThrowIfFailed(d2d1_factory->CreateRectangleGeometry(Convert(in), &in_geometry)); + Microsoft::WRL::ComPtr<ID2D1PathGeometry> result_geometry; + ThrowIfFailed(d2d1_factory->CreatePathGeometry(&result_geometry)); + Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink; + ThrowIfFailed(result_geometry->Open(&sink)); + ThrowIfFailed(out_geometry->CombineWithGeometry(in_geometry.Get(), D2D1_COMBINE_MODE_EXCLUDE, D2D1::Matrix3x2F::Identity(), sink.Get())); + ThrowIfFailed(sink->Close()); + return result_geometry; + } + } + void Control::OnSizeChangedCore(SizeChangedEventArgs & args) + { +#ifdef CRU_DEBUG_LAYOUT + margin_geometry_ = CalculateSquareRingGeometry(GetRect(RectRange::Margin), GetRect(RectRange::FullBorder)); + padding_geometry_ = CalculateSquareRingGeometry(GetRect(RectRange::Padding), GetRect(RectRange::Content)); +#endif } void Control::RaisePositionChangedEvent(PositionChangedEventArgs& args) diff --git a/src/ui/control.h b/src/ui/control.h index 18ca4b69..b2321e2b 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -399,6 +399,11 @@ namespace cru std::unordered_map<String, std::any> additional_properties_{}; bool is_focus_on_pressed_ = true; + +#ifdef CRU_DEBUG_LAYOUT + Microsoft::WRL::ComPtr<ID2D1Geometry> margin_geometry_; + Microsoft::WRL::ComPtr<ID2D1Geometry> padding_geometry_; +#endif }; // Find the lowest common ancestor. diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp index da0113f3..ee5b253d 100644 --- a/src/ui/controls/text_control.cpp +++ b/src/ui/controls/text_control.cpp @@ -229,8 +229,7 @@ namespace cru::ui::controls void TextControl::OnTextChangedCore(const String& old_text, const String& new_text) { RecreateTextLayout(); - if (const auto window = GetWindow()) - window->Relayout(); + InvalidateLayout(); Repaint(); } diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 9edbd398..8889e032 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -439,12 +439,12 @@ namespace cru } } -#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER - void Window::SetDebugDrawControlBorder(const bool value) +#ifdef CRU_DEBUG_LAYOUT + void Window::SetDebugLayout(const bool value) { - if (debug_draw_control_border_ != value) + if (debug_layout_ != value) { - debug_draw_control_border_ = value; + debug_layout_ = value; Repaint(); } } @@ -501,7 +501,7 @@ namespace cru void Window::OnResizeInternal(const int new_width, const int new_height) { render_target_->ResizeBuffer(new_width, new_height); if (!(new_width == 0 && new_height == 0)) - Relayout(); + InvalidateLayout(); } void Window::OnSetFocusInternal() diff --git a/src/ui/window.h b/src/ui/window.h index b4433e85..e4e89776 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -184,13 +184,13 @@ namespace cru { Control* ReleaseCurrentMouseCapture(); //*************** region: debug *************** -#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER - bool GetDebugDrawControlBorder() const +#ifdef CRU_DEBUG_LAYOUT + bool IsDebugLayout() const { - return debug_draw_control_border_; + return debug_layout_; } - void SetDebugDrawControlBorder(bool value); + void SetDebugLayout(bool value); #endif public: @@ -276,8 +276,8 @@ namespace cru { Control* mouse_capture_control_ = nullptr; -#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER - bool debug_draw_control_border_ = false; +#ifdef CRU_DEBUG_LAYOUT + bool debug_layout_ = false; #endif }; } |