text area working now perfectly well

This commit is contained in:
filipriec
2025-05-24 16:34:59 +02:00
parent a874edf2a1
commit 56fe1c2ccc
5 changed files with 249 additions and 376 deletions

View File

@@ -6,9 +6,9 @@ use crate::state::pages::add_logic::{AddLogicFocus, AddLogicState};
use crate::state::pages::canvas_state::CanvasState;
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, Paragraph},
style::{Modifier, Style, Stylize}, // Added Stylize for .dim()
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph}, // Removed unused Widget
Frame,
};
use crate::components::handlers::canvas::render_canvas;
@@ -33,39 +33,43 @@ pub fn render_add_logic(
let inner_area = main_block.inner(area);
f.render_widget(main_block, area);
// --- Fullscreen Script Content Check ---
if add_logic_state.current_focus == AddLogicFocus::InputScriptContent {
let script_block_border_style = Style::default().fg(theme.highlight); // Always highlighted
let mut editor = add_logic_state.script_content_editor.borrow_mut();
let border_style = if is_edit_mode {
Style::default().fg(theme.highlight)
} else {
Style::default().fg(theme.highlight)
};
let script_block = Block::default()
.title(Span::styled(
" Steel Script Content (Fullscreen) ",
theme.fg,
)) // Indicate fullscreen
.title_alignment(Alignment::Center)
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(script_block_border_style);
editor.set_cursor_line_style(
Style::default().bg(theme.secondary),
);
editor.set_line_number_style(
Style::default().fg(theme.secondary),
);
let script_text =
Text::from(add_logic_state.script_content_input.as_str());
let script_paragraph = Paragraph::new(script_text)
.block(script_block)
.scroll(add_logic_state.script_content_scroll)
.style(Style::default().fg(theme.fg));
f.render_widget(script_paragraph, inner_area); // Use inner_area for fullscreen
return; // IMPORTANT: Stop rendering here for fullscreen mode
editor.set_block(
Block::default()
.title(Span::styled(
" Steel Script Content (Ctrl+E or Enter to edit, Esc to unfocus/exit edit) ",
Style::default().fg(theme.fg),
))
.title_alignment(Alignment::Center)
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(border_style),
);
f.render_widget(&*editor, inner_area);
return;
}
// --- Normal Layout ---
// Calculate areas dynamically
let main_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3), // Top Info (Profile/Table)
Constraint::Length(9), // Canvas Area (3 input fields × 3 lines each)
Constraint::Min(5), // Script Content Area
Constraint::Length(3), // Bottom Buttons
Constraint::Length(3),
Constraint::Length(9),
Constraint::Min(5),
Constraint::Length(3),
])
.split(inner_area);
@@ -74,21 +78,22 @@ pub fn render_add_logic(
let script_content_area = main_chunks[2];
let buttons_area = main_chunks[3];
// Top Info Rendering
let profile_text = Paragraph::new(vec![
Line::from(Span::styled(
format!("Profile: {}", add_logic_state.profile_name),
theme.fg,
Style::default().fg(theme.fg),
)),
Line::from(Span::styled(
format!(
"Table: {}",
add_logic_state
.selected_table_id
.map(|id| format!("ID {}", id))
.unwrap_or_else(|| "Global".to_string())
.selected_table_name
.clone()
.unwrap_or_else(|| add_logic_state.selected_table_id
.map(|id| format!("ID {}", id))
.unwrap_or_else(|| "Global (Not Selected)".to_string()))
),
theme.fg,
Style::default().fg(theme.fg),
)),
])
.block(
@@ -98,7 +103,6 @@ pub fn render_add_logic(
);
f.render_widget(profile_text, top_info_area);
// Canvas rendering for input fields
let focus_on_canvas_inputs = matches!(
add_logic_state.current_focus,
AddLogicFocus::InputLogicName
@@ -118,29 +122,23 @@ pub fn render_add_logic(
highlight_state,
);
// Script Content Area (Normal Mode)
let script_block_border_style =
if add_logic_state.current_focus == AddLogicFocus::InputScriptContent {
Style::default().fg(theme.highlight)
} else {
Style::default().fg(theme.secondary)
};
{
let mut editor = add_logic_state.script_content_editor.borrow_mut();
editor.set_cursor_line_style(Style::default());
editor.set_line_number_style(
Style::default().fg(theme.secondary).dim(), // Fixed: apply .dim() to Style, not Color
);
let script_block = Block::default()
.title(" Steel Script Content ")
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(script_block_border_style);
editor.set_block(
Block::default()
.title(" Steel Script Content ")
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(theme.secondary)),
);
f.render_widget(&*editor, script_content_area);
}
let script_text =
Text::from(add_logic_state.script_content_input.as_str());
let script_paragraph = Paragraph::new(script_text)
.block(script_block)
.scroll(add_logic_state.script_content_scroll)
.style(Style::default().fg(theme.fg));
f.render_widget(script_paragraph, script_content_area);
// Button Style Helpers
let get_button_style = |button_focus: AddLogicFocus, current_focus| {
let is_focused = current_focus == button_focus;
let base_style = Style::default().fg(if is_focused {
@@ -163,12 +161,11 @@ pub fn render_add_logic(
}
};
// Bottom Buttons
let button_chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage(50), // Save Button
Constraint::Percentage(50), // Cancel Button
Constraint::Percentage(50),
Constraint::Percentage(50),
])
.split(buttons_area);
@@ -206,7 +203,6 @@ pub fn render_add_logic(
);
f.render_widget(cancel_button, button_chunks[1]);
// Dialog rendering
if app_state.ui.dialog.dialog_show {
dialog::render_dialog(
f,