Skip to content

Commit

Permalink
Merge iced_core::text with iced_native::text
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Nov 4, 2021
1 parent ef5a731 commit 343f9b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
1 change: 0 additions & 1 deletion core/src/lib.rs
Expand Up @@ -17,7 +17,6 @@
pub mod alignment;
pub mod keyboard;
pub mod mouse;
pub mod text;

mod background;
mod color;
Expand Down
29 changes: 0 additions & 29 deletions core/src/text.rs

This file was deleted.

31 changes: 28 additions & 3 deletions native/src/text.rs
@@ -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> {
Expand All @@ -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;
Expand Down

0 comments on commit 343f9b7

Please sign in to comment.