From 1dab244aaad8694ba37ef43caedd8c8ba0310c00 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 5 Nov 2018 20:54:48 +0800 Subject: ... --- src/ui/controls/text_box.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (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 54b2f7ab..d6c3d132 100644 --- a/src/ui/controls/text_box.cpp +++ b/src/ui/controls/text_box.cpp @@ -1,6 +1,7 @@ #include "text_box.h" #include +#include #include "graph/graph.h" #include "exception.h" @@ -21,12 +22,6 @@ namespace cru::ui::controls caret_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)); - caret_action_ = CreateActionPtr([this] - { - is_caret_show_ = !is_caret_show_; - Repaint(); - }); - SetBordered(true); } @@ -48,17 +43,21 @@ namespace cru::ui::controls void TextBox::OnGetFocusCore(events::FocusChangeEventArgs& args) { TextControl::OnGetFocusCore(args); - assert(caret_timer_ == nullptr); + assert(!caret_timer_.has_value()); is_caret_show_ = true; - caret_timer_ = SetInterval(Application::GetInstance()->GetCaretInfo().caret_blink_duration, caret_action_); + caret_timer_ = SetInterval(Application::GetInstance()->GetCaretInfo().caret_blink_duration, [this] + { + is_caret_show_ = !is_caret_show_; + Repaint(); + }); } void TextBox::OnLoseFocusCore(events::FocusChangeEventArgs& args) { Control::OnLoseFocusCore(args); - assert(caret_timer_ != nullptr); + assert(caret_timer_.has_value()); caret_timer_->Cancel(); - caret_timer_ = nullptr; + caret_timer_ = std::nullopt; is_caret_show_ = false; } -- cgit v1.2.3