aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/border.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@outlook.com>2018-10-01 17:11:11 +0000
committerYuqian Yang <crupest@outlook.com>2018-10-01 17:11:11 +0000
commit30ecda8bb354d5982978af97aa90b5f49d9ea195 (patch)
treea271bddb244fa2041f14f8d46d249457cee09e5f /src/ui/controls/border.cpp
parent398b8f3ba535bb43c4b8593e3027c14894a7a211 (diff)
parent040a6c18f18100b825a56443a73aa1de64e4518c (diff)
downloadcru-30ecda8bb354d5982978af97aa90b5f49d9ea195.tar.gz
cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.tar.bz2
cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.zip
Merge branch '9-border' into 'master'
Resolve "Abstract out border control of button and border." Closes #9 See merge request crupest/CruUI!11
Diffstat (limited to 'src/ui/controls/border.cpp')
-rw-r--r--src/ui/controls/border.cpp45
1 files changed, 12 insertions, 33 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());
}
}