summaryrefslogtreecommitdiffstats
path: root/native/src/renderer
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-20 18:40:39 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-20 18:40:39 +0700
commite914888f57394e4b67b40e42f1ad9df4ae8147e6 (patch)
tree8aa199ea229941e7861e63b0b6bd7994dbca3ede /native/src/renderer
parent954d6349a8cd5505d99403285ce9617c65a63a2b (diff)
downloadiced-e914888f57394e4b67b40e42f1ad9df4ae8147e6.tar.gz
iced-e914888f57394e4b67b40e42f1ad9df4ae8147e6.tar.bz2
iced-e914888f57394e4b67b40e42f1ad9df4ae8147e6.zip
Implement `Widget::draw` for `TextInput`
Diffstat (limited to 'native/src/renderer')
-rw-r--r--native/src/renderer/null.rs24
-rw-r--r--native/src/renderer/text.rs40
2 files changed, 40 insertions, 24 deletions
diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs
index 2d6979e3..084b8d6f 100644
--- a/native/src/renderer/null.rs
+++ b/native/src/renderer/null.rs
@@ -4,7 +4,6 @@ use crate::progress_bar;
use crate::radio;
use crate::renderer::{self, Renderer};
use crate::text;
-use crate::text_input;
use crate::toggler;
use crate::{Font, Point, Rectangle, Size, Vector};
@@ -38,10 +37,6 @@ impl Renderer for Null {
impl renderer::Text for Null {
type Font = Font;
- fn fill_text(&mut self, _text: renderer::text::Section<'_, Self::Font>) {}
-}
-
-impl text::Renderer for Null {
fn default_size(&self) -> u16 {
20
}
@@ -67,25 +62,8 @@ impl text::Renderer for Null {
) -> Option<text::Hit> {
None
}
-}
-impl text_input::Renderer for Null {
- type Style = ();
-
- fn measure_value(&self, _value: &str, _size: u16, _font: Font) -> f32 {
- 0.0
- }
-
- fn offset(
- &self,
- _text_bounds: Rectangle,
- _font: Font,
- _size: u16,
- _value: &text_input::Value,
- _state: &text_input::State,
- ) -> f32 {
- 0.0
- }
+ fn fill_text(&mut self, _text: renderer::text::Section<'_, Self::Font>) {}
}
impl radio::Renderer for Null {
diff --git a/native/src/renderer/text.rs b/native/src/renderer/text.rs
index 9234c587..80769b62 100644
--- a/native/src/renderer/text.rs
+++ b/native/src/renderer/text.rs
@@ -1,10 +1,48 @@
use crate::alignment;
-use crate::{Color, Rectangle, Renderer};
+use crate::{Color, Point, Rectangle, Renderer, Size};
+
+pub use crate::text::Hit;
pub trait Text: Renderer {
/// The font type used.
type Font: Default + Copy;
+ /// Returns the default size of [`Text`].
+ fn default_size(&self) -> u16;
+
+ /// Measures the text in the given bounds and returns the minimum boundaries
+ /// that can fit the contents.
+ fn measure(
+ &self,
+ content: &str,
+ size: u16,
+ font: Self::Font,
+ bounds: Size,
+ ) -> (f32, f32);
+
+ fn measure_width(&self, content: &str, size: u16, font: Self::Font) -> f32 {
+ let (width, _) = self.measure(content, size, font, Size::INFINITY);
+
+ width
+ }
+
+ /// Tests whether the provided point is within the boundaries of [`Text`]
+ /// 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
+ /// the point is interior to any glyph bounds, returning only the character
+ /// with the nearest centeroid.
+ fn hit_test(
+ &self,
+ contents: &str,
+ size: f32,
+ font: Self::Font,
+ bounds: Size,
+ point: Point,
+ nearest_only: bool,
+ ) -> Option<Hit>;
+
fn fill_text(&mut self, section: Section<'_, Self::Font>);
}