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` --- core/src/hit_test.rs | 28 ---------------------------- core/src/keyboard.rs | 2 +- core/src/lib.rs | 3 +-- core/src/mouse.rs | 2 +- core/src/text.rs | 29 +++++++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 core/src/hit_test.rs create mode 100644 core/src/text.rs (limited to 'core') diff --git a/core/src/hit_test.rs b/core/src/hit_test.rs deleted file mode 100644 index a4a7b610..00000000 --- a/core/src/hit_test.rs +++ /dev/null @@ -1,28 +0,0 @@ -use crate::Vector; - -/// The result of hit testing on text. -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum HitTestResult { - /// 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 HitTestResult { - /// Computes the cursor position corresponding to this [`HitTestResult`] . - pub fn cursor(&self) -> usize { - match self { - HitTestResult::CharOffset(i) => *i, - HitTestResult::NearestCharOffset(i, delta) => { - if delta.x > f32::EPSILON { - i + 1 - } else { - *i - } - } - } - } -} diff --git a/core/src/keyboard.rs b/core/src/keyboard.rs index cb64701a..6827a4db 100644 --- a/core/src/keyboard.rs +++ b/core/src/keyboard.rs @@ -1,4 +1,4 @@ -//! Reuse basic keyboard types. +//! Listen to keyboard events. mod event; mod hotkey; mod key_code; diff --git a/core/src/lib.rs b/core/src/lib.rs index 7c4c3c0c..a0decdab 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -17,12 +17,12 @@ pub mod keyboard; pub mod menu; pub mod mouse; +pub mod text; mod align; mod background; mod color; mod font; -mod hit_test; mod length; mod padding; mod point; @@ -34,7 +34,6 @@ pub use align::{Align, HorizontalAlignment, VerticalAlignment}; pub use background::Background; pub use color::Color; pub use font::Font; -pub use hit_test::HitTestResult; pub use length::Length; pub use menu::Menu; pub use padding::Padding; diff --git a/core/src/mouse.rs b/core/src/mouse.rs index 25ce6ac3..48214f65 100644 --- a/core/src/mouse.rs +++ b/core/src/mouse.rs @@ -1,4 +1,4 @@ -//! Reuse basic mouse types. +//! Handle mouse events. mod button; mod event; mod interaction; diff --git a/core/src/text.rs b/core/src/text.rs new file mode 100644 index 00000000..ded22eef --- /dev/null +++ b/core/src/text.rs @@ -0,0 +1,29 @@ +//! 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 + } + } + } + } +} -- cgit