border fixed

This commit is contained in:
filipriec
2025-04-05 17:34:26 +02:00
parent 1c662888c6
commit 0219dc0ede

View File

@@ -4,13 +4,13 @@ use crate::{
config::colors::themes::Theme, config::colors::themes::Theme,
state::pages::auth::AuthState, state::pages::auth::AuthState,
components::common::dialog, components::common::dialog,
state::state::AppState, // Add this import state::state::AppState,
}; };
use ratatui::{ use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect, Margin}, layout::{Alignment, Constraint, Direction, Layout, Rect, Margin},
style::{Style, Modifier, Color}, // Removed unused Color import style::{Style, Modifier, Color},
widgets::{Block, BorderType, Borders, Paragraph}, widgets::{Block, BorderType, Borders, Paragraph},
Frame, // Removed unused Span import Frame,
}; };
pub fn render_login( pub fn render_login(
@@ -18,7 +18,7 @@ pub fn render_login(
area: Rect, area: Rect,
theme: &Theme, theme: &Theme,
state: &AuthState, state: &AuthState,
app_state: &AppState, // Add AppState parameter app_state: &AppState,
is_edit_mode: bool, is_edit_mode: bool,
) { ) {
// Main container // Main container
@@ -47,24 +47,10 @@ pub fn render_login(
.split(inner_area); .split(inner_area);
// --- FORM RENDERING --- // --- FORM RENDERING ---
let input_block = Block::default() // Directly pass the form area to canvas for border handling
.borders(Borders::ALL)
.border_style(if is_edit_mode {
Style::default().fg(theme.accent)
} else {
Style::default().fg(theme.border)
})
.style(Style::default().bg(theme.bg));
// Calculate inner area BEFORE rendering
let input_area = input_block.inner(chunks[0]);
f.render_widget(input_block, chunks[0]);
// Use the canvas renderer for fields
crate::components::handlers::canvas::render_canvas( crate::components::handlers::canvas::render_canvas(
f, f,
input_area, // Use the pre-calculated area chunks[0],
state, state,
&["Username/Email", "Password"], &["Username/Email", "Password"],
&state.current_field, &state.current_field,
@@ -73,7 +59,17 @@ pub fn render_login(
is_edit_mode, is_edit_mode,
); );
// --- BUTTONS --- (Keep this unchanged) // --- ERROR MESSAGE ---
if let Some(err) = &state.error_message {
f.render_widget(
Paragraph::new(err.as_str())
.style(Style::default().fg(Color::Red))
.alignment(Alignment::Center),
chunks[1],
);
}
// --- BUTTONS ---
let button_chunks = Layout::default() let button_chunks = Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)]) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
@@ -123,20 +119,11 @@ pub fn render_login(
button_chunks[1], button_chunks[1],
); );
// Error message // --- DIALOG ---
if let Some(err) = &state.error_message {
f.render_widget(
Paragraph::new(err.as_str())
.style(Style::default().fg(Color::Red))
.alignment(Alignment::Center),
chunks[1],
);
}
if app_state.ui.dialog.show_dialog { if app_state.ui.dialog.show_dialog {
dialog::render_dialog( dialog::render_dialog(
f, f,
f.area(), // Use area() instead of deprecated size() f.size(),
theme, theme,
&app_state.ui.dialog.dialog_title, &app_state.ui.dialog.dialog_title,
&app_state.ui.dialog.dialog_message, &app_state.ui.dialog.dialog_message,