102 lines
3.2 KiB
Rust
102 lines
3.2 KiB
Rust
// src/ui/handlers/render.rs
|
|
|
|
use crate::components::{
|
|
render_background,
|
|
render_command_line,
|
|
render_status_line,
|
|
handlers::{sidebar::{self, calculate_sidebar_layout}, admin_panel::AdminPanelState, form::render_form},
|
|
intro::{intro},
|
|
};
|
|
use crate::config::colors::Theme;
|
|
use ratatui::layout::{Constraint, Direction, Layout};
|
|
use ratatui::Frame;
|
|
use super::form::FormState;
|
|
use crate::state::state::AppState;
|
|
|
|
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,
|
|
app_state: &AppState,
|
|
intro_state: &intro::IntroState,
|
|
admin_panel_state: &AdminPanelState,
|
|
) {
|
|
render_background(f, f.area(), theme);
|
|
|
|
let root = Layout::default()
|
|
.direction(Direction::Vertical)
|
|
.constraints([
|
|
Constraint::Min(1),
|
|
Constraint::Length(1),
|
|
Constraint::Length(1),
|
|
])
|
|
.split(f.area());
|
|
|
|
let main_content_area = root[0];
|
|
if app_state.ui.show_intro {
|
|
intro_state.render(f, main_content_area, theme);
|
|
} else if app_state.ui.show_admin {
|
|
admin_panel_state.render(f, main_content_area, theme);
|
|
} else {
|
|
let (sidebar_area, form_area) = calculate_sidebar_layout(
|
|
app_state.ui.show_sidebar,
|
|
main_content_area
|
|
);
|
|
|
|
if let Some(sidebar_rect) = sidebar_area {
|
|
sidebar::render_sidebar(f, sidebar_rect, theme, &app_state.profile_tree);
|
|
}
|
|
|
|
// This change makes the form stay stationary when toggling sidebar
|
|
let available_width = form_area.width;
|
|
let form_constraint = if available_width >= 80 {
|
|
// Use main_content_area for centering when enough space
|
|
Layout::default()
|
|
.direction(Direction::Horizontal)
|
|
.constraints([
|
|
Constraint::Min(0),
|
|
Constraint::Length(80),
|
|
Constraint::Min(0),
|
|
])
|
|
.split(main_content_area)[1]
|
|
} else {
|
|
// Use form_area (post sidebar) when limited space
|
|
Layout::default()
|
|
.direction(Direction::Horizontal)
|
|
.constraints([
|
|
Constraint::Min(0),
|
|
Constraint::Length(80.min(available_width)),
|
|
Constraint::Min(0),
|
|
])
|
|
.split(form_area)[1]
|
|
};
|
|
|
|
// Convert fields to &[&str] and values to &[&String]
|
|
let fields: Vec<&str> = form_state.fields.iter().map(|s| s.as_str()).collect();
|
|
let values: Vec<&String> = form_state.values.iter().collect();
|
|
|
|
render_form(
|
|
f,
|
|
form_constraint,
|
|
form_state,
|
|
&fields,
|
|
&form_state.current_field,
|
|
&values,
|
|
theme,
|
|
is_edit_mode,
|
|
total_count,
|
|
current_position,
|
|
);
|
|
}
|
|
|
|
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);
|
|
}
|