adding stuff to the column

This commit is contained in:
filipriec
2025-04-17 19:06:54 +02:00
parent 5e47c53fcf
commit 5c8557b369

View File

@@ -8,7 +8,7 @@ use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect}, layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Modifier, Style, Stylize}, style::{Modifier, Style, Stylize},
text::{Line, Span}, text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph}, widgets::{Block, BorderType, Borders, Paragraph, Cell, Row, Table},
Frame, Frame,
}; };
// Assuming render_canvas exists and works like in register.rs // Assuming render_canvas exists and works like in register.rs
@@ -19,9 +19,9 @@ pub fn render_add_table(
f: &mut Frame, f: &mut Frame,
area: Rect, area: Rect,
theme: &Theme, theme: &Theme,
app_state: &AppState, // Changed back from _app_state as it's needed for focus_outside_canvas check potentially app_state: &AppState,
add_table_state: &mut AddTableState, add_table_state: &mut AddTableState,
is_edit_mode: bool, // This comes from the main event loop based on AppMode is_edit_mode: bool,
highlight_state: &HighlightState, highlight_state: &HighlightState,
) { ) {
// Determine if focus is on canvas inputs vs other elements based on AddTableState // Determine if focus is on canvas inputs vs other elements based on AddTableState
@@ -71,19 +71,19 @@ pub fn render_add_table(
// Profile & Table Name section (Displays current state) // Profile & Table Name section (Displays current state)
let profile_text = Paragraph::new(vec![ let profile_text = Paragraph::new(vec![
Line::from(Span::styled( Line::from(Span::styled(
format!("profile: {}", add_table_state.profile_name), // Use actual profile format!("profile: {}", add_table_state.profile_name), // Use actual profile
theme.fg, theme.fg,
)), )),
Line::from(Span::styled( Line::from(Span::styled(
format!("table name: {}", add_table_state.table_name), // Use actual table name (from input) format!("table name: {}", add_table_state.table_name), // Use actual table name (from input)
theme.fg, theme.fg,
)), ))
]) ])
.block( .block(
Block::default() Block::default()
.borders(Borders::BOTTOM) .borders(Borders::BOTTOM)
.border_style(Style::default().fg(theme.secondary)), .border_style(Style::default().fg(theme.secondary)),
); );
f.render_widget(profile_text, left_vertical_chunks[0]); f.render_widget(profile_text, left_vertical_chunks[0]);
// --- Columns Table --- // --- Columns Table ---
@@ -94,18 +94,43 @@ pub fn render_add_table(
} else { } else {
Style::default().fg(theme.secondary) Style::default().fg(theme.secondary)
}; };
// TODO: Replace this Paragraph with a Table widget rendering add_table_state.columns // --- Create Table Rows from State ---
let columns_content = Paragraph::new(vec![ let column_rows: Vec<Row> = add_table_state
Line::from(Span::styled("Name Type", theme.accent)), // Header .columns
Line::from("... Column list placeholder ..."), // Placeholder content .iter()
]) .map(|col_def| {
.block( Row::new(vec![
Cell::from(col_def.name.clone()),
Cell::from(col_def.data_type.clone()),
])
.style(Style::default().fg(theme.fg))
})
.collect();
// --- Define Table Header ---
let header_cells = ["Name", "Type"]
.iter()
.map(|h| Cell::from(*h).style(Style::default().fg(theme.accent)));
let header = Row::new(header_cells).height(1).bottom_margin(1);
// --- Create the Table Widget ---
let columns_table = Table::new(column_rows, [Constraint::Percentage(50), Constraint::Percentage(50)])
.header(header)
.block(
Block::default() Block::default()
.title(Span::styled(" Columns ", theme.fg)) .title(Span::styled(" Columns ", theme.fg))
.borders(Borders::TOP) // Separator from Profile/Name .borders(Borders::TOP) // Separator from Profile/Name
.border_style(columns_border_style), // Indicate focus .border_style(columns_border_style),
)
.highlight_style(Style::default().add_modifier(Modifier::REVERSED).fg(theme.highlight)) // Style for selected row
.highlight_symbol(" > "); // Symbol for selected row
// --- Render the Table ---
f.render_stateful_widget(
columns_table,
left_vertical_chunks[1],
&mut add_table_state.column_table_state,
); );
f.render_widget(columns_content, left_vertical_chunks[1]);
// --- Indexes Table --- // --- Indexes Table ---
let indexes_focused = let indexes_focused =