diff options
author | crupest <crupest@outlook.com> | 2020-03-19 19:45:26 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-03-19 19:45:26 +0800 |
commit | 507de8c6a931d0784c8f740d41db610d3ed8db68 (patch) | |
tree | 9f77d8e2b1b0955ff669677b4d5913a08075946a /src/ui/controls/text_box.cpp | |
parent | 5da4f511e85de9e79bee40e3c5e04f899a48723c (diff) | |
download | cru-507de8c6a931d0784c8f740d41db610d3ed8db68.tar.gz cru-507de8c6a931d0784c8f740d41db610d3ed8db68.tar.bz2 cru-507de8c6a931d0784c8f740d41db610d3ed8db68.zip |
...
Diffstat (limited to 'src/ui/controls/text_box.cpp')
-rw-r--r-- | src/ui/controls/text_box.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp index 1e0890b8..99164b9b 100644 --- a/src/ui/controls/text_box.cpp +++ b/src/ui/controls/text_box.cpp @@ -36,6 +36,16 @@ TextBox::TextBox() stack_layout_render_object_->SetAttachedControl(this); text_render_object_->SetAttachedControl(this); caret_render_object_->SetAttachedControl(this); + + GainFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) { + this->service_->SetEnabled(true); + this->UpdateBorderStyle(); + }); + + LoseFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) { + this->service_->SetEnabled(false); + this->UpdateBorderStyle(); + }); } TextBox::~TextBox() {} @@ -55,6 +65,16 @@ std::shared_ptr<platform::graph::IBrush> TextBox::GetCaretBrush() { const TextBoxBorderStyle& TextBox::GetBorderStyle() { return border_style_; } void TextBox::SetBorderStyle(TextBoxBorderStyle border_style) { - border_style_ = std::move(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)); } } // namespace cru::ui::controls |