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.cpp22
-rw-r--r--CruUI/ui/controls/text_block.h34
2 files changed, 52 insertions, 4 deletions
diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp
index 60f8a1c1..739cd793 100644
--- a/CruUI/ui/controls/text_block.cpp
+++ b/CruUI/ui/controls/text_block.cpp
@@ -65,6 +65,22 @@ namespace cru
device_context->DrawTextLayout(D2D1::Point2F(), text_layout_.Get(), brush_.Get());
}
+ void TextBlock::OnMouseDownCore(events::MouseButtonEventArgs& args)
+ {
+ if (args.GetMouseButton() == MouseButton::Left)
+ {
+ BOOL is_trailing, is_inside;
+ DWRITE_HIT_TEST_METRICS metrics;
+ text_layout_->HitTestPoint(args.GetPoint(this).x, args.GetPoint(this).y, &is_trailing, &is_inside, &metrics);
+ if (is_inside)
+ {
+ mouse_down_position_ = is_trailing == 0 ? metrics.textPosition : metrics.textPosition + 1;
+ is_mouse_down_ = true;
+ }
+ }
+ Control::OnMouseDownCore(args);
+ }
+
Size TextBlock::OnMeasure(const Size& available_size)
{
if (text_.empty())
@@ -75,8 +91,6 @@ namespace cru
if (layout_params->width.mode == MeasureMode::Stretch && layout_params->height.mode == MeasureMode::Stretch)
return available_size;
- Size measure_size; // NOLINT(cppcoreguidelines-pro-type-member-init)
-
auto&& get_measure_length = [](const MeasureLength& layout_length, const float available_length) -> float
{
switch (layout_length.mode)
@@ -95,8 +109,8 @@ namespace cru
}
};
- measure_size.width = get_measure_length(layout_params->width, available_size.width);
- measure_size.height = get_measure_length(layout_params->height, available_size.height);
+ const Size measure_size(get_measure_length(layout_params->width, available_size.width),
+ get_measure_length(layout_params->height, available_size.height));
ThrowIfFailed(text_layout_->SetMaxWidth(measure_size.width));
ThrowIfFailed(text_layout_->SetMaxHeight(measure_size.height));
diff --git a/CruUI/ui/controls/text_block.h b/CruUI/ui/controls/text_block.h
index 04347a0c..d6d173ba 100644
--- a/CruUI/ui/controls/text_block.h
+++ b/CruUI/ui/controls/text_block.h
@@ -10,6 +10,32 @@ namespace cru
{
namespace controls
{
+ struct TextRange
+ {
+ TextRange() = default;
+ TextRange(const int position, const int count)
+ : position(position), count(count)
+ {
+
+ }
+ TextRange(const TextRange& other) = default;
+ TextRange(TextRange&& other) = default;
+ TextRange& operator=(const TextRange& other) = default;
+ TextRange& operator=(TextRange&& other) = default;
+ ~TextRange() = default;
+
+ unsigned position;
+ unsigned count;
+
+ operator DWRITE_TEXT_RANGE() const
+ {
+ DWRITE_TEXT_RANGE result;
+ result.startPosition = position;
+ result.length = count;
+ return result;
+ }
+ };
+
class TextBlock : public Control
{
public:
@@ -74,6 +100,9 @@ namespace cru
void OnSizeChangedCore(events::SizeChangedEventArgs& args) override final;
void OnDraw(ID2D1DeviceContext* device_context) override;
+ void OnMouseDownCore(events::MouseButtonEventArgs& args) override;
+ void OnMouseMoveCore(events::MouseEventArgs& args) override;
+
Size OnMeasure(const Size& available_size) override;
private:
@@ -91,6 +120,11 @@ namespace cru
Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout_;
Vector<std::shared_ptr<TextLayoutHandler>> text_layout_handlers_;
+
+ unsigned mouse_down_position_;
+ std::optional<TextRange> selected_range_;
+
+ bool is_mouse_down_ = false; //TODO!!!
};
}
}