96 lines
2.5 KiB
Rust
96 lines
2.5 KiB
Rust
// src/ui/handlers/render.rs
|
|
|
|
use crate::components::{render_background, render_command_line, render_status_line};
|
|
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.size(), theme);
|
|
|
|
// Root layout - vertical split for main content, status, and command line
|
|
let root = Layout::default()
|
|
.direction(Direction::Vertical)
|
|
.constraints([
|
|
Constraint::Min(10), // Main content area
|
|
Constraint::Length(1), // Status line
|
|
Constraint::Length(1), // Command line
|
|
])
|
|
.split(f.area());
|
|
|
|
// Main content area layout
|
|
let main_content_area = root[0];
|
|
|
|
// Split into sidebar + content or just content
|
|
let (sidebar_area, content_area) = if ui_state.show_sidebar {
|
|
let chunks = Layout::default()
|
|
.direction(Direction::Horizontal)
|
|
.constraints([
|
|
Constraint::Length(16), // Fixed sidebar width
|
|
Constraint::Fill(1), // Remaining space for form/preview
|
|
])
|
|
.split(main_content_area);
|
|
(Some(chunks[0]), chunks[1])
|
|
} else {
|
|
(None, main_content_area)
|
|
};
|
|
|
|
// Create centered form layout
|
|
let form_layout = Layout::default()
|
|
.direction(Direction::Horizontal)
|
|
.constraints([
|
|
Constraint::Min(0),
|
|
Constraint::Max(80),
|
|
Constraint::Min(0),
|
|
])
|
|
.split(content_area);
|
|
|
|
// Render form in the left content area
|
|
form_state.render(
|
|
f,
|
|
form_layout[1],
|
|
theme,
|
|
is_edit_mode,
|
|
total_count,
|
|
current_position,
|
|
);
|
|
|
|
// Render sidebar if enabled
|
|
if let Some(sidebar_rect) = sidebar_area {
|
|
crate::components::handlers::sidebar::render_sidebar(f, sidebar_rect, theme);
|
|
}
|
|
|
|
// Status line
|
|
render_status_line(
|
|
f,
|
|
root[1],
|
|
current_dir,
|
|
theme,
|
|
is_edit_mode,
|
|
);
|
|
|
|
// Command line
|
|
render_command_line(
|
|
f,
|
|
root[2],
|
|
command_input,
|
|
command_mode,
|
|
theme,
|
|
command_message,
|
|
);
|
|
}
|