Rename HitTestResult to Hit

... and also move it to a new `text` module in `iced_core`
This commit is contained in:
Héctor Ramón Jiménez 2021-08-26 14:41:33 +07:00
parent aa63841e2c
commit 7614127d36
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
14 changed files with 48 additions and 48 deletions

View file

@ -1,4 +1,4 @@
//! Reuse basic keyboard types.
//! Listen to keyboard events.
mod event;
mod hotkey;
mod key_code;

View file

@ -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;

View file

@ -1,4 +1,4 @@
//! Reuse basic mouse types.
//! Handle mouse events.
mod button;
mod event;
mod interaction;

View file

@ -1,8 +1,9 @@
//! Draw and interact with text.
use crate::Vector;
/// The result of hit testing on text.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum HitTestResult {
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
@ -11,12 +12,12 @@ pub enum HitTestResult {
NearestCharOffset(usize, Vector),
}
impl HitTestResult {
impl Hit {
/// Computes the cursor position corresponding to this [`HitTestResult`] .
pub fn cursor(&self) -> usize {
match self {
HitTestResult::CharOffset(i) => *i,
HitTestResult::NearestCharOffset(i, delta) => {
Self::CharOffset(i) => *i,
Self::NearestCharOffset(i, delta) => {
if delta.x > f32::EPSILON {
i + 1
} else {