aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/controls
diff options
context:
space:
mode:
Diffstat (limited to 'CruUI/ui/controls')
-rw-r--r--CruUI/ui/controls/text_block.cpp25
-rw-r--r--CruUI/ui/controls/text_block.h3
2 files changed, 27 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)
diff --git a/CruUI/ui/controls/text_block.h b/CruUI/ui/controls/text_block.h
index 1d1166a5..c817104e 100644
--- a/CruUI/ui/controls/text_block.h
+++ b/CruUI/ui/controls/text_block.h
@@ -104,6 +104,8 @@ namespace cru
void OnMouseMoveCore(events::MouseEventArgs& args) override;
void OnMouseUpCore(events::MouseButtonEventArgs& args) override;
+ void OnLoseFocusCore(events::UiEventArgs& args) override;
+
Size OnMeasure(const Size& available_size) override;
private:
@@ -124,6 +126,7 @@ namespace cru
Vector<std::shared_ptr<TextLayoutHandler>> text_layout_handlers_;
unsigned mouse_down_position_ = 0;
+ bool is_mouse_moved_ = false;
std::optional<TextRange> selected_range_ = std::nullopt;
bool is_selecting_ = false;