Files
komp_ac/client/src/ui/handlers/render.rs
2025-03-21 22:20:43 +01:00

78 lines
2.1 KiB
Rust

// src/ui/handlers/render.rs
use crate::components::{
render_background,
render_command_line,
render_status_line,
handlers::sidebar::{self, calculate_sidebar_layout}
};
use crate::config::colors::Theme;
use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame;
use super::form::FormState;
use crate::state::state::UiState;
pub fn render_ui(
f: &mut Frame,
form_state: &mut FormState,
theme: &Theme,
is_edit_mode: bool,
total_count: u64,
current_position: u64,
current_dir: &str,
command_input: &str,
command_mode: bool,
command_message: &str,
ui_state: &UiState,
) {
render_background(f, f.area(), theme);
let root = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Min(10),
Constraint::Length(1),
Constraint::Length(1),
])
.split(f.area());
let main_content_area = root[0];
let (sidebar_area, form_area) = calculate_sidebar_layout(ui_state.show_sidebar, main_content_area);
let available_width = form_area.width;
let form_constraint = if available_width >= 80 {
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Min(0),
Constraint::Length(80),
Constraint::Min(0),
])
.split(main_content_area)[1]
} else {
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Min(0),
Constraint::Length(80.min(available_width)),
Constraint::Min(0),
])
.split(form_area)[1]
};
form_state.render(
f,
form_constraint,
theme,
is_edit_mode,
total_count,
current_position,
);
if let Some(sidebar_rect) = sidebar_area {
sidebar::render_sidebar(f, sidebar_rect, theme, &ui_state.profile_tree);
}
render_status_line(f, root[1], current_dir, theme, is_edit_mode);
render_command_line(f, root[2], command_input, command_mode, theme, command_message);
}