pub mod dashboard;
pub mod detail;
pub mod editor;
pub mod error_modal;
pub mod help;
pub mod link_form;
pub mod run_form;
pub mod view_value;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::Frame;
use crate::app::{AppState, View};
use crate::components::{fuzzy_input, keybindings, modal, statusbar, toast};
use crate::theme::Theme;
pub fn render(frame: &mut Frame<'_>, app: &mut AppState, theme: &Theme) {
let area = frame.area();
let show_toast = app.toast_text().is_some();
let mut constraints: Vec<Constraint> = vec![Constraint::Min(1)];
if show_toast {
constraints.push(Constraint::Length(1));
}
constraints.push(Constraint::Length(keybindings::HEIGHT));
constraints.push(Constraint::Length(1));
let regions = Layout::vertical(constraints).split(area);
let Some(&body) = regions.first() else { return };
let Some(&status) = regions.last() else {
return;
};
let keybindings_idx = regions.len().saturating_sub(2);
let Some(&keybindings_rect) = regions.get(keybindings_idx) else {
return;
};
match app.current_view() {
View::Dashboard => dashboard::render(frame, body, app, theme),
View::Detail => detail::render(frame, body, app, theme),
}
keybindings::render(frame, keybindings_rect, app, theme);
statusbar::render(frame, status, app, theme);
if show_toast {
if let Some(&r) = regions.get(1) {
toast::render(frame, r, app, theme);
}
}
if app.is_filter_input_active() {
fuzzy_input::render(frame, centered(area, 50, 25), app, theme);
}
if app.help_visible() {
help::render(frame, centered(area, 60, 70), theme);
}
if app.is_form_visible() {
editor::render(frame, centered(area, 60, 35), app, theme);
}
if app.is_link_form_visible() {
link_form::render(frame, centered(area, 60, 30), app, theme);
}
if app.is_run_form_visible() {
run_form::render(frame, centered(area, 60, 30), app, theme);
}
if app.is_view_value_visible() {
view_value::render(frame, centered(area, 70, 40), app, theme);
}
if let Some(req) = app.current_confirm() {
modal::render(frame, centered(area, 50, 25), req, theme);
}
if app.is_error_modal_visible() {
error_modal::render(frame, centered(area, 60, 50), app, theme);
}
}
fn centered(outer: Rect, pct_x: u16, pct_y: u16) -> Rect {
let [_, mid_v, _] = Layout::vertical([
Constraint::Percentage((100 - pct_y) / 2),
Constraint::Percentage(pct_y),
Constraint::Percentage((100 - pct_y) / 2),
])
.areas(outer);
let [_, mid_h, _] = Layout::horizontal([
Constraint::Percentage((100 - pct_x) / 2),
Constraint::Percentage(pct_x),
Constraint::Percentage((100 - pct_x) / 2),
])
.areas(mid_v);
mid_h
}