aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/text_box.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-05 20:54:48 +0800
committercrupest <crupest@outlook.com>2018-11-05 20:54:48 +0800
commit1dab244aaad8694ba37ef43caedd8c8ba0310c00 (patch)
treef70f6489a0f88520a0bdc095cd9713d03f83687b /src/ui/controls/text_box.cpp
parent252519effe30881825dd02e26dc41bd9cde34782 (diff)
downloadcru-1dab244aaad8694ba37ef43caedd8c8ba0310c00.tar.gz
cru-1dab244aaad8694ba37ef43caedd8c8ba0310c00.tar.bz2
cru-1dab244aaad8694ba37ef43caedd8c8ba0310c00.zip
...
Diffstat (limited to 'src/ui/controls/text_box.cpp')
-rw-r--r--src/ui/controls/text_box.cpp19
1 files changed, 9 insertions, 10 deletions
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 <cwctype>
+#include <cassert>
#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;
}