67 lines
1.7 KiB
Rust
67 lines
1.7 KiB
Rust
// src/components/handlers/form.rs
|
|
use ratatui::{
|
|
widgets::{Paragraph, Block, Borders},
|
|
layout::{Layout, Constraint, Direction, Rect, Margin, Alignment},
|
|
style::Style,
|
|
Frame,
|
|
};
|
|
use crate::config::colors::Theme;
|
|
use crate::ui::form::FormState;
|
|
use super::canvas::render_canvas; // Changed to canvas
|
|
|
|
pub fn render_form(
|
|
f: &mut Frame,
|
|
area: Rect,
|
|
form_state: &FormState,
|
|
fields: &[&str],
|
|
current_field: &usize,
|
|
inputs: &[&String],
|
|
theme: &Theme,
|
|
is_edit_mode: bool,
|
|
total_count: u64,
|
|
current_position: u64,
|
|
) {
|
|
// Create Adresar card
|
|
let adresar_card = Block::default()
|
|
.borders(Borders::ALL)
|
|
.border_style(Style::default().fg(theme.border))
|
|
.title(" Adresar ")
|
|
.style(Style::default().bg(theme.bg).fg(theme.fg));
|
|
|
|
f.render_widget(adresar_card, area);
|
|
|
|
// Define inner area
|
|
let inner_area = area.inner(Margin {
|
|
horizontal: 1,
|
|
vertical: 1,
|
|
});
|
|
|
|
// Create main layout
|
|
let main_layout = Layout::default()
|
|
.direction(Direction::Vertical)
|
|
.constraints([
|
|
Constraint::Length(1),
|
|
Constraint::Min(1),
|
|
])
|
|
.split(inner_area);
|
|
|
|
// Render count/position
|
|
let count_position_text = format!("Total: {} | Position: {}", total_count, current_position);
|
|
let count_para = Paragraph::new(count_position_text)
|
|
.style(Style::default().fg(theme.fg))
|
|
.alignment(Alignment::Left);
|
|
f.render_widget(count_para, main_layout[0]);
|
|
|
|
// Delegate input handling to canvas
|
|
render_canvas(
|
|
f,
|
|
main_layout[1],
|
|
form_state,
|
|
fields,
|
|
current_field,
|
|
inputs,
|
|
theme,
|
|
is_edit_mode,
|
|
);
|
|
}
|