clock_tui/
clock_text.rs

1use ratatui::{style::Style, widgets::Widget};
2
3use crate::clock_text::font::Font;
4
5pub mod font;
6pub mod point;
7
8#[derive(Clone)]
9pub struct ClockText<'a> {
10    pub text: String,
11    pub font: &'a dyn Font,
12    pub style: Style,
13}
14
15impl<'a> ClockText<'a> {
16    pub fn new(text: String, font: &'a dyn Font, style: Style) -> ClockText<'a> {
17        ClockText { text, font, style }
18    }
19    pub fn size(&self) -> (u16, u16) {
20        let width = self.text.chars().count() as u16 * (self.font.get_char_width() + 2) - 2;
21        let height = self.font.get_char_height();
22        (width, height)
23    }
24}
25
26impl<'a> Widget for ClockText<'a> {
27    fn render(self, area: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) {
28        self.font.draw_str(&self.text, area, self.style, buf);
29    }
30}