rustic_rs/commands/tui/widgets/
sized_paragraph.rs

1use super::{Draw, Frame, Paragraph, Rect, SizedWidget, Text};
2
3pub struct SizedParagraph {
4    p: Paragraph<'static>,
5    height: Option<u16>,
6    width: Option<u16>,
7}
8
9impl SizedParagraph {
10    pub fn new(text: Text<'static>) -> Self {
11        let height = text.height().try_into().ok();
12        let width = text.width().try_into().ok();
13        let p = Paragraph::new(text);
14        Self { p, height, width }
15    }
16}
17
18impl SizedWidget for SizedParagraph {
19    fn width(&self) -> Option<u16> {
20        self.width
21    }
22    fn height(&self) -> Option<u16> {
23        self.height
24    }
25}
26
27impl Draw for SizedParagraph {
28    fn draw(&mut self, area: Rect, f: &mut Frame<'_>) {
29        f.render_widget(&self.p, area);
30    }
31}