1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use super::*;

pub struct SizedParagraph {
    p: Paragraph<'static>,
    height: Option<u16>,
    width: Option<u16>,
}

impl SizedParagraph {
    pub fn new(text: Text<'static>) -> Self {
        let height = text.height().try_into().ok();
        let width = text.width().try_into().ok();
        let p = Paragraph::new(text);
        Self { p, height, width }
    }
}

impl SizedWidget for SizedParagraph {
    fn width(&self) -> Option<u16> {
        self.width
    }
    fn height(&self) -> Option<u16> {
        self.height
    }
}

impl Draw for SizedParagraph {
    fn draw(&mut self, area: Rect, f: &mut Frame<'_>) {
        f.render_widget(&self.p, area);
    }
}