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
|
|
@ -1,4 +1,4 @@
|
|||
//! Reuse basic keyboard types.
|
||||
//! Listen to keyboard events.
|
||||
mod event;
|
||||
mod hotkey;
|
||||
mod key_code;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//! Reuse basic mouse types.
|
||||
//! Handle mouse events.
|
||||
mod button;
|
||||
mod event;
|
||||
mod interaction;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -2,14 +2,13 @@ use crate::quad;
|
|||
use crate::text;
|
||||
use crate::triangle;
|
||||
use crate::{Settings, Transformation, Viewport};
|
||||
|
||||
use iced_graphics::backend;
|
||||
use iced_graphics::font;
|
||||
use iced_graphics::Layer;
|
||||
use iced_graphics::Primitive;
|
||||
use iced_native::mouse;
|
||||
use iced_native::{
|
||||
Font, HitTestResult, HorizontalAlignment, Size, VerticalAlignment,
|
||||
};
|
||||
use iced_native::{Font, HorizontalAlignment, Size, VerticalAlignment};
|
||||
|
||||
/// A [`glow`] graphics backend for [`iced`].
|
||||
///
|
||||
|
|
@ -222,7 +221,7 @@ impl backend::Text for Backend {
|
|||
bounds: Size,
|
||||
point: iced_native::Point,
|
||||
nearest_only: bool,
|
||||
) -> HitTestResult {
|
||||
) -> text::Hit {
|
||||
self.text_pipeline.hit_test(
|
||||
contents,
|
||||
size,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
use crate::Transformation;
|
||||
use glow_glyph::ab_glyph;
|
||||
|
||||
use iced_graphics::font;
|
||||
use iced_native::HitTestResult;
|
||||
|
||||
use glow_glyph::ab_glyph;
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
|
||||
pub use iced_native::text::Hit;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Pipeline {
|
||||
draw_brush: RefCell<glow_glyph::GlyphBrush>,
|
||||
|
|
@ -118,7 +121,7 @@ impl Pipeline {
|
|||
bounds: iced_native::Size,
|
||||
point: iced_native::Point,
|
||||
nearest_only: bool,
|
||||
) -> HitTestResult {
|
||||
) -> Hit {
|
||||
use glow_glyph::GlyphCruncher;
|
||||
|
||||
let glow_glyph::FontId(font_id) = self.find_font(font);
|
||||
|
|
@ -179,7 +182,7 @@ impl Pipeline {
|
|||
if !nearest_only {
|
||||
for (idx, bounds) in bounds.clone() {
|
||||
if bounds.contains(point) {
|
||||
return HitTestResult::CharOffset(char_index(idx));
|
||||
return Hit::CharOffset(char_index(idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -195,10 +198,7 @@ impl Pipeline {
|
|||
},
|
||||
);
|
||||
|
||||
HitTestResult::NearestCharOffset(
|
||||
char_index(idx),
|
||||
(point - nearest).into(),
|
||||
)
|
||||
Hit::NearestCharOffset(char_index(idx), (point - nearest).into())
|
||||
}
|
||||
|
||||
pub fn trim_measurement_cache(&mut self) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
//! Write a graphics backend.
|
||||
use iced_native::image;
|
||||
use iced_native::svg;
|
||||
use iced_native::{Font, HitTestResult, Point, Size};
|
||||
use iced_native::text;
|
||||
use iced_native::{Font, Point, Size};
|
||||
|
||||
/// The graphics backend of a [`Renderer`].
|
||||
///
|
||||
|
|
@ -59,7 +60,7 @@ pub trait Text {
|
|||
bounds: Size,
|
||||
point: Point,
|
||||
nearest_only: bool,
|
||||
) -> HitTestResult;
|
||||
) -> text::Hit;
|
||||
}
|
||||
|
||||
/// A graphics backend that supports image rendering.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,6 @@ pub use transformation::Transformation;
|
|||
pub use viewport::Viewport;
|
||||
|
||||
pub use iced_native::{
|
||||
Background, Color, Font, HitTestResult, HorizontalAlignment, Point,
|
||||
Rectangle, Size, Vector, VerticalAlignment,
|
||||
Background, Color, Font, HorizontalAlignment, Point, Rectangle, Size,
|
||||
Vector, VerticalAlignment,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ use crate::{Primitive, Renderer};
|
|||
use iced_native::mouse;
|
||||
use iced_native::text;
|
||||
use iced_native::{
|
||||
Color, Font, HitTestResult, HorizontalAlignment, Point, Rectangle, Size,
|
||||
VerticalAlignment,
|
||||
Color, Font, HorizontalAlignment, Point, Rectangle, Size, VerticalAlignment,
|
||||
};
|
||||
|
||||
/// A paragraph of text.
|
||||
|
|
@ -44,7 +43,7 @@ where
|
|||
bounds: Size,
|
||||
point: Point,
|
||||
nearest_only: bool,
|
||||
) -> HitTestResult {
|
||||
) -> text::Hit {
|
||||
self.backend().hit_test(
|
||||
content,
|
||||
size,
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ mod debug;
|
|||
mod debug;
|
||||
|
||||
pub use iced_core::{
|
||||
menu, Align, Background, Color, Font, HitTestResult, HorizontalAlignment,
|
||||
Length, Menu, Padding, Point, Rectangle, Size, Vector, VerticalAlignment,
|
||||
menu, Align, Background, Color, Font, HorizontalAlignment, Length, Menu,
|
||||
Padding, Point, Rectangle, Size, Vector, VerticalAlignment,
|
||||
};
|
||||
pub use iced_futures::{executor, futures, Command};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{
|
||||
button, checkbox, column, container, pane_grid, progress_bar, radio, row,
|
||||
scrollable, slider, text, text_input, toggler, Color, Element, Font,
|
||||
HitTestResult, HorizontalAlignment, Layout, Padding, Point, Rectangle,
|
||||
Renderer, Size, Vector, VerticalAlignment,
|
||||
HorizontalAlignment, Layout, Padding, Point, Rectangle, Renderer, Size,
|
||||
Vector, VerticalAlignment,
|
||||
};
|
||||
|
||||
/// A renderer that does nothing.
|
||||
|
|
@ -75,8 +75,8 @@ impl text::Renderer for Null {
|
|||
_bounds: Size,
|
||||
_point: Point,
|
||||
_nearest_only: bool,
|
||||
) -> HitTestResult {
|
||||
HitTestResult::NearestCharOffset(0, Vector::new(0., 0.))
|
||||
) -> text::Hit {
|
||||
text::Hit::NearestCharOffset(0, Vector::new(0., 0.))
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
//! Write some text for your users to read.
|
||||
use crate::{
|
||||
layout, Color, Element, Hasher, HitTestResult, HorizontalAlignment, Layout,
|
||||
Length, Point, Rectangle, Size, VerticalAlignment, Widget,
|
||||
layout, Color, Element, Hasher, HorizontalAlignment, Layout, Length, Point,
|
||||
Rectangle, Size, VerticalAlignment, Widget,
|
||||
};
|
||||
|
||||
pub use iced_core::text::Hit;
|
||||
|
||||
use std::hash::Hash;
|
||||
|
||||
/// A paragraph of text.
|
||||
|
|
@ -183,7 +185,7 @@ pub trait Renderer: crate::Renderer {
|
|||
/// laid out with the given parameters, returning information about
|
||||
/// the nearest character.
|
||||
///
|
||||
/// If nearest_only is true, the hit test does not consider whether the
|
||||
/// If `nearest_only` is true, the hit test does not consider whether the
|
||||
/// the point is interior to any glyph bounds, returning only the character
|
||||
/// with the nearest centeroid.
|
||||
fn hit_test(
|
||||
|
|
@ -194,7 +196,7 @@ pub trait Renderer: crate::Renderer {
|
|||
bounds: Size,
|
||||
point: Point,
|
||||
nearest_only: bool,
|
||||
) -> HitTestResult;
|
||||
) -> Hit;
|
||||
|
||||
/// Draws a [`Text`] fragment.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@ use crate::quad;
|
|||
use crate::text;
|
||||
use crate::triangle;
|
||||
use crate::{Settings, Transformation};
|
||||
|
||||
use iced_graphics::backend;
|
||||
use iced_graphics::font;
|
||||
use iced_graphics::layer::Layer;
|
||||
use iced_graphics::{Primitive, Viewport};
|
||||
use iced_native::mouse;
|
||||
use iced_native::{
|
||||
Font, HitTestResult, HorizontalAlignment, Size, VerticalAlignment,
|
||||
};
|
||||
use iced_native::{Font, HorizontalAlignment, Size, VerticalAlignment};
|
||||
|
||||
#[cfg(any(feature = "image_rs", feature = "svg"))]
|
||||
use crate::image;
|
||||
|
|
@ -285,7 +284,7 @@ impl backend::Text for Backend {
|
|||
bounds: Size,
|
||||
point: iced_native::Point,
|
||||
nearest_only: bool,
|
||||
) -> HitTestResult {
|
||||
) -> text::Hit {
|
||||
self.text_pipeline.hit_test(
|
||||
contents,
|
||||
size,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
use crate::Transformation;
|
||||
|
||||
use iced_graphics::font;
|
||||
use iced_native::HitTestResult;
|
||||
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
use wgpu_glyph::ab_glyph;
|
||||
|
||||
pub use iced_native::text::Hit;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Pipeline {
|
||||
draw_brush: RefCell<wgpu_glyph::GlyphBrush<()>>,
|
||||
|
|
@ -126,7 +129,7 @@ impl Pipeline {
|
|||
bounds: iced_native::Size,
|
||||
point: iced_native::Point,
|
||||
nearest_only: bool,
|
||||
) -> HitTestResult {
|
||||
) -> Hit {
|
||||
use wgpu_glyph::GlyphCruncher;
|
||||
|
||||
let wgpu_glyph::FontId(font_id) = self.find_font(font);
|
||||
|
|
@ -187,7 +190,7 @@ impl Pipeline {
|
|||
if !nearest_only {
|
||||
for (idx, bounds) in bounds.clone() {
|
||||
if bounds.contains(point) {
|
||||
return HitTestResult::CharOffset(char_index(idx));
|
||||
return Hit::CharOffset(char_index(idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -203,10 +206,7 @@ impl Pipeline {
|
|||
},
|
||||
);
|
||||
|
||||
HitTestResult::NearestCharOffset(
|
||||
char_index(idx),
|
||||
(point - nearest).into(),
|
||||
)
|
||||
Hit::NearestCharOffset(char_index(idx), (point - nearest).into())
|
||||
}
|
||||
|
||||
pub fn trim_measurement_cache(&mut self) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue