rustic_rs/commands/tui/widgets/
sized_gauge.rs

1use super::{Color, Draw, Frame, Gauge, Rect, SizedWidget, Span, Style};
2
3pub struct SizedGauge {
4    p: Gauge<'static>,
5    width: Option<u16>,
6}
7
8impl SizedGauge {
9    pub fn new(text: Span<'static>, ratio: f64) -> Self {
10        let width = text.width().try_into().ok();
11        let p = Gauge::default()
12            .gauge_style(Style::default().fg(Color::Blue))
13            .use_unicode(true)
14            .label(text)
15            .ratio(ratio);
16        Self { p, width }
17    }
18}
19
20impl SizedWidget for SizedGauge {
21    fn width(&self) -> Option<u16> {
22        self.width.map(|w| w + 10)
23    }
24    fn height(&self) -> Option<u16> {
25        Some(1)
26    }
27}
28
29impl Draw for SizedGauge {
30    fn draw(&mut self, area: Rect, f: &mut Frame<'_>) {
31        f.render_widget(&self.p, area);
32    }
33}