diff options
author | 2021-10-31 16:13:03 +0700 | |
---|---|---|
committer | 2021-10-31 16:14:38 +0700 | |
commit | b3a01973c6c726e6539be959659f4306ef3234c6 (patch) | |
tree | 06e6ce43b5e47eb78f2707eb2c6177a2f9af91f4 /native/src/renderer | |
parent | 0aafcde0ef1533c9eeba0379de8c0082e30c7504 (diff) | |
download | iced-b3a01973c6c726e6539be959659f4306ef3234c6.tar.gz iced-b3a01973c6c726e6539be959659f4306ef3234c6.tar.bz2 iced-b3a01973c6c726e6539be959659f4306ef3234c6.zip |
Introduce first-class `text` module in `iced_native`
Diffstat (limited to 'native/src/renderer')
-rw-r--r-- | native/src/renderer/null.rs | 6 | ||||
-rw-r--r-- | native/src/renderer/text.rs | 71 |
2 files changed, 3 insertions, 74 deletions
diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs index e57841f4..263b38a9 100644 --- a/native/src/renderer/null.rs +++ b/native/src/renderer/null.rs @@ -1,5 +1,5 @@ use crate::renderer::{self, Renderer}; -use crate::widget::text; +use crate::text::{self, Text}; use crate::{Font, Point, Rectangle, Size, Vector}; /// A renderer that does nothing. @@ -30,7 +30,7 @@ impl Renderer for Null { fn fill_rectangle(&mut self, _quad: renderer::Quad) {} } -impl renderer::Text for Null { +impl text::Renderer for Null { type Font = Font; const ICON_FONT: Font = Font::Default; @@ -63,5 +63,5 @@ impl renderer::Text for Null { None } - fn fill_text(&mut self, _text: renderer::text::Section<'_, Self::Font>) {} + fn fill_text(&mut self, _text: Text<'_, Self::Font>) {} } diff --git a/native/src/renderer/text.rs b/native/src/renderer/text.rs deleted file mode 100644 index fc1a2c66..00000000 --- a/native/src/renderer/text.rs +++ /dev/null @@ -1,71 +0,0 @@ -use crate::alignment; -use crate::{Color, Point, Rectangle, Renderer, Size}; - -pub use crate::widget::text::Hit; - -pub trait Text: Renderer { - /// The font type used. - type Font: Default + Copy; - - /// The icon font of the backend. - const ICON_FONT: Self::Font; - - /// The `char` representing a ✔ icon in the [`ICON_FONT`]. - /// - /// [`ICON_FONT`]: Self::ICON_FONT - const CHECKMARK_ICON: char; - - /// The `char` representing a ▼ icon in the built-in [`ICON_FONT`]. - /// - /// [`ICON_FONT`]: Self::ICON_FONT - const ARROW_DOWN_ICON: char; - - /// 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>); -} - -#[derive(Debug, Clone, Copy)] -pub struct Section<'a, Font> { - pub content: &'a str, - pub bounds: Rectangle, - pub size: f32, - pub color: Color, - pub font: Font, - pub horizontal_alignment: alignment::Horizontal, - pub vertical_alignment: alignment::Vertical, -} |