pub struct SceneGraph {
pub graph: StableDiGraph<SceneNode, ()>,
pub root: NodeIndex,
pub styles: HashMap<NodeId, Style>,
pub id_index: HashMap<NodeId, NodeIndex>,
pub edges: Vec<Edge>,
pub imports: Vec<Import>,
pub sorted_child_order: HashMap<NodeIndex, Vec<NodeIndex>>,
}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, Style>Named theme definitions (theme 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.
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 define_style(&mut self, name: NodeId, style: Style)
pub fn define_style(&mut self, name: NodeId, style: Style)
Define a named style.
Sourcepub fn resolve_style(
&self,
node: &SceneNode,
active_triggers: &[AnimTrigger],
) -> Style
pub fn resolve_style( &self, node: &SceneNode, active_triggers: &[AnimTrigger], ) -> Style
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],
) -> Style
pub fn resolve_style_for_edge( &self, edge: &Edge, active_triggers: &[AnimTrigger], ) -> Style
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
Return the leaf node directly — children are always selectable first. Groups can still be selected by clicking their own area (not covered by children) or via marquee selection.
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