working perfectly well
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
// src/components/handlers/sidebar.rs
|
||||
use ratatui::{
|
||||
widgets::{Block, List, ListItem},
|
||||
layout::Rect,
|
||||
layout::{Rect, Direction, Layout, Constraint},
|
||||
style::Style,
|
||||
text::Text,
|
||||
Frame,
|
||||
};
|
||||
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) {
|
||||
let sidebar_block = Block::default()
|
||||
.style(Style::default().bg(theme.bg));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user