From e914888f57394e4b67b40e42f1ad9df4ae8147e6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Oct 2021 18:40:39 +0700 Subject: Implement `Widget::draw` for `TextInput` --- native/src/renderer/text.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'native/src/renderer/text.rs') 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; + fn fill_text(&mut self, section: Section<'_, Self::Font>); } -- cgit