Skip to main content

SceneGraph

Struct SceneGraph 

Source
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: NodeIndex

The 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

Source

pub fn new() -> Self

Create a new empty scene graph with a root node.

Source

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.

Source

pub fn remove_node(&mut self, idx: NodeIndex) -> Option<SceneNode>

Remove a node safely, keeping the id_index synchronized.

Source

pub fn get_by_id(&self, id: NodeId) -> Option<&SceneNode>

Look up a node by its @id.

Source

pub fn get_by_id_mut(&mut self, id: NodeId) -> Option<&mut SceneNode>

Look up a node mutably by its @id.

Source

pub fn index_of(&self, id: NodeId) -> Option<NodeIndex>

Get the index for a NodeId.

Source

pub fn parent(&self, idx: NodeIndex) -> Option<NodeIndex>

Get the parent index of a node.

Source

pub fn reparent_node(&mut self, child: NodeIndex, new_parent: NodeIndex)

Reparent a node to a new parent.

Source

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).

Source

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.

Source

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.

Source

pub fn send_to_back(&mut self, child: NodeIndex) -> bool

Move a child to the back of z-order (first child).

Source

pub fn bring_to_front(&mut self, child: NodeIndex) -> bool

Move a child to the front of z-order (last child).

Source

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.

Source

pub fn define_style(&mut self, name: NodeId, style: Properties)

Define a named style.

Source

pub fn resolve_style( &self, node: &SceneNode, active_triggers: &[AnimTrigger], ) -> Properties

Resolve a node’s effective style (merging use references + inline overrides + active animations).

Source

pub fn rebuild_index(&mut self)

Rebuild the id_index (needed after deserialization).

Source

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).

Source

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.
Source

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

Source§

fn clone(&self) -> SceneGraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SceneGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SceneGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.