use super::{CanvasPos, Grid};
#[derive(Clone)]
pub(super) struct EditorState<S> {
pub(super) viewport_position: CanvasPos,
pub(super) grid: Grid,
pub(super) dragged_node: Option<(egui::Id, egui::Vec2)>,
pub(super) dragged_socket: Option<S>,
}
impl<S> Default for EditorState<S> {
fn default() -> Self {
Self {
viewport_position: CanvasPos::ZERO,
grid: Grid { size: 10.0 },
dragged_node: None,
dragged_socket: None,
}
}
}
impl<S> EditorState<S>
where
Self: Clone + Send + Sync + 'static,
{
pub(super) fn load(ctx: &egui::Context, id: egui::Id) -> Self {
ctx.data(|data| data.get_temp(id).unwrap_or_default())
}
pub(super) fn store(self, ctx: &egui::Context, id: egui::Id) {
ctx.data_mut(|data| data.insert_temp(id, self));
}
}