2023-07-08 14:46:43 +03:00
|
|
|
use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, widgets::Widget};
|
|
|
|
|
2023-07-24 02:26:16 +03:00
|
|
|
use super::{header, manager, status, tasks, which::Which, Ctx, Input, Select};
|
2023-07-08 14:46:43 +03:00
|
|
|
|
|
|
|
pub struct Root<'a> {
|
|
|
|
cx: &'a mut Ctx,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Root<'a> {
|
|
|
|
pub fn new(cx: &'a mut Ctx) -> Self { Self { cx } }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Widget for Root<'a> {
|
|
|
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
2023-07-24 02:56:08 +03:00
|
|
|
let chunks = Layout::new()
|
2023-07-08 14:46:43 +03:00
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)].as_ref())
|
|
|
|
.split(area);
|
|
|
|
|
|
|
|
header::Layout::new(self.cx).render(chunks[0], buf);
|
|
|
|
manager::Layout::new(self.cx).render(chunks[1], buf);
|
|
|
|
status::Layout::new(self.cx).render(chunks[2], buf);
|
|
|
|
|
|
|
|
if self.cx.tasks.visible {
|
|
|
|
tasks::Layout::new(self.cx).render(area, buf);
|
|
|
|
}
|
|
|
|
|
2023-07-18 17:23:27 +03:00
|
|
|
if self.cx.select.visible {
|
|
|
|
Select::new(self.cx).render(area, buf);
|
|
|
|
}
|
|
|
|
|
2023-07-08 14:46:43 +03:00
|
|
|
if self.cx.input.visible {
|
|
|
|
Input::new(self.cx).render(area, buf);
|
|
|
|
self.cx.cursor = Some(self.cx.input.cursor());
|
|
|
|
} else {
|
|
|
|
self.cx.cursor = None;
|
|
|
|
}
|
2023-07-24 02:26:16 +03:00
|
|
|
|
|
|
|
if self.cx.which.visible {
|
|
|
|
Which::new(self.cx).render(area, buf);
|
|
|
|
}
|
2023-07-08 14:46:43 +03:00
|
|
|
}
|
|
|
|
}
|