diff options
author | crupest <crupest@outlook.com> | 2020-03-19 19:11:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-03-19 19:11:33 +0800 |
commit | 5da4f511e85de9e79bee40e3c5e04f899a48723c (patch) | |
tree | 8c07925417fc1f062bb6f4ec64dc9226199e6099 /src | |
parent | ad29543fe081d2a0a5e6737f9073399e4e91383f (diff) | |
download | cru-5da4f511e85de9e79bee40e3c5e04f899a48723c.tar.gz cru-5da4f511e85de9e79bee40e3c5e04f899a48723c.tar.bz2 cru-5da4f511e85de9e79bee40e3c5e04f899a48723c.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/ui/controls/text_block.cpp | 4 | ||||
-rw-r--r-- | src/ui/controls/text_box.cpp | 25 | ||||
-rw-r--r-- | src/ui/controls/text_control_service.hpp | 4 | ||||
-rw-r--r-- | src/ui/ui_manager.cpp | 16 |
5 files changed, 45 insertions, 5 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 029fab9d..e132f3df 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -38,6 +38,7 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/ui_event.hpp ${CRU_UI_INCLUDE_DIR}/ui_manager.hpp ${CRU_UI_INCLUDE_DIR}/window.hpp + ${CRU_UI_INCLUDE_DIR}/controls/base.hpp ${CRU_UI_INCLUDE_DIR}/controls/button.hpp ${CRU_UI_INCLUDE_DIR}/controls/container.hpp ${CRU_UI_INCLUDE_DIR}/controls/flex_layout.hpp 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()); } } diff --git a/src/ui/ui_manager.cpp b/src/ui/ui_manager.cpp index 5c7e4577..905d29ad 100644 --- a/src/ui/ui_manager.cpp +++ b/src/ui/ui_manager.cpp @@ -59,6 +59,22 @@ UiManager::UiManager() { theme_resource_.button_style.press.border_radius = theme_resource_.button_style.press_cancel.border_radius = CornerRadius({5, 5}); + + theme_resource_.text_box_border_style.normal.border_brush = + CreateSolidColorBrush(factory, Color::FromHex(0xced4da)); + theme_resource_.text_box_border_style.normal.border_radius = CornerRadius(5); + theme_resource_.text_box_border_style.normal.border_thickness = Thickness(1); + + theme_resource_.text_box_border_style.hover = + theme_resource_.text_box_border_style.normal; + + theme_resource_.text_box_border_style.normal.border_brush = + CreateSolidColorBrush(factory, Color::FromHex(0x495057)); + theme_resource_.text_box_border_style.normal.border_radius = CornerRadius(5); + theme_resource_.text_box_border_style.normal.border_thickness = Thickness(1); + + theme_resource_.text_box_border_style.focus_hover = + theme_resource_.text_box_border_style.focus; } UiManager::~UiManager() = default; |