From 343f9b7e2e594bd1fef1ed511d71e81f9c44e3d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 4 Nov 2021 18:28:06 +0700 Subject: [PATCH] Merge `iced_core::text` with `iced_native::text` --- core/src/lib.rs | 1 - core/src/text.rs | 29 ----------------------------- native/src/text.rs | 31 ++++++++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 33 deletions(-) delete mode 100644 core/src/text.rs diff --git a/core/src/lib.rs b/core/src/lib.rs index 1f58a8cde3..cd505239e0 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -17,7 +17,6 @@ pub mod alignment; pub mod keyboard; pub mod mouse; -pub mod text; mod background; mod color; diff --git a/core/src/text.rs b/core/src/text.rs deleted file mode 100644 index e5d0092e6f..0000000000 --- a/core/src/text.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! Draw and interact with text. -use crate::Vector; - -/// 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 - } - } - } - } -} diff --git a/native/src/text.rs b/native/src/text.rs index f112a8f386..8141948122 100644 --- a/native/src/text.rs +++ b/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> { @@ -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;