pub struct SceneGraph {
pub graph: StableDiGraph<SceneNode, ()>,
pub root: NodeIndex,
pub styles: HashMap<NodeId, Properties>,
pub id_index: HashMap<NodeId, NodeIndex>,
pub edges: Vec<Edge>,
pub imports: Vec<Import>,
pub sorted_child_order: HashMap<NodeIndex, Vec<NodeIndex>>,
pub edge_defaults: Option<EdgeDefaults>,
}Expand description
The complete FD document — a DAG of SceneNode values.
Edges go from parent → child. Style definitions are stored separately in a hashmap for lookup by name.
Fields§
§graph: StableDiGraph<SceneNode, ()>The underlying directed graph.
root: NodeIndexThe root node index.
styles: HashMap<NodeId, Properties>Named style definitions (style base_text { ... }).
id_index: HashMap<NodeId, NodeIndex>Index from NodeId → NodeIndex for fast lookup.
edges: Vec<Edge>Visual edges (connections between nodes).
imports: Vec<Import>File imports with namespace aliases.
sorted_child_order: HashMap<NodeIndex, Vec<NodeIndex>>Explicit child ordering set by sort_nodes.
When present for a parent, children() returns this order
instead of the default NodeIndex sort.
edge_defaults: Option<EdgeDefaults>Document-level default styles for edges. When present, individual edge properties matching the defaults are omitted.
Implementations§
Source§impl SceneGraph
impl SceneGraph
Sourcepub fn add_node(&mut self, parent: NodeIndex, node: SceneNode) -> NodeIndex
pub fn add_node(&mut self, parent: NodeIndex, node: SceneNode) -> NodeIndex
Add a node as a child of parent. Returns the new node’s index.
Sourcepub fn remove_node(&mut self, idx: NodeIndex) -> Option<SceneNode>
pub fn remove_node(&mut self, idx: NodeIndex) -> Option<SceneNode>
Remove a node safely, keeping the id_index synchronized.
Sourcepub fn get_by_id_mut(&mut self, id: NodeId) -> Option<&mut SceneNode>
pub fn get_by_id_mut(&mut self, id: NodeId) -> Option<&mut SceneNode>
Look up a node mutably by its @id.
Sourcepub fn reparent_node(&mut self, child: NodeIndex, new_parent: NodeIndex)
pub fn reparent_node(&mut self, child: NodeIndex, new_parent: NodeIndex)
Reparent a node to a new parent.
Sourcepub fn children(&self, idx: NodeIndex) -> Vec<NodeIndex>
pub fn children(&self, idx: NodeIndex) -> Vec<NodeIndex>
Get children of a node in document (insertion) order.
Sorts by NodeIndex so the result is deterministic regardless of
how petgraph iterates its adjacency list on different targets
(native vs WASM).
Sourcepub fn send_backward(&mut self, child: NodeIndex) -> bool
pub fn send_backward(&mut self, child: NodeIndex) -> bool
Move a child one step backward in z-order (swap with previous sibling). Returns true if the z-order changed.
Sourcepub fn bring_forward(&mut self, child: NodeIndex) -> bool
pub fn bring_forward(&mut self, child: NodeIndex) -> bool
Move a child one step forward in z-order (swap with next sibling). Returns true if the z-order changed.
Sourcepub fn send_to_back(&mut self, child: NodeIndex) -> bool
pub fn send_to_back(&mut self, child: NodeIndex) -> bool
Move a child to the back of z-order (first child).
Sourcepub fn bring_to_front(&mut self, child: NodeIndex) -> bool
pub fn bring_to_front(&mut self, child: NodeIndex) -> bool
Move a child to the front of z-order (last child).
Sourcepub fn move_child_to_index(
&mut self,
child: NodeIndex,
target_index: usize,
) -> bool
pub fn move_child_to_index( &mut self, child: NodeIndex, target_index: usize, ) -> bool
Move a child to a specific index within its parent’s children.
Clamps target_index to [0, sibling_count - 1].
Returns true if the order changed.
Sourcepub fn define_style(&mut self, name: NodeId, style: Properties)
pub fn define_style(&mut self, name: NodeId, style: Properties)
Define a named style.
Sourcepub fn resolve_style(
&self,
node: &SceneNode,
active_triggers: &[AnimTrigger],
) -> Properties
pub fn resolve_style( &self, node: &SceneNode, active_triggers: &[AnimTrigger], ) -> Properties
Resolve a node’s effective style (merging use references + inline overrides + active animations).
Sourcepub fn rebuild_index(&mut self)
pub fn rebuild_index(&mut self)
Rebuild the id_index (needed after deserialization).
Sourcepub fn resolve_style_for_edge(
&self,
edge: &Edge,
active_triggers: &[AnimTrigger],
) -> Properties
pub fn resolve_style_for_edge( &self, edge: &Edge, active_triggers: &[AnimTrigger], ) -> Properties
Resolve an edge’s effective style (merging use references + inline overrides + active animations).
Sourcepub fn effective_target(&self, leaf_id: NodeId, selected: &[NodeId]) -> NodeId
pub fn effective_target(&self, leaf_id: NodeId, selected: &[NodeId]) -> NodeId
Resolve the effective click target for a leaf node.
Figma-style group selection with progressive drill-down:
- First click → selects the topmost group ancestor (below root).
- Click again (topmost group already selected) → next-level group.
- Click again (all group ancestors selected) → the leaf itself.
Sourcepub fn is_ancestor_of(&self, ancestor_id: NodeId, descendant_id: NodeId) -> bool
pub fn is_ancestor_of(&self, ancestor_id: NodeId, descendant_id: NodeId) -> bool
Check if ancestor_id is a parent/grandparent/etc. of descendant_id.
Trait Implementations§
Source§impl Clone for SceneGraph
impl Clone for SceneGraph
Source§fn clone(&self) -> SceneGraph
fn clone(&self) -> SceneGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more