45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
// src/state/canvas_state.rs
|
|
|
|
use crate::state::pages::form::FormState;
|
|
|
|
pub trait CanvasState {
|
|
fn current_field(&self) -> usize;
|
|
fn current_cursor_pos(&self) -> usize;
|
|
fn has_unsaved_changes(&self) -> bool;
|
|
fn inputs(&self) -> Vec<&String>;
|
|
fn get_current_input(&self) -> &str;
|
|
fn get_current_input_mut(&mut self) -> &mut String;
|
|
}
|
|
|
|
// Implement for FormState (keep existing form.rs code and add this)
|
|
impl CanvasState for FormState {
|
|
fn current_field(&self) -> usize {
|
|
self.current_field
|
|
}
|
|
|
|
fn current_cursor_pos(&self) -> usize {
|
|
self.current_cursor_pos
|
|
}
|
|
|
|
fn has_unsaved_changes(&self) -> bool {
|
|
self.has_unsaved_changes
|
|
}
|
|
|
|
fn inputs(&self) -> Vec<&String> {
|
|
self.values.iter().collect()
|
|
}
|
|
|
|
fn get_current_input(&self) -> &str {
|
|
self.values
|
|
.get(self.current_field)
|
|
.map(|s| s.as_str())
|
|
.unwrap_or("")
|
|
}
|
|
|
|
fn get_current_input_mut(&mut self) -> &mut String {
|
|
self.values
|
|
.get_mut(self.current_field)
|
|
.expect("Invalid current_field index")
|
|
}
|
|
}
|