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,13 +1,30 @@
// src/components/handlers/sidebar.rs // src/components/handlers/sidebar.rs
use ratatui::{ use ratatui::{
widgets::{Block, List, ListItem}, widgets::{Block, List, ListItem},
layout::Rect, layout::{Rect, Direction, Layout, Constraint},
style::Style, style::Style,
text::Text, text::Text,
Frame, Frame,
}; };
use crate::config::colors::Theme; use crate::config::colors::Theme;
const SIDEBAR_WIDTH: u16 = 16;
pub fn calculate_sidebar_layout(show_sidebar: bool, main_content_area: Rect) -> (Option<Rect>, Rect) {
if 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)
}
}
pub fn render_sidebar(f: &mut Frame, area: Rect, theme: &Theme) { pub fn render_sidebar(f: &mut Frame, area: Rect, theme: &Theme) {
let sidebar_block = Block::default() let sidebar_block = Block::default()
.style(Style::default().bg(theme.bg)); .style(Style::default().bg(theme.bg));

View File

@@ -1,6 +1,10 @@
// src/ui/handlers/render.rs // src/ui/handlers/render.rs
use crate::components::{
use crate::components::{render_background, render_command_line, render_status_line}; render_background,
render_command_line,
render_status_line,
handlers::sidebar::{self, calculate_sidebar_layout}
};
use crate::config::colors::Theme; use crate::config::colors::Theme;
use ratatui::layout::{Constraint, Direction, Layout}; use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame; use ratatui::Frame;
@@ -20,44 +24,22 @@ pub fn render_ui(
command_message: &str, command_message: &str,
ui_state: &UiState, ui_state: &UiState,
) { ) {
// Render background first
render_background(f, f.size(), theme); render_background(f, f.size(), theme);
// Root layout - vertical split for main content, status, and command line
let root = Layout::default() let root = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([ .constraints([
Constraint::Min(10), // Main content area Constraint::Min(10),
Constraint::Length(1), // Status line Constraint::Length(1),
Constraint::Length(1), // Command line Constraint::Length(1),
]) ])
.split(f.size()); .split(f.size());
// Main content area layout
let main_content_area = root[0]; 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 { let form_constraint = if available_width >= 80 {
// Center in full width if there's enough space
Layout::default() Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints([ .constraints([
@@ -65,9 +47,8 @@ pub fn render_ui(
Constraint::Length(80), Constraint::Length(80),
Constraint::Min(0), Constraint::Min(0),
]) ])
.split(main_content_area)[1] // Use full width centering .split(main_content_area)[1]
} else { } else {
// Center in remaining space
Layout::default() Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints([ .constraints([
@@ -75,10 +56,9 @@ pub fn render_ui(
Constraint::Length(80.min(available_width)), Constraint::Length(80.min(available_width)),
Constraint::Min(0), Constraint::Min(0),
]) ])
.split(form_area)[1] // Use remaining space centering .split(form_area)[1]
}; };
// Render form in the calculated area
form_state.render( form_state.render(
f, f,
form_constraint, form_constraint,
@@ -88,27 +68,10 @@ pub fn render_ui(
current_position, current_position,
); );
// Render sidebar if enabled
if let Some(sidebar_rect) = sidebar_area { 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);
render_status_line( render_command_line(f, root[2], command_input, command_mode, theme, command_message);
f,
root[1],
current_dir,
theme,
is_edit_mode,
);
// Command line
render_command_line(
f,
root[2],
command_input,
command_mode,
theme,
command_message,
);
} }