use crate::{event::Event, layout::Rect, render::Frame, style::Style};
pub struct Panel {
title: Option<String>,
style: Style,
border_style: Style,
content: Box<dyn super::Component>,
}
impl Panel {
pub fn new(content: impl super::Component + 'static) -> Self {
Self { title: None, style: Style::new(), border_style: Style::new(), content: Box::new(content) }
}
pub fn title(mut self, title: &str) -> Self {
self.title = Some(title.to_string());
self
}
pub fn style(mut self, style: Style) -> Self {
self.style = style;
self
}
pub fn border_style(mut self, style: Style) -> Self {
self.border_style = style;
self
}
}
impl super::Component for Panel {
fn render(&self, frame: &mut Frame, area: Rect) {
frame.render_panel(self.title.as_deref(), area, self.style.clone(), self.border_style.clone());
let content_area = area.shrink(1);
self.content.render(frame, content_area);
}
fn handle_event(&mut self, event: &Event) -> bool {
self.content.handle_event(event)
}
}