use crate::CellIndex;
use egui::Ui;
#[derive(Debug, Clone)]
pub enum CellEditState<E, T> {
Pivot(CellIndex),
Editing(CellIndex, E, T),
}
pub trait ApplyChange<T, E> {
fn apply_change(&mut self, value: T) -> Result<(), E>;
}
pub trait EditableTableRenderer<DataSource> {
type Value;
type ItemState;
fn build_item_state(
&self,
cell_index: CellIndex,
source: &mut DataSource,
) -> Option<(Self::ItemState, Self::Value)>;
fn on_edit_complete(
&mut self,
cell_index: CellIndex,
state: Self::ItemState,
original_item: Self::Value,
source: &mut DataSource,
);
fn render_cell_editor(
&self,
ui: &mut Ui,
cell_index: &CellIndex,
state: &mut Self::ItemState,
original_item: &Self::Value,
source: &mut DataSource,
);
}
#[derive(Debug, Clone)]
pub struct EditorState<IS, V> {
pub state: Option<CellEditState<IS, V>>,
}
impl<IS, V> Default for EditorState<IS, V> {
fn default() -> Self {
Self { state: None }
}
}
pub struct NullEditor {}
impl<DataSource> EditableTableRenderer<DataSource> for NullEditor {
type Value = ();
type ItemState = ();
fn build_item_state(
&self,
cell_index: CellIndex,
source: &mut DataSource,
) -> Option<(Self::ItemState, Self::Value)> {
let (_, _) = (cell_index, source);
unreachable!()
}
fn on_edit_complete(
&mut self,
index: CellIndex,
state: Self::ItemState,
original_item: Self::Value,
source: &mut DataSource,
) {
let (_, _, _, _) = (index, state, original_item, source);
unreachable!()
}
fn render_cell_editor(
&self,
ui: &mut Ui,
cell_index: &CellIndex,
state: &mut Self::ItemState,
original_item: &Self::Value,
source: &mut DataSource,
) {
let (_, _, _, _, _) = (ui, cell_index, state, original_item, source);
unreachable!()
}
}