Merge iced_core::text with iced_native::text

This commit is contained in:
Héctor Ramón Jiménez 2021-11-04 18:28:06 +07:00
parent ef5a731e4b
commit 343f9b7e2e
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
3 changed files with 28 additions and 33 deletions

View file

@ -1,7 +1,5 @@
use crate::alignment;
use crate::{Color, Point, Rectangle, Size};
pub use iced_core::text::Hit;
use crate::{Color, Point, Rectangle, Size, Vector};
#[derive(Debug, Clone, Copy)]
pub struct Text<'a, Font> {
@ -14,6 +12,33 @@ pub struct Text<'a, Font> {
pub vertical_alignment: alignment::Vertical,
}
/// The result of hit testing on text.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Hit {
/// The point was within the bounds of the returned character index.
CharOffset(usize),
/// The provided point was not within the bounds of a glyph. The index
/// of the character with the closest centeroid position is returned,
/// as well as its delta.
NearestCharOffset(usize, Vector),
}
impl Hit {
/// Computes the cursor position corresponding to this [`HitTestResult`] .
pub fn cursor(self) -> usize {
match self {
Self::CharOffset(i) => i,
Self::NearestCharOffset(i, delta) => {
if delta.x > f32::EPSILON {
i + 1
} else {
i
}
}
}
}
}
pub trait Renderer: crate::Renderer {
/// The font type used.
type Font: Default + Copy;