use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame;
use crate::app::{App, AppScreen};
use crate::features;
use crate::widgets;
pub fn render(app: &mut App, frame: &mut Frame) {
match app.screen {
AppScreen::Welcome => {
features::repo::view::render(&*app, frame, frame.area());
}
AppScreen::DirBrowser => {
features::repo::view::render_browser(app, frame, frame.area());
}
AppScreen::Main => {
render_main(app, frame);
}
}
}
fn render_main(app: &mut App, frame: &mut Frame) {
let outer = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3),
Constraint::Min(10),
Constraint::Length(12),
Constraint::Length(1),
])
.split(frame.area());
widgets::header::render(app, frame, outer[0]);
let longest_branch = app
.tab()
.branches
.iter()
.map(|b| b.name.chars().count())
.max()
.unwrap_or(10);
let ideal_sidebar = (longest_branch + 6) as u16;
let term_width = outer[1].width;
let max_sidebar = (term_width * 30 / 100).clamp(22, 50);
let sidebar_width = ideal_sidebar.min(max_sidebar).max(22);
let main_cols = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(sidebar_width),
Constraint::Percentage(40),
Constraint::Min(20),
])
.split(outer[1]);
let sidebar = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Min(6), Constraint::Length(5), Constraint::Length(5), ])
.split(main_cols[0]);
features::branches::view::render(app, frame, sidebar[0]);
features::stash::view::render(app, frame, sidebar[1]);
features::remotes::view::render(app, frame, sidebar[2]);
features::commits::view::render(app, frame, main_cols[1]);
if app.show_theme_panel {
features::theme::view::render(app, frame, main_cols[2]);
} else if app.show_options_panel {
features::options::view::render(app, frame, main_cols[2]);
} else {
features::diff::view::render(app, frame, main_cols[2]);
}
features::staging::view::render(app, frame, outer[2]);
widgets::status_bar::render(app, frame, outer[3]);
}