itools_tui/components/
panel.rs1use crate::{event::Event, layout::Rect, render::Frame, style::Style};
4
5pub struct Panel {
7 title: Option<String>,
9 style: Style,
11 border_style: Style,
13 content: Box<dyn super::Component>,
15}
16
17impl Panel {
18 pub fn new(content: impl super::Component + 'static) -> Self {
20 Self { title: None, style: Style::new(), border_style: Style::new(), content: Box::new(content) }
21 }
22
23 pub fn title(mut self, title: &str) -> Self {
25 self.title = Some(title.to_string());
26 self
27 }
28
29 pub fn style(mut self, style: Style) -> Self {
31 self.style = style;
32 self
33 }
34
35 pub fn border_style(mut self, style: Style) -> Self {
37 self.border_style = style;
38 self
39 }
40}
41
42impl super::Component for Panel {
43 fn render(&self, frame: &mut Frame, area: Rect) {
44 frame.render_panel(self.title.as_deref(), area, self.style.clone(), self.border_style.clone());
45
46 let content_area = area.shrink(1);
48 self.content.render(frame, content_area);
49 }
50
51 fn handle_event(&mut self, event: &Event) -> bool {
52 self.content.handle_event(event)
53 }
54}