yazi/yazi-fm/src/root.rs

50 lines
1.2 KiB
Rust
Raw Normal View History

use ratatui::{buffer::Buffer, layout::{Constraint, Layout, Rect}, widgets::Widget};
2023-07-08 14:46:43 +03:00
use super::{completion, input, select, tasks, which};
use crate::{components, help, Ctx};
2023-07-08 14:46:43 +03:00
pub(super) struct Root<'a> {
cx: &'a Ctx,
2023-07-08 14:46:43 +03:00
}
impl<'a> Root<'a> {
pub(super) fn new(cx: &'a Ctx) -> Self { Self { cx } }
2023-07-08 14:46:43 +03:00
}
impl<'a> Widget for Root<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks =
Layout::vertical([Constraint::Length(1), Constraint::Fill(1), Constraint::Length(1)])
.split(area);
2023-07-08 14:46:43 +03:00
components::Header.render(chunks[0], buf);
components::Manager.render(chunks[1], buf);
components::Status.render(chunks[2], buf);
components::Preview::new(self.cx).render(area, buf);
2023-07-08 14:46:43 +03:00
if self.cx.tasks.visible {
tasks::Layout::new(self.cx).render(area, buf);
}
if self.cx.select.visible {
select::Select::new(self.cx).render(area, buf);
}
2023-07-08 14:46:43 +03:00
if self.cx.input.visible {
input::Input::new(self.cx).render(area, buf);
2023-07-08 14:46:43 +03:00
}
if self.cx.help.visible {
2023-08-31 08:58:13 +03:00
help::Layout::new(self.cx).render(area, buf);
}
if self.cx.completion.visible {
completion::Completion::new(self.cx).render(area, buf);
}
if self.cx.which.visible {
which::Which::new(self.cx).render(area, buf);
}
2023-07-08 14:46:43 +03:00
}
}