diff options
Diffstat (limited to '')
-rw-r--r-- | native/src/renderer.rs | 8 | ||||
-rw-r--r-- | native/src/renderer/null.rs | 11 | ||||
-rw-r--r-- | native/src/renderer/text.rs | 20 |
3 files changed, 36 insertions, 3 deletions
diff --git a/native/src/renderer.rs b/native/src/renderer.rs index 3784ff24..ca0aecec 100644 --- a/native/src/renderer.rs +++ b/native/src/renderer.rs @@ -19,13 +19,17 @@ //! [`text::Renderer`]: crate::widget::text::Renderer //! [`Checkbox`]: crate::widget::Checkbox //! [`checkbox::Renderer`]: crate::widget::checkbox::Renderer +pub mod text; + +pub use text::Text; #[cfg(debug_assertions)] mod null; #[cfg(debug_assertions)] pub use null::Null; -use crate::{layout, Element, Rectangle}; +use crate::layout; +use crate::{Element, Rectangle}; /// A component that can take the state of a user interface and produce an /// output for its users. @@ -48,4 +52,6 @@ pub trait Renderer: Sized { } fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)); + + fn clear(&mut self); } diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs index 1ffca5c9..da758ebb 100644 --- a/native/src/renderer/null.rs +++ b/native/src/renderer/null.rs @@ -4,12 +4,13 @@ use crate::container; use crate::pane_grid; use crate::progress_bar; use crate::radio; +use crate::renderer::{self, Renderer}; use crate::scrollable; use crate::slider; use crate::text; use crate::text_input; use crate::toggler; -use crate::{Font, Padding, Point, Rectangle, Renderer, Size}; +use crate::{Font, Padding, Point, Rectangle, Size}; /// A renderer that does nothing. /// @@ -28,11 +29,17 @@ impl Renderer for Null { type Defaults = (); fn with_layer(&mut self, _bounds: Rectangle, _f: impl FnOnce(&mut Self)) {} + + fn clear(&mut self) {} } -impl text::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 } diff --git a/native/src/renderer/text.rs b/native/src/renderer/text.rs new file mode 100644 index 00000000..5c189d89 --- /dev/null +++ b/native/src/renderer/text.rs @@ -0,0 +1,20 @@ +use crate::alignment; +use crate::{Color, Rectangle, Renderer}; + +pub trait Text: Renderer { + /// The font type used. + type Font: Default + Copy; + + 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: Option<f32>, + pub color: Option<Color>, + pub font: Font, + pub horizontal_alignment: alignment::Horizontal, + pub vertical_alignment: alignment::Vertical, +} |