mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-10 05:18:27 +00:00
impl Default in some struct
This commit is contained in:
parent
75308d0e72
commit
36384258ab
@ -47,7 +47,15 @@ pub enum NodeResponse<UserResponse: UserResponseTrait, NodeData: NodeDataTrait>
|
||||
pub struct GraphResponse<UserResponse: UserResponseTrait, NodeData: NodeDataTrait> {
|
||||
pub node_responses: Vec<NodeResponse<UserResponse, NodeData>>,
|
||||
}
|
||||
|
||||
impl<UserResponse: UserResponseTrait, NodeData: NodeDataTrait> Default
|
||||
for GraphResponse<UserResponse, NodeData>
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
node_responses: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct GraphNodeWidget<'a, NodeData, DataType, ValueType> {
|
||||
pub position: &'a mut Pos2,
|
||||
pub graph: &'a mut Graph<NodeData, DataType, ValueType>,
|
||||
|
||||
@ -4,7 +4,7 @@ use std::marker::PhantomData;
|
||||
#[cfg(feature = "persistence")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Default, Copy, Clone)]
|
||||
#[cfg_attr(feature = "persistence", derive(Serialize, Deserialize))]
|
||||
pub struct PanZoom {
|
||||
pub pan: egui::Vec2,
|
||||
@ -38,17 +38,27 @@ impl<NodeData, DataType, ValueType, NodeKind, UserState>
|
||||
{
|
||||
pub fn new(default_zoom: f32) -> Self {
|
||||
Self {
|
||||
graph: Graph::new(),
|
||||
node_order: Vec::new(),
|
||||
connection_in_progress: None,
|
||||
selected_node: None,
|
||||
node_positions: SecondaryMap::new(),
|
||||
node_finder: None,
|
||||
pan_zoom: PanZoom {
|
||||
pan: egui::Vec2::ZERO,
|
||||
zoom: default_zoom,
|
||||
},
|
||||
_user_state: PhantomData,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<NodeData, DataType, ValueType, NodeKind, UserState> Default
|
||||
for GraphEditorState<NodeData, DataType, ValueType, NodeKind, UserState>
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
graph: Default::default(),
|
||||
node_order: Default::default(),
|
||||
connection_in_progress: Default::default(),
|
||||
selected_node: Default::default(),
|
||||
node_positions: Default::default(),
|
||||
node_finder: Default::default(),
|
||||
pan_zoom: Default::default(),
|
||||
_user_state: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,6 +341,7 @@ type MyGraph = Graph<MyNodeData, MyDataType, MyValueType>;
|
||||
type MyEditorState =
|
||||
GraphEditorState<MyNodeData, MyDataType, MyValueType, MyNodeTemplate, MyGraphState>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct NodeGraphExample {
|
||||
// The `GraphEditorState` is the top-level object. You "register" all your
|
||||
// custom types by specifying it as its generic parameters.
|
||||
@ -349,14 +350,6 @@ pub struct NodeGraphExample {
|
||||
user_state: MyGraphState,
|
||||
}
|
||||
|
||||
impl Default for NodeGraphExample {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
state: GraphEditorState::new(1.0),
|
||||
user_state: MyGraphState::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "persistence")]
|
||||
const PERSISTENCE_KEY: &str = "egui_node_graph";
|
||||
|
||||
@ -368,7 +361,7 @@ impl NodeGraphExample {
|
||||
let state = cc
|
||||
.storage
|
||||
.and_then(|storage| eframe::get_value(storage, PERSISTENCE_KEY))
|
||||
.unwrap_or_else(|| GraphEditorState::new(0.0));
|
||||
.unwrap_or_default();
|
||||
Self {
|
||||
state,
|
||||
user_state: MyGraphState::default(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user