aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/TextBox.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-03-24 19:14:19 +0800
committercrupest <crupest@outlook.com>2021-03-24 19:14:19 +0800
commit7f15a1ff9a2007e119798053083a0a87d042990a (patch)
treecb35c01a7eaee867376d959b96c9bbd15df939e5 /src/ui/controls/TextBox.cpp
parent74956951ee663012df0c3fe4ebe29799cb2f7732 (diff)
parent7703063a5816b089483e78ccd74bb9902ccfbea8 (diff)
downloadcru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.gz
cru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.bz2
cru-7f15a1ff9a2007e119798053083a0a87d042990a.zip
Merge branch 'master' of https://github.com/crupest/CruUI
Diffstat (limited to 'src/ui/controls/TextBox.cpp')
-rw-r--r--src/ui/controls/TextBox.cpp36
1 files changed, 5 insertions, 31 deletions
diff --git a/src/ui/controls/TextBox.cpp b/src/ui/controls/TextBox.cpp
index 4a8d6658..bfc98c06 100644
--- a/src/ui/controls/TextBox.cpp
+++ b/src/ui/controls/TextBox.cpp
@@ -1,6 +1,5 @@
#include "cru/ui/controls/TextBox.hpp"
-#include "TextControlService.hpp"
#include "cru/ui/UiManager.hpp"
#include "cru/ui/render/BorderRenderObject.hpp"
#include "cru/ui/render/CanvasRenderObject.hpp"
@@ -10,9 +9,7 @@
namespace cru::ui::controls {
using render::BorderRenderObject;
-using render::CanvasRenderObject;
using render::ScrollRenderObject;
-using render::StackLayoutRenderObject;
using render::TextRenderObject;
TextBox::TextBox()
@@ -20,8 +17,6 @@ TextBox::TextBox()
scroll_render_object_(new ScrollRenderObject()) {
const auto theme_resources = UiManager::GetInstance()->GetThemeResources();
- 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, theme_resources->caret_brush);
@@ -33,24 +28,15 @@ TextBox::TextBox()
scroll_render_object_->SetAttachedControl(this);
text_render_object_->SetAttachedControl(this);
text_render_object_->SetMinSize(Size{100, 24});
+ text_render_object_->SetMeasureIncludingTrailingSpace(true);
- service_ = std::make_unique<TextControlService<TextBox>>(this);
+ service_ = std::make_unique<TextHostControlService>(this);
service_->SetEnabled(true);
- service_->SetCaretVisible(true);
service_->SetEditable(true);
border_render_object_->SetBorderEnabled(true);
- border_render_object_->SetBorderStyle(border_style_.normal);
-
- GainFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) {
- this->service_->SetCaretVisible(true);
- this->UpdateBorderStyle();
- });
- LoseFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) {
- this->service_->SetCaretVisible(false);
- this->UpdateBorderStyle();
- });
+ GetStyleRuleSet()->SetParent(&theme_resources->text_box_style);
}
TextBox::~TextBox() {}
@@ -67,19 +53,7 @@ render::ScrollRenderObject* TextBox::GetScrollRenderObject() {
return scroll_render_object_.get();
}
-const TextBoxBorderStyle& TextBox::GetBorderStyle() { return border_style_; }
-
-void TextBox::SetBorderStyle(TextBoxBorderStyle border_style) {
- border_style_ = std::move(border_style);
-}
-
-void TextBox::OnMouseHoverChange(bool) { UpdateBorderStyle(); }
-
-void TextBox::UpdateBorderStyle() {
- const auto focus = HasFocus();
- const auto hover = IsMouseOver();
- border_render_object_->SetBorderStyle(
- focus ? (hover ? border_style_.focus_hover : border_style_.focus)
- : (hover ? border_style_.hover : border_style_.normal));
+void TextBox::ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) {
+ border_render_object_->ApplyBorderStyle(style);
}
} // namespace cru::ui::controls