gui of canvas is from the canvas crate now

This commit is contained in:
Priec
2025-07-29 19:54:29 +02:00
parent a1fa42e204
commit aec5f80879
13 changed files with 370 additions and 53 deletions

View File

@@ -1,9 +1,7 @@
// src/components/form/form.rs
use crate::components::common::autocomplete;
use crate::components::handlers::canvas::render_canvas;
use crate::config::colors::themes::Theme;
use crate::state::app::highlight::HighlightState;
use canvas::CanvasState;
use canvas::{CanvasState, render_canvas, HighlightState}; // CHANGED: Import HighlightState from canvas
use crate::state::pages::form::FormState;
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
@@ -15,14 +13,14 @@ use ratatui::{
pub fn render_form(
f: &mut Frame,
area: Rect,
form_state: &FormState, // <--- CHANGE THIS to the concrete type
form_state: &FormState,
fields: &[&str],
current_field_idx: &usize,
inputs: &[&String],
table_name: &str,
theme: &Theme,
is_edit_mode: bool,
highlight_state: &HighlightState,
highlight_state: &HighlightState, // Now using canvas::HighlightState
total_count: u64,
current_position: u64,
) {
@@ -63,27 +61,23 @@ pub fn render_form(
.alignment(Alignment::Left);
f.render_widget(count_para, main_layout[0]);
// Get the active field's rect from render_canvas
let active_field_rect = crate::components::handlers::canvas::render_canvas_library(
// Use the canvas library's render_canvas function
let active_field_rect = render_canvas(
f,
main_layout[1],
form_state,
fields,
current_field_idx,
inputs,
theme,
is_edit_mode,
highlight_state,
);
// --- NEW: RENDER AUTOCOMPLETE ---
// --- RENDER AUTOCOMPLETE ---
if form_state.autocomplete_active {
if let Some(active_rect) = active_field_rect {
let selected_index = form_state.get_selected_suggestion_index();
if let Some(rich_suggestions) = form_state.get_rich_suggestions() {
if !rich_suggestions.is_empty() {
// CHANGE THIS to call the renamed function
autocomplete::render_hit_autocomplete_dropdown(
f,
active_rect,
@@ -95,8 +89,6 @@ pub fn render_form(
);
}
}
// The fallback to simple suggestions is now correctly handled
// because the original render_autocomplete_dropdown exists again.
else if let Some(simple_suggestions) = form_state.get_suggestions() {
if !simple_suggestions.is_empty() {
autocomplete::render_autocomplete_dropdown(
@@ -112,4 +104,3 @@ pub fn render_form(
}
}
}