going into a new canvas library structure

This commit is contained in:
Priec
2025-08-19 13:24:48 +02:00
parent 858f5137d8
commit d0ff449e3b
7 changed files with 76 additions and 71 deletions

View File

@@ -13,7 +13,8 @@ use ratatui::{
Frame,
};
use crate::state::app::highlight::HighlightState;
use canvas::canvas::{render_canvas, HighlightState as CanvasHighlightState}; // Use canvas library's render function
use canvas::{FormEditor, render_canvas_default, render_suggestions_dropdown, DefaultCanvasTheme};
use canvas::canvas::HighlightState as CanvasHighlightState;
// Helper function to convert between HighlightState types
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
@@ -58,15 +59,17 @@ pub fn render_login(
])
.split(inner_area);
// --- FORM RENDERING (Using canvas library directly) ---
let canvas_highlight_state = convert_highlight_state(highlight_state);
render_canvas(
// --- FORM RENDERING (Using new canvas API) ---
let _canvas_highlight_state = convert_highlight_state(highlight_state);
// Wrap LoginState in FormEditor
let editor = FormEditor::new(login_state.clone());
let input_rect = render_canvas_default(
f,
chunks[0],
login_state, // LoginState implements CanvasState
theme, // Theme implements CanvasTheme
is_edit_mode,
&canvas_highlight_state,
&editor,
theme,
);
// --- ERROR MESSAGE ---
@@ -88,7 +91,7 @@ pub fn render_login(
// Login Button
let login_button_index = 0;
let login_active = if app_state.ui.focus_outside_canvas {
app_state.focused_button_index== login_button_index
app_state.focused_button_index == login_button_index
} else {
false
};
@@ -115,7 +118,7 @@ pub fn render_login(
// Return Button
let return_button_index = 1;
let return_active = if app_state.ui.focus_outside_canvas {
app_state.focused_button_index== return_button_index
app_state.focused_button_index == return_button_index
} else {
false
};
@@ -139,6 +142,19 @@ pub fn render_login(
button_chunks[1],
);
// --- SUGGESTIONS DROPDOWN (if active) ---
if app_state.current_mode == crate::modes::handlers::mode_manager::AppMode::Edit {
if let Some(input_rect) = input_rect {
render_suggestions_dropdown(
f,
f.area(),
input_rect,
&DefaultCanvasTheme,
&editor,
);
}
}
// --- DIALOG ---
if app_state.ui.dialog.dialog_show {
dialog::render_dialog(

View File

@@ -14,9 +14,8 @@ use ratatui::{
Frame,
};
use crate::state::app::highlight::HighlightState;
use canvas::canvas::{render_canvas, HighlightState as CanvasHighlightState}; // Use canvas library's render function
use canvas::autocomplete::gui::render_autocomplete_dropdown;
use canvas::autocomplete::AutocompleteCanvasState;
use canvas::{FormEditor, render_canvas_default, render_suggestions_dropdown, DefaultCanvasTheme};
use canvas::canvas::HighlightState as CanvasHighlightState;
// Helper function to convert between HighlightState types
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
@@ -62,13 +61,15 @@ pub fn render_register(
// --- FORM RENDERING (Using canvas library directly) ---
let canvas_highlight_state = convert_highlight_state(highlight_state);
let input_rect = render_canvas(
// Wrap RegisterState in FormEditor
let editor = FormEditor::new(state.clone());
let input_rect = render_canvas_default(
f,
chunks[0],
state, // RegisterState implements CanvasState
theme, // Theme implements CanvasTheme
is_edit_mode,
&canvas_highlight_state,
&editor,
theme,
);
// --- HELP TEXT ---
@@ -96,7 +97,7 @@ pub fn render_register(
// Register Button
let register_button_index = 0;
let register_active = if app_state.ui.focus_outside_canvas {
app_state.focused_button_index== register_button_index
app_state.focused_button_index == register_button_index
} else {
false
};
@@ -123,7 +124,7 @@ pub fn render_register(
// Return Button
let return_button_index = 1;
let return_active = if app_state.ui.focus_outside_canvas {
app_state.focused_button_index== return_button_index
app_state.focused_button_index == return_button_index
} else {
false
};
@@ -147,18 +148,16 @@ pub fn render_register(
button_chunks[1],
);
// --- AUTOCOMPLETE DROPDOWN (Using canvas library directly) ---
// --- AUTOCOMPLETE DROPDOWN (Using new canvas suggestions) ---
if app_state.current_mode == AppMode::Edit {
if let Some(autocomplete_state) = state.autocomplete_state() {
if let Some(input_rect) = input_rect {
render_autocomplete_dropdown(
f,
f.area(), // Frame area
input_rect, // Current input field rect
theme, // Theme implements CanvasTheme
autocomplete_state,
);
}
if let Some(input_rect) = input_rect {
render_suggestions_dropdown(
f,
f.area(), // Frame area
input_rect, // Current input field rect
&DefaultCanvasTheme,
&editor,
);
}
}

View File

@@ -1,7 +1,7 @@
// src/components/form/form.rs
use crate::components::common::autocomplete;
use crate::config::colors::themes::Theme;
use canvas::canvas::{CanvasState, render_canvas, HighlightState};
use canvas::{FormEditor, render_canvas_default, render_suggestions_dropdown, DefaultCanvasTheme};
use canvas::canvas::HighlightState;
use crate::state::pages::form::FormState;
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
@@ -14,12 +14,12 @@ pub fn render_form(
f: &mut Frame,
area: Rect,
form_state: &FormState,
fields: &[&str],
current_field_idx: &usize,
inputs: &[&String],
fields: &[&str], // no longer needed, FormEditor handles this
current_field_idx: &usize, // no longer needed
inputs: &[&String], // no longer needed
table_name: &str,
theme: &Theme,
is_edit_mode: bool,
is_edit_mode: bool, // FormEditor tracks mode internally
highlight_state: &HighlightState,
total_count: u64,
current_position: u64,
@@ -56,43 +56,30 @@ pub fn render_form(
total_count, current_position, total_count
)
};
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]);
// Use the canvas library's render_canvas function
let active_field_rect = render_canvas(
// --- FORM RENDERING (Using new canvas API) ---
let editor = FormEditor::new(form_state.clone());
let active_field_rect = render_canvas_default(
f,
main_layout[1],
form_state,
&editor,
theme,
is_edit_mode,
highlight_state,
);
// --- RENDER RICH AUTOCOMPLETE ONLY ---
if form_state.autocomplete_active {
if let Some(active_rect) = active_field_rect {
// Get selected index directly from form_state
let selected_index = form_state.selected_suggestion_index;
// Only render rich suggestions (your Hit objects)
if let Some(rich_suggestions) = form_state.get_rich_suggestions() {
if !rich_suggestions.is_empty() {
autocomplete::render_hit_autocomplete_dropdown(
f,
active_rect,
f.area(),
theme,
rich_suggestions,
selected_index,
form_state,
);
}
}
// Removed simple suggestions - we only use rich ones now!
}
// --- SUGGESTIONS DROPDOWN ---
if let Some(active_rect) = active_field_rect {
render_suggestions_dropdown(
f,
main_layout[1],
active_rect,
&DefaultCanvasTheme,
&editor,
);
}
}

View File

@@ -1,6 +1,6 @@
// src/config/colors/themes.rs
use ratatui::style::Color;
use canvas::canvas::CanvasTheme;
use canvas::CanvasTheme;
#[derive(Debug, Clone)]
pub struct Theme {
@@ -12,7 +12,7 @@ pub struct Theme {
pub warning: Color,
pub border: Color,
pub highlight_bg: Color,
pub inactive_highlight_bg: Color,// admin panel no idea what it really is
pub inactive_highlight_bg: Color, // admin panel no idea what it really is
}
impl Theme {
@@ -108,4 +108,9 @@ impl CanvasTheme for Theme {
fn warning(&self) -> Color {
self.warning
}
fn suggestion_gray(&self) -> Color {
// Neutral gray for suggestions
Color::Rgb(128, 128, 128)
}
}

View File

@@ -16,7 +16,6 @@ use crate::components::{
};
use crate::config::colors::themes::Theme;
use crate::modes::general::command_navigation::NavigationState;
use canvas::canvas::CanvasState;
use crate::state::app::buffer::BufferState;
use crate::state::app::highlight::HighlightState as LocalHighlightState;
use canvas::canvas::HighlightState as CanvasHighlightState;

View File

@@ -8,7 +8,6 @@ use crate::config::storage::storage::load_auth_data;
use crate::modes::common::commands::CommandHandler;
use crate::modes::handlers::event::{EventHandler, EventOutcome};
use crate::modes::handlers::mode_manager::{AppMode, ModeManager};
use canvas::canvas::CanvasState; // Only external library import
use crate::state::pages::form::{FormState, FieldDefinition};
use crate::state::pages::auth::AuthState;
use crate::state::pages::auth::LoginState;