journey/widgets/
heading.rs1use saudade::{Painter, Rect, Theme, Widget};
9
10pub struct Heading {
11 rect: Rect,
12 text: String,
13 size: f32,
14}
15
16impl Heading {
17 pub fn new(text: impl Into<String>) -> Self {
18 Self {
19 rect: Rect::new(0, 0, 0, 0),
20 text: text.into(),
21 size: 12.0,
22 }
23 }
24
25 pub fn set_text(&mut self, text: impl Into<String>) {
26 self.text = text.into();
27 }
28}
29
30impl Widget for Heading {
31 fn bounds(&self) -> Rect {
32 self.rect
33 }
34
35 fn paint(&mut self, painter: &mut Painter, theme: &Theme) {
36 let y = self.rect.y + (self.rect.h - self.size as i32).max(0) / 2;
37 painter.text(self.rect.x, y, &self.text, self.size, theme.text);
38 }
39
40 fn layout(&mut self, bounds: Rect) {
41 self.rect = bounds;
42 }
43}