summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-08-26 14:41:33 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-08-26 14:41:33 +0700
commit7614127d3641cf3224798c2f0ff07b6ae57d9a53 (patch)
tree413fc3a6f7a22bfaf00de05dfcc9acf5b40bdd26
parentaa63841e2c80ca8130adf41d25e5d731409b92f4 (diff)
downloadiced-7614127d3641cf3224798c2f0ff07b6ae57d9a53.tar.gz
iced-7614127d3641cf3224798c2f0ff07b6ae57d9a53.tar.bz2
iced-7614127d3641cf3224798c2f0ff07b6ae57d9a53.zip
Rename `HitTestResult` to `Hit`
... and also move it to a new `text` module in `iced_core`
-rw-r--r--core/src/keyboard.rs2
-rw-r--r--core/src/lib.rs3
-rw-r--r--core/src/mouse.rs2
-rw-r--r--core/src/text.rs (renamed from core/src/hit_test.rs)9
-rw-r--r--glow/src/backend.rs7
-rw-r--r--glow/src/text.rs16
-rw-r--r--graphics/src/backend.rs5
-rw-r--r--graphics/src/lib.rs4
-rw-r--r--graphics/src/widget/text.rs5
-rw-r--r--native/src/lib.rs4
-rw-r--r--native/src/renderer/null.rs8
-rw-r--r--native/src/widget/text.rs10
-rw-r--r--wgpu/src/backend.rs7
-rw-r--r--wgpu/src/text.rs14
14 files changed, 48 insertions, 48 deletions
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/hit_test.rs b/core/src/text.rs
index a4a7b610..ded22eef 100644
--- a/core/src/hit_test.rs
+++ b/core/src/text.rs
@@ -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 {
diff --git a/glow/src/backend.rs b/glow/src/backend.rs
index d97cbceb..37c0ac9d 100644
--- a/glow/src/backend.rs
+++ b/glow/src/backend.rs
@@ -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,
diff --git a/glow/src/text.rs b/glow/src/text.rs
index bb882594..d6915d92 100644
--- a/glow/src/text.rs
+++ b/glow/src/text.rs
@@ -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) {
diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs
index 94124509..656949c5 100644
--- a/graphics/src/backend.rs
+++ b/graphics/src/backend.rs
@@ -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.
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index 687294fc..14388653 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -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,
};
diff --git a/graphics/src/widget/text.rs b/graphics/src/widget/text.rs
index e1b4e4e8..c235f254 100644
--- a/graphics/src/widget/text.rs
+++ b/graphics/src/widget/text.rs
@@ -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,
diff --git a/native/src/lib.rs b/native/src/lib.rs
index 06bfd3c5..cbb02506 100644
--- a/native/src/lib.rs
+++ b/native/src/lib.rs
@@ -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};
diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs
index 3ae05f10..b1a26c41 100644
--- a/native/src/renderer/null.rs
+++ b/native/src/renderer/null.rs
@@ -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(
diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs
index f37f90a9..adf6a74f 100644
--- a/native/src/widget/text.rs
+++ b/native/src/widget/text.rs
@@ -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.
///
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs
index fe8ed255..b31bf92c 100644
--- a/wgpu/src/backend.rs
+++ b/wgpu/src/backend.rs
@@ -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,
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index f227cb6f..ee49ee4b 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -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) {