working, separated canvas from form fully
This commit is contained in:
@@ -19,43 +19,35 @@ pub fn render_canvas(
|
|||||||
inputs: &[&String],
|
inputs: &[&String],
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
total_count: u64,
|
|
||||||
current_position: u64,
|
|
||||||
) {
|
) {
|
||||||
// Get canvas areas from form
|
// Split area into columns
|
||||||
let (label_area, input_container_area) = super::form::render_form(
|
let columns = Layout::default()
|
||||||
f,
|
.direction(Direction::Horizontal)
|
||||||
area,
|
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
||||||
theme,
|
.split(area);
|
||||||
total_count,
|
|
||||||
current_position
|
// Input container styling
|
||||||
);
|
|
||||||
// Create input container with dynamic border
|
|
||||||
let input_container = Block::default()
|
let input_container = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_style(if is_edit_mode {
|
.border_style(if is_edit_mode {
|
||||||
if form_state.has_unsaved_changes {
|
form_state.has_unsaved_changes.then(|| theme.warning).unwrap_or(theme.accent)
|
||||||
Style::default().fg(theme.warning)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.accent)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Style::default().fg(theme.secondary)
|
theme.secondary
|
||||||
})
|
})
|
||||||
.style(Style::default().bg(theme.bg));
|
.style(Style::default().bg(theme.bg));
|
||||||
|
|
||||||
// Calculate input container dimensions
|
// Input block dimensions
|
||||||
let input_block_area = Rect {
|
let input_block = Rect {
|
||||||
x: input_container_area.x,
|
x: columns[1].x,
|
||||||
y: input_container_area.y,
|
y: columns[1].y,
|
||||||
width: input_container_area.width,
|
width: columns[1].width,
|
||||||
height: fields.len() as u16 + 2,
|
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
|
// Input rows layout
|
||||||
let input_area = input_container.inner(input_block_area);
|
let input_area = input_container.inner(input_block);
|
||||||
let input_rows = Layout::default()
|
let input_rows = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints(vec![Constraint::Length(1); fields.len()])
|
.constraints(vec![Constraint::Length(1); fields.len()])
|
||||||
@@ -65,17 +57,17 @@ pub fn render_canvas(
|
|||||||
for (i, field) in fields.iter().enumerate() {
|
for (i, field) in fields.iter().enumerate() {
|
||||||
let label = Paragraph::new(Line::from(Span::styled(
|
let label = Paragraph::new(Line::from(Span::styled(
|
||||||
format!("{}:", field),
|
format!("{}:", field),
|
||||||
Style::default().fg(theme.fg),
|
Style::default().fg(theme.fg)),
|
||||||
)));
|
));
|
||||||
f.render_widget(label, Rect {
|
f.render_widget(label, Rect {
|
||||||
x: label_area.x,
|
x: columns[0].x,
|
||||||
y: input_block_area.y + 1 + i as u16,
|
y: input_block.y + 1 + i as u16,
|
||||||
width: label_area.width,
|
width: columns[0].width,
|
||||||
height: 1,
|
height: 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render input fields and cursor
|
// Render inputs and cursor
|
||||||
for (i, input) in inputs.iter().enumerate() {
|
for (i, input) in inputs.iter().enumerate() {
|
||||||
let is_active = i == *current_field;
|
let is_active = i == *current_field;
|
||||||
let input_display = Paragraph::new(input.as_str())
|
let input_display = Paragraph::new(input.as_str())
|
||||||
|
|||||||
@@ -6,14 +6,21 @@ use ratatui::{
|
|||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::config::colors::Theme;
|
use crate::config::colors::Theme;
|
||||||
|
use crate::ui::form::FormState;
|
||||||
|
use super::canvas::render_canvas; // Changed to canvas
|
||||||
|
|
||||||
pub fn render_form(
|
pub fn render_form(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
|
form_state: &FormState,
|
||||||
|
fields: &[&str],
|
||||||
|
current_field: &usize,
|
||||||
|
inputs: &[&String],
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
|
is_edit_mode: bool,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
current_position: u64,
|
current_position: u64,
|
||||||
) -> (Rect, Rect) {
|
) {
|
||||||
// Create Adresar card
|
// Create Adresar card
|
||||||
let adresar_card = Block::default()
|
let adresar_card = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
@@ -23,33 +30,37 @@ pub fn render_form(
|
|||||||
|
|
||||||
f.render_widget(adresar_card, area);
|
f.render_widget(adresar_card, area);
|
||||||
|
|
||||||
// Define the inner area for the form (inside the card)
|
// Define inner area
|
||||||
let inner_area = area.inner(Margin {
|
let inner_area = area.inner(Margin {
|
||||||
horizontal: 1,
|
horizontal: 1,
|
||||||
vertical: 1,
|
vertical: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a vertical layout for the entire form content
|
// Create main layout
|
||||||
let main_layout = Layout::default()
|
let main_layout = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Length(1), // For count and position
|
Constraint::Length(1),
|
||||||
Constraint::Min(1), // For form fields
|
Constraint::Min(1),
|
||||||
])
|
])
|
||||||
.split(inner_area);
|
.split(inner_area);
|
||||||
|
|
||||||
// Render the count and position at the very top
|
// Render count/position
|
||||||
let count_position_text = format!("Total: {} | Current Position: {}", total_count, current_position);
|
let count_position_text = format!("Total: {} | Position: {}", total_count, current_position);
|
||||||
let count_position_paragraph = Paragraph::new(count_position_text)
|
let count_para = Paragraph::new(count_position_text)
|
||||||
.style(Style::default().fg(theme.fg))
|
.style(Style::default().fg(theme.fg))
|
||||||
.alignment(Alignment::Left);
|
.alignment(Alignment::Left);
|
||||||
f.render_widget(count_position_paragraph, main_layout[0]);
|
f.render_widget(count_para, main_layout[0]);
|
||||||
|
|
||||||
// Return label area and input area
|
// Delegate input handling to canvas
|
||||||
let columns = Layout::default()
|
render_canvas(
|
||||||
.direction(Direction::Horizontal)
|
f,
|
||||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
main_layout[1],
|
||||||
.split(main_layout[1]);
|
form_state,
|
||||||
|
fields,
|
||||||
(columns[0], columns[1])
|
current_field,
|
||||||
|
inputs,
|
||||||
|
theme,
|
||||||
|
is_edit_mode,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ impl FormState {
|
|||||||
let fields: Vec<&str> = self.fields.iter().map(|s| s.as_str()).collect();
|
let fields: Vec<&str> = self.fields.iter().map(|s| s.as_str()).collect();
|
||||||
let values: Vec<&String> = self.values.iter().collect();
|
let values: Vec<&String> = self.values.iter().collect();
|
||||||
|
|
||||||
crate::components::handlers::canvas::render_canvas(
|
crate::components::handlers::form::render_form(
|
||||||
f,
|
f,
|
||||||
area,
|
area,
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user