From 507de8c6a931d0784c8f740d41db610d3ed8db68 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 19 Mar 2020 19:45:26 +0800 Subject: ... --- src/ui/controls/text_box.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/ui/controls/text_box.cpp') 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 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 -- cgit v1.2.3