Implement Widget::draw for Text
This commit is contained in:
parent
03b3493138
commit
3a0c503db9
11 changed files with 128 additions and 32 deletions
|
|
@ -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 renderer::Text for Null {
|
||||
type Font = Font;
|
||||
|
||||
fn fill_text(&mut self, _text: renderer::text::Section<'_, Self::Font>) {}
|
||||
}
|
||||
|
||||
impl text::Renderer for Null {
|
||||
type Font = Font;
|
||||
|
||||
fn default_size(&self) -> u16 {
|
||||
20
|
||||
}
|
||||
|
|
|
|||
20
native/src/renderer/text.rs
Normal file
20
native/src/renderer/text.rs
Normal file
|
|
@ -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,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue