aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp12
-rw-r--r--src/ui/controls/border.cpp58
-rw-r--r--src/ui/controls/border.h85
-rw-r--r--src/ui/controls/text_control.cpp2
4 files changed, 154 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 67b35406..4f711208 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,13 +1,13 @@
#include "application.h"
#include "ui/window.h"
+#include "ui/events/ui_event.h"
#include "ui/controls/linear_layout.h"
#include "ui/controls/text_block.h"
#include "ui/controls/toggle_button.h"
#include "ui/controls/button.h"
#include "ui/controls/margin_container.h"
-#include "ui/events/ui_event.h"
#include "ui/controls/text_box.h"
-
+#include "ui/controls/border.h"
using cru::String;
using cru::Application;
@@ -22,6 +22,7 @@ using cru::ui::controls::ToggleButton;
using cru::ui::controls::Button;
using cru::ui::controls::MarginContainer;
using cru::ui::controls::TextBox;
+using cru::ui::controls::Border;
int APIENTRY wWinMain(
HINSTANCE hInstance,
@@ -142,7 +143,12 @@ int APIENTRY wWinMain(
window.AddChild(layout);
*/
- window.AddChild(CreateWithLayout<TextBox>(LayoutSideParams::Stretch(), LayoutSideParams::Stretch()));
+ window.AddChild(
+ CreateWithLayout<Border>(LayoutSideParams::Exactly(200), LayoutSideParams::Content(),
+ std::initializer_list<cru::ui::Control*>{
+ CreateWithLayout<TextBox>(LayoutSideParams::Stretch(), LayoutSideParams::Content())
+ }
+ ));
window.Show();
diff --git a/src/ui/controls/border.cpp b/src/ui/controls/border.cpp
new file mode 100644
index 00000000..f79d610f
--- /dev/null
+++ b/src/ui/controls/border.cpp
@@ -0,0 +1,58 @@
+#include "border.h"
+
+#include "graph/graph.h"
+
+namespace cru::ui::controls
+{
+ using graph::CreateSolidBrush;
+
+ Border::Border() : Control(true)
+ {
+ 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)
+ {
+ border_stroke_style_ = std::move(stroke_style);
+ Repaint();
+ }
+
+ void Border::SetBorderRadiusX(const float border_radius_x)
+ {
+ border_radius_x_ = border_radius_x;
+ Repaint();
+ }
+
+ void Border::SetBorderRadiusY(const float border_radius_y)
+ {
+ border_radius_y_ = border_radius_y;
+ Repaint();
+ }
+
+ void Border::OnDraw(ID2D1DeviceContext* device_context)
+ {
+ 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());
+ }
+ }
+}
diff --git a/src/ui/controls/border.h b/src/ui/controls/border.h
new file mode 100644
index 00000000..74e12c92
--- /dev/null
+++ b/src/ui/controls/border.h
@@ -0,0 +1,85 @@
+#pragma once
+
+#include <initializer_list>
+
+#include "ui/control.h"
+
+namespace cru::ui::controls
+{
+ class Border : public Control
+ {
+ public:
+ static Border* Create(const std::initializer_list<Control*>& children = std::initializer_list<Control*>())
+ {
+ const auto border = new Border();
+ for (const auto control : children)
+ border->AddChild(control);
+ return border;
+ }
+
+ protected:
+ Border();
+
+ public:
+ Border(const Border& other) = delete;
+ Border(Border&& other) = delete;
+ Border& operator=(const Border& other) = delete;
+ Border& operator=(Border&& other) = delete;
+ ~Border() override = default;
+
+ bool IsDrawBorder() const
+ {
+ return draw_border_;
+ }
+
+ void SetDrawBorder(bool draw_border);
+
+ Microsoft::WRL::ComPtr<ID2D1Brush> GetBorderBrush() const
+ {
+ return border_brush_;
+ }
+
+ 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;
+
+ 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;
+ };
+}
diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp
index 845b090a..692c4451 100644
--- a/src/ui/controls/text_control.cpp
+++ b/src/ui/controls/text_control.cpp
@@ -267,6 +267,8 @@ namespace cru::ui::controls
void TextControl::OnTextChangedCore(const String& old_text, const String& new_text)
{
RecreateTextLayout();
+ if (const auto window = GetWindow())
+ window->Relayout();
Repaint();
}