use derive_builder::Builder;
use ratatui::{
buffer::Buffer,
layout::Rect,
style::Style,
text::Line,
widgets::{Block, BorderType, Borders, Clear, Widget},
};
use crate::ui::widget::Shortcuts;
#[derive(Builder, Clone, Debug)]
#[builder(pattern = "owned")]
pub struct PopupWindow {
title: Line<'static>,
border_style: Style,
border_type: BorderType,
background: Style,
#[builder(default)]
shortcuts: Option<Shortcuts<'static>>,
}
impl PopupWindow {
pub fn builder() -> PopupWindowBuilder {
PopupWindowBuilder::default()
}
fn window_block(&self) -> Block {
let w = Block::new()
.borders(Borders::ALL)
.title_style(self.border_style)
.title(self.title.clone())
.border_style(self.border_style)
.border_type(self.border_type)
.style(self.background);
match self.shortcuts.as_ref() {
Some(shortcuts) => w.title_bottom(shortcuts.as_line()),
None => w,
}
}
}
impl Widget for PopupWindow {
fn render(self, area: Rect, buf: &mut Buffer)
where
Self: Sized,
{
Clear.render(area, buf);
self.window_block().render(area, buf);
}
}