aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-03-19 19:11:33 +0800
committercrupest <crupest@outlook.com>2020-03-19 19:11:33 +0800
commit5da4f511e85de9e79bee40e3c5e04f899a48723c (patch)
tree8c07925417fc1f062bb6f4ec64dc9226199e6099 /src/ui/controls
parentad29543fe081d2a0a5e6737f9073399e4e91383f (diff)
downloadcru-5da4f511e85de9e79bee40e3c5e04f899a48723c.tar.gz
cru-5da4f511e85de9e79bee40e3c5e04f899a48723c.tar.bz2
cru-5da4f511e85de9e79bee40e3c5e04f899a48723c.zip
...
Diffstat (limited to 'src/ui/controls')
-rw-r--r--src/ui/controls/text_block.cpp4
-rw-r--r--src/ui/controls/text_box.cpp25
-rw-r--r--src/ui/controls/text_control_service.hpp4
3 files changed, 28 insertions, 5 deletions
diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp
index 0a243d2e..1c20540d 100644
--- a/src/ui/controls/text_block.cpp
+++ b/src/ui/controls/text_block.cpp
@@ -56,7 +56,7 @@ render::CanvasRenderObject* TextBlock::GetCaretRenderObject() {
return caret_render_object_.get();
}
-platform::graph::IBrush* TextBlock::GetCaretBrush() {
- return caret_brush_.get();
+std::shared_ptr<platform::graph::IBrush> TextBlock::GetCaretBrush() {
+ return caret_brush_;
}
} // namespace cru::ui::controls
diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp
index 9c6fcbe5..1e0890b8 100644
--- a/src/ui/controls/text_box.cpp
+++ b/src/ui/controls/text_box.cpp
@@ -5,6 +5,7 @@
#include "cru/ui/render/stack_layout_render_object.hpp"
#include "cru/ui/render/text_render_object.hpp"
#include "cru/ui/ui_manager.hpp"
+#include "text_control_service.hpp"
namespace cru::ui::controls {
using render::BorderRenderObject;
@@ -16,9 +17,13 @@ TextBox::TextBox()
: border_render_object_(new BorderRenderObject()),
stack_layout_render_object_(new StackLayoutRenderObject()),
text_render_object_(),
- caret_render_object_(new CanvasRenderObject()) {
+ caret_render_object_(new CanvasRenderObject()),
+ service_(new TextControlService<TextBox>(this)) {
const auto theme_resources = UiManager::GetInstance()->GetThemeResources();
+ caret_brush_ = theme_resources->caret_brush;
+ border_style_ = theme_resources->text_box_border_style;
+
text_render_object_ = std::make_unique<TextRenderObject>(
theme_resources->text_brush, theme_resources->default_font,
theme_resources->text_selection_brush);
@@ -34,4 +39,22 @@ TextBox::TextBox()
}
TextBox::~TextBox() {}
+
+render::TextRenderObject* TextBox::GetTextRenderObject() {
+ return text_render_object_.get();
+}
+
+render::CanvasRenderObject* TextBox::GetCaretRenderObject() {
+ return caret_render_object_.get();
+}
+
+std::shared_ptr<platform::graph::IBrush> TextBox::GetCaretBrush() {
+ return caret_brush_;
+}
+
+const TextBoxBorderStyle& TextBox::GetBorderStyle() { return border_style_; }
+
+void TextBox::SetBorderStyle(TextBoxBorderStyle border_style) {
+ border_style_ = std::move(border_style_);
+}
} // namespace cru::ui::controls
diff --git a/src/ui/controls/text_control_service.hpp b/src/ui/controls/text_control_service.hpp
index 3885242a..d4f3ecf9 100644
--- a/src/ui/controls/text_control_service.hpp
+++ b/src/ui/controls/text_control_service.hpp
@@ -16,7 +16,7 @@ constexpr long long caret_blink_duration = 500;
// ```
// render::TextRenderObject* GetTextRenderObject();
// render::CanvasRenderObject* GetCaretRenderObject();
-// platform::graph::IBrush* GetCaretBrush();
+// std::shared_ptr<platform::graph::IBrush> GetCaretBrush();
// ```
template <typename TControl>
class TextControlService : public Object {
@@ -125,7 +125,7 @@ void TextControlService<TControl>::DrawCaret(
painter->FillRectangle(
Rect{point,
Size{caret_width, text_render_object->GetFont()->GetFontSize()}},
- control_->GetCaretBrush());
+ control_->GetCaretBrush().get());
}
}