diff options
author | 2021-11-04 19:24:52 +0700 | |
---|---|---|
committer | 2021-11-04 19:24:52 +0700 | |
commit | d5f4067defcc033c5963676c872d9245d494db69 (patch) | |
tree | f32a4f62aefd02b08ec0b2d3978889836c62e7b7 /native | |
parent | faaa17c3a5332a74147b6d5c937e3e9bc0952ecb (diff) | |
download | iced-d5f4067defcc033c5963676c872d9245d494db69.tar.gz iced-d5f4067defcc033c5963676c872d9245d494db69.tar.bz2 iced-d5f4067defcc033c5963676c872d9245d494db69.zip |
Write documentation for `iced_native::text`
Diffstat (limited to 'native')
-rw-r--r-- | native/src/text.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/native/src/text.rs b/native/src/text.rs index 81419481..8b9205e3 100644 --- a/native/src/text.rs +++ b/native/src/text.rs @@ -1,14 +1,29 @@ +//! Draw and interact with text. use crate::alignment; use crate::{Color, Point, Rectangle, Size, Vector}; +/// A paragraph. #[derive(Debug, Clone, Copy)] pub struct Text<'a, Font> { + /// The content of the paragraph. pub content: &'a str, + + /// The bounds of the paragraph. pub bounds: Rectangle, + + /// The size of the [`Text`]. pub size: f32, + + /// The color of the [`Text`]. pub color: Color, + + /// The font of the [`Text`]. pub font: Font, + + /// The horizontal alignment of the [`Text`]. pub horizontal_alignment: alignment::Horizontal, + + /// The vertical alignment of the [`Text`]. pub vertical_alignment: alignment::Vertical, } @@ -39,6 +54,7 @@ impl Hit { } } +/// A renderer capable of measuring and drawing [`Text`]. pub trait Renderer: crate::Renderer { /// The font type used. type Font: Default + Copy; @@ -69,13 +85,14 @@ pub trait Renderer: crate::Renderer { bounds: Size, ) -> (f32, f32); + /// Measures the width of the text as if it were laid out in a single line. 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`] + /// Tests whether the provided point is within the boundaries of text /// laid out with the given parameters, returning information about /// the nearest character. /// @@ -92,5 +109,6 @@ pub trait Renderer: crate::Renderer { nearest_only: bool, ) -> Option<Hit>; + /// Draws the given [`Text`]. fn fill_text(&mut self, text: Text<'_, Self::Font>); } |