aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/controls/text_block.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-13 00:14:59 +0800
committercrupest <crupest@outlook.com>2018-09-13 00:14:59 +0800
commit5f35ba198582bb93e16d34c8d94ffdc8f453068d (patch)
tree9ac9865ff3f058d688240abff8b7a44c876dd32a /CruUI/ui/controls/text_block.cpp
parentbbcd0257150d967bdccd3ab89c100d02bd7a23d3 (diff)
downloadcru-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.cpp25
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)