displaying admin panel properly well
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
// src/ui/handlers/render.rs
|
// src/ui/handlers/render.rs
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
render_background,
|
render_background,
|
||||||
render_command_line,
|
render_command_line,
|
||||||
render_status_line,
|
render_status_line,
|
||||||
handlers::{sidebar::{self, calculate_sidebar_layout}, intro, admin_panel::AdminPanelState},
|
handlers::{sidebar::{self, calculate_sidebar_layout}, intro, admin_panel::AdminPanelState, form::render_form},
|
||||||
};
|
};
|
||||||
use crate::config::colors::Theme;
|
use crate::config::colors::Theme;
|
||||||
use ratatui::layout::{Constraint, Direction, Layout};
|
use ratatui::layout::{Constraint, Direction, Layout};
|
||||||
@@ -28,61 +29,55 @@ pub fn render_ui(
|
|||||||
) {
|
) {
|
||||||
render_background(f, f.area(), theme);
|
render_background(f, f.area(), theme);
|
||||||
|
|
||||||
if app_state.ui.show_intro {
|
|
||||||
intro_state.render(f, f.area(), theme);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let root = Layout::default()
|
let root = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Min(10),
|
Constraint::Min(1),
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
])
|
])
|
||||||
.split(f.area());
|
.split(f.area());
|
||||||
|
|
||||||
let main_content_area = root[0];
|
let main_content_area = root[0];
|
||||||
let (sidebar_area, form_area) = if app_state.ui.show_admin {
|
if app_state.ui.show_intro {
|
||||||
(None, main_content_area)
|
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 {
|
} else {
|
||||||
calculate_sidebar_layout(app_state.ui.show_sidebar, main_content_area)
|
let (sidebar_area, form_area) = calculate_sidebar_layout(
|
||||||
};
|
app_state.ui.show_sidebar,
|
||||||
let available_width = form_area.width;
|
main_content_area
|
||||||
|
);
|
||||||
|
|
||||||
let form_constraint = if available_width >= 80 {
|
if let Some(sidebar_rect) = sidebar_area {
|
||||||
Layout::default()
|
sidebar::render_sidebar(f, sidebar_rect, theme, &app_state.profile_tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
let form_constraint = Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Min(0),
|
Constraint::Min(0),
|
||||||
Constraint::Length(80),
|
Constraint::Length(80.min(form_area.width)),
|
||||||
Constraint::Min(0),
|
Constraint::Min(0),
|
||||||
])
|
])
|
||||||
.split(main_content_area)[1]
|
.split(form_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(
|
// Convert fields to &[&str] and values to &[&String]
|
||||||
f,
|
let fields: Vec<&str> = form_state.fields.iter().map(|s| s.as_str()).collect();
|
||||||
form_constraint,
|
let values: Vec<&String> = form_state.values.iter().collect();
|
||||||
theme,
|
|
||||||
is_edit_mode,
|
|
||||||
total_count,
|
|
||||||
current_position,
|
|
||||||
);
|
|
||||||
|
|
||||||
if app_state.ui.show_admin {
|
render_form(
|
||||||
admin_panel_state.render(f, form_area, theme);
|
f,
|
||||||
} else if let Some(sidebar_rect) = sidebar_area {
|
form_constraint,
|
||||||
sidebar::render_sidebar(f, sidebar_rect, theme, &app_state.profile_tree);
|
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_status_line(f, root[1], current_dir, theme, is_edit_mode);
|
||||||
|
|||||||
Reference in New Issue
Block a user