diff options
author | crupest <crupest@outlook.com> | 2018-10-02 00:39:16 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-10-02 00:39:16 +0800 |
commit | a3b78397f71c35e51681104b572de06a1780e4ee (patch) | |
tree | 6a73d60c5a44dd43133f328b443a3df7e12351d3 | |
parent | f55a20fd3bad952481339d47ff844ad816192f50 (diff) | |
download | cru-a3b78397f71c35e51681104b572de06a1780e4ee.tar.gz cru-a3b78397f71c35e51681104b572de06a1780e4ee.tar.bz2 cru-a3b78397f71c35e51681104b572de06a1780e4ee.zip |
Make border use border delegate.
-rw-r--r-- | src/ui/controls/border.cpp | 45 | ||||
-rw-r--r-- | src/ui/controls/border.h | 45 |
2 files changed, 19 insertions, 71 deletions
diff --git a/src/ui/controls/border.cpp b/src/ui/controls/border.cpp index f79d610f..1caed91d 100644 --- a/src/ui/controls/border.cpp +++ b/src/ui/controls/border.cpp @@ -6,53 +6,32 @@ namespace cru::ui::controls { using graph::CreateSolidBrush; - Border::Border() : Control(true) + Border::Border() : Control(true), border_delegate_(this) { - border_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)); - } - - void Border::SetDrawBorder(bool draw_border) - { - draw_border_ = draw_border; - Repaint(); - } - void Border::SetBorderBrush(Microsoft::WRL::ComPtr<ID2D1Brush> border_brush) - { - border_brush_ = std::move(border_brush); - Repaint(); - } - - void Border::SetBorderWidth(const float border_width) - { - border_width_ = border_width; - Repaint(); } - void Border::SetBorderStrokeStyle(Microsoft::WRL::ComPtr<ID2D1StrokeStyle> stroke_style) + void Border::SetDrawBorder(const bool draw_border) { - border_stroke_style_ = std::move(stroke_style); + draw_border_ = draw_border; Repaint(); } - void Border::SetBorderRadiusX(const float border_radius_x) + void Border::OnDraw(ID2D1DeviceContext* device_context) { - border_radius_x_ = border_radius_x; - Repaint(); + if (draw_border_) + { + border_delegate_.Draw(device_context, GetSize()); + } } - void Border::SetBorderRadiusY(const float border_radius_y) + Size Border::OnMeasure(const Size& available_size) { - border_radius_y_ = border_radius_y; - Repaint(); + return Control::DefaultMeasureWithPadding(available_size, border_delegate_.GetBorderThickness()); } - void Border::OnDraw(ID2D1DeviceContext* device_context) + void Border::OnLayout(const Rect& rect) { - if (draw_border_) - { - const auto size = GetSize(); - device_context->DrawRoundedRectangle(D2D1::RoundedRect(D2D1::RectF(0.0f, 0.0f, size.width, size.height), border_radius_x_, border_radius_y_), border_brush_.Get(), border_width_, border_stroke_style_.Get()); - } + Control::DefaultLayoutWithPadding(rect, border_delegate_.GetBorderThickness()); } } diff --git a/src/ui/controls/border.h b/src/ui/controls/border.h index 74e12c92..7880e690 100644 --- a/src/ui/controls/border.h +++ b/src/ui/controls/border.h @@ -3,6 +3,7 @@ #include <initializer_list> #include "ui/control.h" +#include "border_delegate.h" namespace cru::ui::controls { @@ -34,52 +35,20 @@ namespace cru::ui::controls void SetDrawBorder(bool draw_border); - Microsoft::WRL::ComPtr<ID2D1Brush> GetBorderBrush() const + BorderProperty::Ptr GetBorderProperty() const { - return border_brush_; + return border_delegate_.GetBorderProperty(); } - void SetBorderBrush(Microsoft::WRL::ComPtr<ID2D1Brush> border_brush); - - float GetBorderWidth() const - { - return border_width_; - } - - void SetBorderWidth(float border_width); - - Microsoft::WRL::ComPtr<ID2D1StrokeStyle> GetBorderStrokeStyle() const - { - return border_stroke_style_; - } - - void SetBorderStrokeStyle(Microsoft::WRL::ComPtr<ID2D1StrokeStyle> stroke_style); - - float GetBorderRadiusX() const - { - return border_radius_x_; - } - - void SetBorderRadiusX(float border_radius_x); - - float GetBorderRadiusY() const - { - return border_radius_y_; - } - - void SetBorderRadiusY(float border_radius_y); - protected: void OnDraw(ID2D1DeviceContext* device_context) override; + Size OnMeasure(const Size& available_size) override; + void OnLayout(const Rect& rect) override; + private: bool draw_border_ = true; - Microsoft::WRL::ComPtr<ID2D1Brush> border_brush_; - float border_width_ = 1.0f; - Microsoft::WRL::ComPtr<ID2D1StrokeStyle> border_stroke_style_ = nullptr; - - float border_radius_x_ = 0.0f; - float border_radius_y_ = 0.0f; + BorderDelegate border_delegate_; }; } |