working perfectly well

This commit is contained in:
filipriec
2025-03-21 19:56:07 +01:00
parent 8ce90f3c42
commit 8b2120bdc8
2 changed files with 34 additions and 54 deletions

View File

@@ -1,6 +1,10 @@
// src/ui/handlers/render.rs
use crate::components::{render_background, render_command_line, render_status_line};
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;
@@ -20,44 +24,22 @@ pub fn render_ui(
command_message: &str,
ui_state: &UiState,
) {
// Render background first
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
Constraint::Min(10),
Constraint::Length(1),
Constraint::Length(1),
])
.split(f.size());
// Main content area layout
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;
// Calculate available width for form
let full_width = main_content_area.width;
let sidebar_width = if ui_state.show_sidebar { 16 } else { 0 };
let available_width = full_width.saturating_sub(sidebar_width);
// Create layout chunks based on available space
let (sidebar_area, form_area) = if ui_state.show_sidebar {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(sidebar_width),
Constraint::Min(0),
])
.split(main_content_area);
(Some(chunks[0]), chunks[1])
} else {
(None, main_content_area)
};
// Center form in available space or full width depending on space
let form_constraint = if available_width >= 80 {
// Center in full width if there's enough space
Layout::default()
.direction(Direction::Horizontal)
.constraints([
@@ -65,9 +47,8 @@ pub fn render_ui(
Constraint::Length(80),
Constraint::Min(0),
])
.split(main_content_area)[1] // Use full width centering
.split(main_content_area)[1]
} else {
// Center in remaining space
Layout::default()
.direction(Direction::Horizontal)
.constraints([
@@ -75,10 +56,9 @@ pub fn render_ui(
Constraint::Length(80.min(available_width)),
Constraint::Min(0),
])
.split(form_area)[1] // Use remaining space centering
.split(form_area)[1]
};
// Render form in the calculated area
form_state.render(
f,
form_constraint,
@@ -88,27 +68,10 @@ pub fn render_ui(
current_position,
);
// Render sidebar if enabled
if let Some(sidebar_rect) = sidebar_area {
crate::components::handlers::sidebar::render_sidebar(f, sidebar_rect, theme);
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,
);
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);
}