Merge pull request #670 from twitchyliquid64/text_backend
Refactor textual hit testing into a `renderer::Backend` method
This commit is contained in:
commit
6821114cae
13 changed files with 335 additions and 69 deletions
|
|
@ -1,7 +1,8 @@
|
|||
//! Write a graphics backend.
|
||||
use iced_native::image;
|
||||
use iced_native::svg;
|
||||
use iced_native::{Font, Size};
|
||||
use iced_native::text;
|
||||
use iced_native::{Font, Point, Size};
|
||||
|
||||
/// The graphics backend of a [`Renderer`].
|
||||
///
|
||||
|
|
@ -43,6 +44,23 @@ pub trait Text {
|
|||
font: Font,
|
||||
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: Font,
|
||||
bounds: Size,
|
||||
point: Point,
|
||||
nearest_only: bool,
|
||||
) -> text::Hit;
|
||||
}
|
||||
|
||||
/// A graphics backend that supports image rendering.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::{Primitive, Renderer};
|
|||
use iced_native::mouse;
|
||||
use iced_native::text;
|
||||
use iced_native::{
|
||||
Color, Font, HorizontalAlignment, Rectangle, Size, VerticalAlignment,
|
||||
Color, Font, HorizontalAlignment, Point, Rectangle, Size, VerticalAlignment,
|
||||
};
|
||||
|
||||
/// A paragraph of text.
|
||||
|
|
@ -35,6 +35,25 @@ where
|
|||
.measure(content, f32::from(size), font, bounds)
|
||||
}
|
||||
|
||||
fn hit_test(
|
||||
&self,
|
||||
content: &str,
|
||||
size: f32,
|
||||
font: Font,
|
||||
bounds: Size,
|
||||
point: Point,
|
||||
nearest_only: bool,
|
||||
) -> text::Hit {
|
||||
self.backend().hit_test(
|
||||
content,
|
||||
size,
|
||||
font,
|
||||
bounds,
|
||||
point,
|
||||
nearest_only,
|
||||
)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
defaults: &Self::Defaults,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue