Rename HitTestResult to Hit
... and also move it to a new `text` module in `iced_core`
This commit is contained in:
parent
aa63841e2c
commit
7614127d36
14 changed files with 48 additions and 48 deletions
29
core/src/text.rs
Normal file
29
core/src/text.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue