step2 compiled

This commit is contained in:
filipriec
2025-03-30 18:41:27 +02:00
parent 12aec72141
commit 2180d8decf
2 changed files with 16 additions and 57 deletions

View File

@@ -16,6 +16,7 @@ pub fn render_login(
area: Rect, area: Rect,
theme: &Theme, theme: &Theme,
state: &AuthState, state: &AuthState,
is_edit_mode: bool,
) { ) {
// Main container // Main container
let block = Block::default() let block = Block::default()
@@ -43,75 +44,33 @@ pub fn render_login(
.split(inner_area); .split(inner_area);
// --- FORM RENDERING --- // --- FORM RENDERING ---
let fields = &["Username/Email", "Password"];
let inputs = &[&state.username, &state.password];
let current_field = state.current_field;
// Create input container (store the inner area before rendering)
let input_block = Block::default() let input_block = Block::default()
.borders(Borders::ALL) .borders(Borders::ALL)
.border_style(if !state.return_selected { .border_style(if is_edit_mode {
Style::default().fg(theme.accent) Style::default().fg(theme.accent)
} else { } else {
Style::default().fg(theme.border) Style::default().fg(theme.border)
}) })
.style(Style::default().bg(theme.bg)); .style(Style::default().bg(theme.bg));
// Calculate inner area before consuming input_block // Calculate inner area BEFORE rendering
let input_area = input_block.inner(chunks[0]); let input_area = input_block.inner(chunks[0]);
// Now render the widget
f.render_widget(input_block, chunks[0]); f.render_widget(input_block, chunks[0]);
let input_layout = Layout::default() // Use the canvas renderer for fields
.direction(Direction::Horizontal) crate::components::handlers::canvas::render_canvas(
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)]) f,
.split(input_area); input_area, // Use the pre-calculated area
state,
// Render field labels &["Username/Email", "Password"],
for (i, field) in fields.iter().enumerate() { &state.current_field,
f.render_widget( &[&state.username, &state.password],
Paragraph::new(Line::from(Span::styled( theme,
format!("{}:", field), is_edit_mode,
Style::default().fg(theme.fg),
))),
Rect {
x: input_layout[0].x,
y: input_layout[0].y + i as u16,
width: input_layout[0].width,
height: 1,
},
);
}
// Render input fields
let input_rows = Layout::default()
.direction(Direction::Vertical)
.constraints(vec![Constraint::Length(1); fields.len()])
.split(input_layout[1]);
for (i, input) in inputs.iter().enumerate() {
let is_active = i == current_field;
let mut style = Style::default().fg(theme.fg);
if is_active {
style = style.fg(theme.highlight);
}
f.render_widget(
Paragraph::new(input.as_str()).style(style),
input_rows[i],
); );
// Set cursor position if active // --- BUTTONS --- (Keep this unchanged)
if is_active {
f.set_cursor_position((
input_rows[i].x + state.current_cursor_pos as u16,
input_rows[i].y,
));
}
}
// --- 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)])

View File

@@ -47,7 +47,7 @@ pub fn render_ui(
// Use app_state's intro_state directly // Use app_state's intro_state directly
app_state.ui.intro_state.render(f, main_content_area, theme); app_state.ui.intro_state.render(f, main_content_area, theme);
}else if app_state.ui.show_login { }else if app_state.ui.show_login {
render_login(f, main_content_area, theme, auth_state); render_login(f, main_content_area, theme, auth_state, false);
} else if app_state.ui.show_admin { } else if app_state.ui.show_admin {
// Create temporary AdminPanelState for rendering // Create temporary AdminPanelState for rendering
let mut admin_state = AdminPanelState::new( let mut admin_state = AdminPanelState::new(