rustic_rs/commands/tui/widgets/
popup.rs1use super::{Clear, Constraint, Draw, Event, Frame, Layout, ProcessEvent, Rect, SizedWidget};
2
3pub struct PopUp<T>(pub T);
5
6impl<T: ProcessEvent> ProcessEvent for PopUp<T> {
7 type Result = T::Result;
8 fn input(&mut self, event: Event) -> Self::Result {
9 self.0.input(event)
10 }
11}
12
13impl<T: Draw + SizedWidget> Draw for PopUp<T> {
14 fn draw(&mut self, mut area: Rect, f: &mut Frame<'_>) {
15 if let Some(h) = self.0.height() {
17 let layout = Layout::vertical([
18 Constraint::Min(1),
19 Constraint::Length(h),
20 Constraint::Min(1),
21 ]);
22 area = layout.split(area)[1];
23 }
24
25 if let Some(w) = self.0.width() {
27 let layout = Layout::horizontal([
28 Constraint::Min(1),
29 Constraint::Length(w),
30 Constraint::Min(1),
31 ]);
32 area = layout.split(area)[1];
33 }
34
35 f.render_widget(Clear, area);
36 self.0.draw(area, f);
37 }
38}