Skip to main content

draw_text_view

Function draw_text_view 

Source
pub fn draw_text_view<D>(
    display: &mut D,
    frame: Rectangle,
    spans: &[TextSpan<'_>],
    view_style: &TextViewStyle,
)
where D: DrawTarget<Color = Rgb565>,
Expand description

Shared renderer used by TextView and RichTextView.

Examples found in repository?
src/text_view/widget.rs (line 47)
42    pub fn draw<D>(&self, display: &mut D)
43    where
44        D: DrawTarget<Color = Rgb565>,
45    {
46        let spans = [TextSpan::new(self.text, self.style)];
47        draw_text_view(display, self.frame, &spans, &self.view_style);
48    }
49}
50
51/// Rich text view built from multiple styled spans.
52pub struct RichTextView<'a> {
53    /// Outer frame for the text view.
54    pub frame: Rectangle,
55    /// Styled spans rendered in order.
56    pub spans: &'a [TextSpan<'a>],
57    /// Container-level layout and shell styling.
58    pub view_style: TextViewStyle,
59}
60
61impl<'a> RichTextView<'a> {
62    /// Creates a rich text view.
63    pub const fn new(frame: Rectangle, spans: &'a [TextSpan<'a>]) -> Self {
64        Self {
65            frame,
66            spans,
67            view_style: TextViewStyle::new(),
68        }
69    }
70
71    /// Replaces the container style.
72    pub fn with_view_style(mut self, view_style: TextViewStyle) -> Self {
73        self.view_style = view_style;
74        self
75    }
76
77    /// Draws the rich text view.
78    pub fn draw<D>(&self, display: &mut D)
79    where
80        D: DrawTarget<Color = Rgb565>,
81    {
82        draw_text_view(display, self.frame, self.spans, &self.view_style);
83    }