diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/platform/graph_base.hpp | 9 | ||||
-rw-r--r-- | include/cru/ui/render/text_render_object.hpp | 2 | ||||
-rw-r--r-- | include/cru/win/graph/direct/text_layout.hpp | 2 |
3 files changed, 12 insertions, 1 deletions
diff --git a/include/cru/platform/graph_base.hpp b/include/cru/platform/graph_base.hpp index 0b997770..c880c7a2 100644 --- a/include/cru/platform/graph_base.hpp +++ b/include/cru/platform/graph_base.hpp @@ -229,6 +229,15 @@ struct TextRange final { gsl::index GetEnd() const { return position + count; } + TextRange Normalize() const { + auto result = *this; + if (result.count < 0) { + result.position += result.count; + result.count = -result.count; + } + return result; + } + gsl::index position = 0; gsl::index count = 0; }; diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp index 1c472753..c062c9f0 100644 --- a/include/cru/ui/render/text_render_object.hpp +++ b/include/cru/ui/render/text_render_object.hpp @@ -27,7 +27,7 @@ class TextRenderObject : public RenderObject { void SetFont(std::shared_ptr<platform::graph::IFont> font); std::vector<Rect> TextRangeRect(const TextRange& text_range); - Point TextSingleRect(int position, bool trailing); + Point TextSingleRect(gsl::index position, bool trailing); platform::graph::TextHitTestResult TextHitTest(const Point& point); std::optional<TextRange> GetSelectionRange() const { diff --git a/include/cru/win/graph/direct/text_layout.hpp b/include/cru/win/graph/direct/text_layout.hpp index a9b89011..90faadf9 100644 --- a/include/cru/win/graph/direct/text_layout.hpp +++ b/include/cru/win/graph/direct/text_layout.hpp @@ -37,6 +37,8 @@ class DWriteTextLayout : public DirectGraphResource, void SetMaxHeight(float max_height) override; Rect GetTextBounds() override; + // Return empty vector if text_range.count is 0. Text range could be in + // reverse direction, it should be normalized first in implementation. std::vector<Rect> TextRangeRect(const TextRange& text_range) override; Point TextSingleRect(gsl::index position, bool trailing) override; TextHitTestResult HitTest(const Point& point) override; |