From aa63841e2c80ca8130adf41d25e5d731409b92f4 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 21 Aug 2021 10:31:26 -0700 Subject: Implement textual hit testing --- native/src/widget/text.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'native/src/widget/text.rs') diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs index 6cc18e6c..f37f90a9 100644 --- a/native/src/widget/text.rs +++ b/native/src/widget/text.rs @@ -1,7 +1,7 @@ //! Write some text for your users to read. use crate::{ - layout, Color, Element, Hasher, HorizontalAlignment, Layout, Length, Point, - Rectangle, Size, VerticalAlignment, Widget, + layout, Color, Element, Hasher, HitTestResult, HorizontalAlignment, Layout, + Length, Point, Rectangle, Size, VerticalAlignment, Widget, }; use std::hash::Hash; @@ -179,6 +179,23 @@ pub trait Renderer: crate::Renderer { bounds: Size, ) -> (f32, f32); + /// Tests whether the provided point is within the boundaries of [`Text`] + /// laid out with the given parameters, returning information about + /// the nearest character. + /// + /// If nearest_only is true, the hit test does not consider whether the + /// the point is interior to any glyph bounds, returning only the character + /// with the nearest centeroid. + fn hit_test( + &self, + contents: &str, + size: f32, + font: Self::Font, + bounds: Size, + point: Point, + nearest_only: bool, + ) -> HitTestResult; + /// Draws a [`Text`] fragment. /// /// It receives: -- cgit From 7614127d3641cf3224798c2f0ff07b6ae57d9a53 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 Aug 2021 14:41:33 +0700 Subject: Rename `HitTestResult` to `Hit` ... and also move it to a new `text` module in `iced_core` --- native/src/widget/text.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'native/src/widget/text.rs') diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs index f37f90a9..adf6a74f 100644 --- a/native/src/widget/text.rs +++ b/native/src/widget/text.rs @@ -1,9 +1,11 @@ //! Write some text for your users to read. use crate::{ - layout, Color, Element, Hasher, HitTestResult, HorizontalAlignment, Layout, - Length, Point, Rectangle, Size, VerticalAlignment, Widget, + layout, Color, Element, Hasher, HorizontalAlignment, Layout, Length, Point, + Rectangle, Size, VerticalAlignment, Widget, }; +pub use iced_core::text::Hit; + use std::hash::Hash; /// A paragraph of text. @@ -183,7 +185,7 @@ pub trait Renderer: crate::Renderer { /// laid out with the given parameters, returning information about /// the nearest character. /// - /// If nearest_only is true, the hit test does not consider whether the + /// If `nearest_only` is true, the hit test does not consider whether the /// the point is interior to any glyph bounds, returning only the character /// with the nearest centeroid. fn hit_test( @@ -194,7 +196,7 @@ pub trait Renderer: crate::Renderer { bounds: Size, point: Point, nearest_only: bool, - ) -> HitTestResult; + ) -> Hit; /// Draws a [`Text`] fragment. /// -- cgit