aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/controls/text_block.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-21 22:53:12 +0800
committercrupest <crupest@outlook.com>2018-09-21 22:53:12 +0800
commit82a45e611a2638cff7e3fffc09ba4569ca53a274 (patch)
tree69d6eb024b9aa35949761d6e75df28717ff02e35 /CruUI/ui/controls/text_block.cpp
parent5f7d3268e3d2ea84a1afc97c209b703bf4092c76 (diff)
downloadcru-82a45e611a2638cff7e3fffc09ba4569ca53a274.tar.gz
cru-82a45e611a2638cff7e3fffc09ba4569ca53a274.tar.bz2
cru-82a45e611a2638cff7e3fffc09ba4569ca53a274.zip
Add selectable switch in text block.
Diffstat (limited to 'CruUI/ui/controls/text_block.cpp')
-rw-r--r--CruUI/ui/controls/text_block.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp
index 5fabb3f4..45f0d574 100644
--- a/CruUI/ui/controls/text_block.cpp
+++ b/CruUI/ui/controls/text_block.cpp
@@ -65,6 +65,26 @@ namespace cru
text_layout_handlers_.erase(find_result);
}
+ void TextBlock::SetSelectable(const bool is_selectable)
+ {
+ if (!is_selectable)
+ {
+ is_selecting_ = false;
+ selected_range_ = std::nullopt;
+ Repaint();
+ }
+ is_selectable_ = is_selectable;
+ }
+
+ void TextBlock::SetSelectedRange(std::optional<TextRange> text_range)
+ {
+ if (is_selectable_)
+ {
+ selected_range_ = text_range;
+ Repaint();
+ }
+ }
+
void TextBlock::OnSizeChangedCore(events::SizeChangedEventArgs& args)
{
Control::OnSizeChangedCore(args);
@@ -117,7 +137,7 @@ namespace cru
void TextBlock::OnMouseDownCore(events::MouseButtonEventArgs& args)
{
Control::OnMouseDownCore(args);
- if (args.GetMouseButton() == MouseButton::Left)
+ if (is_selectable_ && args.GetMouseButton() == MouseButton::Left)
{
RequestFocus();
selected_range_ = std::nullopt;