working, separated canvas from form fully
This commit is contained in:
@@ -19,43 +19,35 @@ pub fn render_canvas(
|
||||
inputs: &[&String],
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
total_count: u64,
|
||||
current_position: u64,
|
||||
) {
|
||||
// Get canvas areas from form
|
||||
let (label_area, input_container_area) = super::form::render_form(
|
||||
f,
|
||||
area,
|
||||
theme,
|
||||
total_count,
|
||||
current_position
|
||||
);
|
||||
// Create input container with dynamic border
|
||||
// Split area into columns
|
||||
let columns = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
||||
.split(area);
|
||||
|
||||
// Input container styling
|
||||
let input_container = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(if is_edit_mode {
|
||||
if form_state.has_unsaved_changes {
|
||||
Style::default().fg(theme.warning)
|
||||
} else {
|
||||
Style::default().fg(theme.accent)
|
||||
}
|
||||
form_state.has_unsaved_changes.then(|| theme.warning).unwrap_or(theme.accent)
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
theme.secondary
|
||||
})
|
||||
.style(Style::default().bg(theme.bg));
|
||||
|
||||
// Calculate input container dimensions
|
||||
let input_block_area = Rect {
|
||||
x: input_container_area.x,
|
||||
y: input_container_area.y,
|
||||
width: input_container_area.width,
|
||||
// Input block dimensions
|
||||
let input_block = Rect {
|
||||
x: columns[1].x,
|
||||
y: columns[1].y,
|
||||
width: columns[1].width,
|
||||
height: fields.len() as u16 + 2,
|
||||
};
|
||||
|
||||
f.render_widget(&input_container, input_block_area);
|
||||
f.render_widget(&input_container, input_block);
|
||||
|
||||
// Split input area into rows
|
||||
let input_area = input_container.inner(input_block_area);
|
||||
// Input rows layout
|
||||
let input_area = input_container.inner(input_block);
|
||||
let input_rows = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(vec![Constraint::Length(1); fields.len()])
|
||||
@@ -65,17 +57,17 @@ pub fn render_canvas(
|
||||
for (i, field) in fields.iter().enumerate() {
|
||||
let label = Paragraph::new(Line::from(Span::styled(
|
||||
format!("{}:", field),
|
||||
Style::default().fg(theme.fg),
|
||||
)));
|
||||
Style::default().fg(theme.fg)),
|
||||
));
|
||||
f.render_widget(label, Rect {
|
||||
x: label_area.x,
|
||||
y: input_block_area.y + 1 + i as u16,
|
||||
width: label_area.width,
|
||||
x: columns[0].x,
|
||||
y: input_block.y + 1 + i as u16,
|
||||
width: columns[0].width,
|
||||
height: 1,
|
||||
});
|
||||
}
|
||||
|
||||
// Render input fields and cursor
|
||||
// Render inputs and cursor
|
||||
for (i, input) in inputs.iter().enumerate() {
|
||||
let is_active = i == *current_field;
|
||||
let input_display = Paragraph::new(input.as_str())
|
||||
|
||||
Reference in New Issue
Block a user