diff options
author | crupest <crupest@outlook.com> | 2018-09-13 00:14:59 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-13 00:14:59 +0800 |
commit | 5f35ba198582bb93e16d34c8d94ffdc8f453068d (patch) | |
tree | 9ac9865ff3f058d688240abff8b7a44c876dd32a /CruUI/ui/controls/text_block.cpp | |
parent | bbcd0257150d967bdccd3ab89c100d02bd7a23d3 (diff) | |
download | cru-5f35ba198582bb93e16d34c8d94ffdc8f453068d.tar.gz cru-5f35ba198582bb93e16d34c8d94ffdc8f453068d.tar.bz2 cru-5f35ba198582bb93e16d34c8d94ffdc8f453068d.zip |
...
Diffstat (limited to 'CruUI/ui/controls/text_block.cpp')
-rw-r--r-- | CruUI/ui/controls/text_block.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp index c528d3ca..132bd3e7 100644 --- a/CruUI/ui/controls/text_block.cpp +++ b/CruUI/ui/controls/text_block.cpp @@ -111,6 +111,7 @@ namespace cru { if (args.GetMouseButton() == MouseButton::Left) { + RequestFocus(); const auto hit_test_result = TextLayoutHitTest(text_layout_.Get(), args.GetPoint(this), true); if (hit_test_result.has_value()) { @@ -118,6 +119,10 @@ namespace cru is_selecting_ = true; GetWindow()->CaptureMouseFor(this); } + else + { + selected_range_ = std::nullopt; + } } Control::OnMouseDownCore(args); } @@ -126,13 +131,17 @@ namespace cru { if (is_selecting_) { + is_mouse_moved_ = true; const auto hit_test_result = TextLayoutHitTest(text_layout_.Get(), args.GetPoint(this), false).value(); if (hit_test_result > mouse_down_position_) selected_range_ = TextRange(mouse_down_position_, hit_test_result - mouse_down_position_); - else + else if (hit_test_result < mouse_down_position_) selected_range_ = TextRange(hit_test_result, mouse_down_position_ - hit_test_result); + else + selected_range_ = std::nullopt; Repaint(); } + Control::OnMouseMoveCore(args); } void TextBlock::OnMouseUpCore(events::MouseButtonEventArgs& args) @@ -141,10 +150,24 @@ namespace cru { if (is_selecting_) { + if (!is_mouse_moved_) + { + selected_range_ = std::nullopt; + Repaint(); + } + is_mouse_moved_ = false; is_selecting_ = false; GetWindow()->ReleaseCurrentMouseCapture(); } } + Control::OnMouseUpCore(args); + } + + void TextBlock::OnLoseFocusCore(events::UiEventArgs& args) + { + selected_range_ = std::nullopt; + Repaint(); + Control::OnLoseFocusCore(args); } Size TextBlock::OnMeasure(const Size& available_size) |