going into a new canvas library structure
This commit is contained in:
@@ -57,7 +57,7 @@ use canvas::canvas::CanvasState;
|
|||||||
use canvas::canvas::CanvasAction;
|
use canvas::canvas::CanvasAction;
|
||||||
use canvas::canvas::ActionContext;
|
use canvas::canvas::ActionContext;
|
||||||
use canvas::canvas::HighlightState;
|
use canvas::canvas::HighlightState;
|
||||||
use canvas::canvas::CanvasTheme;
|
use canvas::CanvasTheme;
|
||||||
use canvas::dispatcher::ActionDispatcher;
|
use canvas::dispatcher::ActionDispatcher;
|
||||||
use canvas::canvas::ActionResult;
|
use canvas::canvas::ActionResult;
|
||||||
```
|
```
|
||||||
@@ -153,7 +153,7 @@ if editor.is_suggestions_active() {
|
|||||||
**New rendering:**
|
**New rendering:**
|
||||||
```rust
|
```rust
|
||||||
// Canvas handles everything
|
// Canvas handles everything
|
||||||
use canvas::canvas::render_canvas;
|
use canvas::render_canvas_default;
|
||||||
|
|
||||||
let active_field_rect = render_canvas(f, area, form_state, theme, edit_mode, highlight_state);
|
let active_field_rect = render_canvas(f, area, form_state, theme, edit_mode, highlight_state);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ use ratatui::{
|
|||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::state::app::highlight::HighlightState;
|
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
|
// Helper function to convert between HighlightState types
|
||||||
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
|
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
|
||||||
@@ -58,15 +59,17 @@ pub fn render_login(
|
|||||||
])
|
])
|
||||||
.split(inner_area);
|
.split(inner_area);
|
||||||
|
|
||||||
// --- FORM RENDERING (Using canvas library directly) ---
|
// --- FORM RENDERING (Using new canvas API) ---
|
||||||
let canvas_highlight_state = convert_highlight_state(highlight_state);
|
let _canvas_highlight_state = convert_highlight_state(highlight_state);
|
||||||
render_canvas(
|
|
||||||
|
// Wrap LoginState in FormEditor
|
||||||
|
let editor = FormEditor::new(login_state.clone());
|
||||||
|
|
||||||
|
let input_rect = render_canvas_default(
|
||||||
f,
|
f,
|
||||||
chunks[0],
|
chunks[0],
|
||||||
login_state, // LoginState implements CanvasState
|
&editor,
|
||||||
theme, // Theme implements CanvasTheme
|
theme,
|
||||||
is_edit_mode,
|
|
||||||
&canvas_highlight_state,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// --- ERROR MESSAGE ---
|
// --- ERROR MESSAGE ---
|
||||||
@@ -88,7 +91,7 @@ pub fn render_login(
|
|||||||
// Login Button
|
// Login Button
|
||||||
let login_button_index = 0;
|
let login_button_index = 0;
|
||||||
let login_active = if app_state.ui.focus_outside_canvas {
|
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 {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
@@ -115,7 +118,7 @@ pub fn render_login(
|
|||||||
// Return Button
|
// Return Button
|
||||||
let return_button_index = 1;
|
let return_button_index = 1;
|
||||||
let return_active = if app_state.ui.focus_outside_canvas {
|
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 {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
@@ -139,6 +142,19 @@ pub fn render_login(
|
|||||||
button_chunks[1],
|
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 ---
|
// --- DIALOG ---
|
||||||
if app_state.ui.dialog.dialog_show {
|
if app_state.ui.dialog.dialog_show {
|
||||||
dialog::render_dialog(
|
dialog::render_dialog(
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ use ratatui::{
|
|||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::state::app::highlight::HighlightState;
|
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::autocomplete::gui::render_autocomplete_dropdown;
|
use canvas::canvas::HighlightState as CanvasHighlightState;
|
||||||
use canvas::autocomplete::AutocompleteCanvasState;
|
|
||||||
|
|
||||||
// Helper function to convert between HighlightState types
|
// Helper function to convert between HighlightState types
|
||||||
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
|
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
|
||||||
@@ -62,13 +61,15 @@ pub fn render_register(
|
|||||||
|
|
||||||
// --- FORM RENDERING (Using canvas library directly) ---
|
// --- FORM RENDERING (Using canvas library directly) ---
|
||||||
let canvas_highlight_state = convert_highlight_state(highlight_state);
|
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,
|
f,
|
||||||
chunks[0],
|
chunks[0],
|
||||||
state, // RegisterState implements CanvasState
|
&editor,
|
||||||
theme, // Theme implements CanvasTheme
|
theme,
|
||||||
is_edit_mode,
|
|
||||||
&canvas_highlight_state,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// --- HELP TEXT ---
|
// --- HELP TEXT ---
|
||||||
@@ -96,7 +97,7 @@ pub fn render_register(
|
|||||||
// Register Button
|
// Register Button
|
||||||
let register_button_index = 0;
|
let register_button_index = 0;
|
||||||
let register_active = if app_state.ui.focus_outside_canvas {
|
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 {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
@@ -123,7 +124,7 @@ pub fn render_register(
|
|||||||
// Return Button
|
// Return Button
|
||||||
let return_button_index = 1;
|
let return_button_index = 1;
|
||||||
let return_active = if app_state.ui.focus_outside_canvas {
|
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 {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
@@ -147,18 +148,16 @@ pub fn render_register(
|
|||||||
button_chunks[1],
|
button_chunks[1],
|
||||||
);
|
);
|
||||||
|
|
||||||
// --- AUTOCOMPLETE DROPDOWN (Using canvas library directly) ---
|
// --- AUTOCOMPLETE DROPDOWN (Using new canvas suggestions) ---
|
||||||
if app_state.current_mode == AppMode::Edit {
|
if app_state.current_mode == AppMode::Edit {
|
||||||
if let Some(autocomplete_state) = state.autocomplete_state() {
|
if let Some(input_rect) = input_rect {
|
||||||
if let Some(input_rect) = input_rect {
|
render_suggestions_dropdown(
|
||||||
render_autocomplete_dropdown(
|
f,
|
||||||
f,
|
f.area(), // Frame area
|
||||||
f.area(), // Frame area
|
input_rect, // Current input field rect
|
||||||
input_rect, // Current input field rect
|
&DefaultCanvasTheme,
|
||||||
theme, // Theme implements CanvasTheme
|
&editor,
|
||||||
autocomplete_state,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// src/components/form/form.rs
|
// src/components/form/form.rs
|
||||||
use crate::components::common::autocomplete;
|
|
||||||
use crate::config::colors::themes::Theme;
|
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 crate::state::pages::form::FormState;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
|
||||||
@@ -14,12 +14,12 @@ pub fn render_form(
|
|||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
form_state: &FormState,
|
form_state: &FormState,
|
||||||
fields: &[&str],
|
fields: &[&str], // no longer needed, FormEditor handles this
|
||||||
current_field_idx: &usize,
|
current_field_idx: &usize, // no longer needed
|
||||||
inputs: &[&String],
|
inputs: &[&String], // no longer needed
|
||||||
table_name: &str,
|
table_name: &str,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool, // FormEditor tracks mode internally
|
||||||
highlight_state: &HighlightState,
|
highlight_state: &HighlightState,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
current_position: u64,
|
current_position: u64,
|
||||||
@@ -62,37 +62,24 @@ pub fn render_form(
|
|||||||
.alignment(Alignment::Left);
|
.alignment(Alignment::Left);
|
||||||
f.render_widget(count_para, main_layout[0]);
|
f.render_widget(count_para, main_layout[0]);
|
||||||
|
|
||||||
// Use the canvas library's render_canvas function
|
// --- FORM RENDERING (Using new canvas API) ---
|
||||||
let active_field_rect = render_canvas(
|
let editor = FormEditor::new(form_state.clone());
|
||||||
|
|
||||||
|
let active_field_rect = render_canvas_default(
|
||||||
f,
|
f,
|
||||||
main_layout[1],
|
main_layout[1],
|
||||||
form_state,
|
&editor,
|
||||||
theme,
|
theme,
|
||||||
is_edit_mode,
|
|
||||||
highlight_state,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// --- RENDER RICH AUTOCOMPLETE ONLY ---
|
// --- SUGGESTIONS DROPDOWN ---
|
||||||
if form_state.autocomplete_active {
|
if let Some(active_rect) = active_field_rect {
|
||||||
if let Some(active_rect) = active_field_rect {
|
render_suggestions_dropdown(
|
||||||
// Get selected index directly from form_state
|
f,
|
||||||
let selected_index = form_state.selected_suggestion_index;
|
main_layout[1],
|
||||||
|
active_rect,
|
||||||
// Only render rich suggestions (your Hit objects)
|
&DefaultCanvasTheme,
|
||||||
if let Some(rich_suggestions) = form_state.get_rich_suggestions() {
|
&editor,
|
||||||
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!
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// src/config/colors/themes.rs
|
// src/config/colors/themes.rs
|
||||||
use ratatui::style::Color;
|
use ratatui::style::Color;
|
||||||
use canvas::canvas::CanvasTheme;
|
use canvas::CanvasTheme;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Theme {
|
pub struct Theme {
|
||||||
@@ -12,7 +12,7 @@ pub struct Theme {
|
|||||||
pub warning: Color,
|
pub warning: Color,
|
||||||
pub border: Color,
|
pub border: Color,
|
||||||
pub highlight_bg: 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 {
|
impl Theme {
|
||||||
@@ -108,4 +108,9 @@ impl CanvasTheme for Theme {
|
|||||||
fn warning(&self) -> Color {
|
fn warning(&self) -> Color {
|
||||||
self.warning
|
self.warning
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn suggestion_gray(&self) -> Color {
|
||||||
|
// Neutral gray for suggestions
|
||||||
|
Color::Rgb(128, 128, 128)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ use crate::components::{
|
|||||||
};
|
};
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use crate::modes::general::command_navigation::NavigationState;
|
use crate::modes::general::command_navigation::NavigationState;
|
||||||
use canvas::canvas::CanvasState;
|
|
||||||
use crate::state::app::buffer::BufferState;
|
use crate::state::app::buffer::BufferState;
|
||||||
use crate::state::app::highlight::HighlightState as LocalHighlightState;
|
use crate::state::app::highlight::HighlightState as LocalHighlightState;
|
||||||
use canvas::canvas::HighlightState as CanvasHighlightState;
|
use canvas::canvas::HighlightState as CanvasHighlightState;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use crate::config::storage::storage::load_auth_data;
|
|||||||
use crate::modes::common::commands::CommandHandler;
|
use crate::modes::common::commands::CommandHandler;
|
||||||
use crate::modes::handlers::event::{EventHandler, EventOutcome};
|
use crate::modes::handlers::event::{EventHandler, EventOutcome};
|
||||||
use crate::modes::handlers::mode_manager::{AppMode, ModeManager};
|
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::form::{FormState, FieldDefinition};
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::pages::auth::LoginState;
|
use crate::state::pages::auth::LoginState;
|
||||||
|
|||||||
Reference in New Issue
Block a user