Files
Dennis Kobert e420a87453 Integrate the graph-layout crate into the editor to replace its node graph layout (#5007)
* Place chains and stacks by relative offsets instead of their own placements

* Lay out the editor's node graph with the graph-layout crate

* Store chains and stacks as relative positions and migrate documents to them

* Trim comments

* Convert read nodes to relative positions in the format step

* Re-save the demo artwork with relative positions

* Append the position conversion to history as one interaction

* Address review comments on the position migration

* Format let chains as CI's rustfmt does

* Keep the dragged node's owners in place when a drag starts

* Keep absolute positions in documents with pending edits
2026-11-23 18:43:37 +00:00

62 lines
1.3 KiB
Rust

#![allow(dead_code, reason = "Each test file uses a different part of the shared builders")]
use glam::IVec2;
use graph_layout::{CHAIN_WIDTH, Graph, Layout, Node, NodeIndex, NodeKind, Placement, Wire};
pub const LAYER_HEIGHT: i32 = 2;
pub const CHAINED: Placement = Placement::Relative(IVec2::new(-CHAIN_WIDTH, 0));
pub fn stacked(gap: i32) -> Placement {
Placement::Relative(IVec2::new(0, LAYER_HEIGHT + 1 + gap))
}
pub fn node(placement: Placement) -> Node {
Node {
placement,
kind: NodeKind::Node,
size: IVec2::new(5, 2),
chainable: true,
held: false,
}
}
pub fn tall_node(placement: Placement, rows: i32) -> Node {
Node {
size: IVec2::new(5, rows + 1),
..node(placement)
}
}
pub fn layer(placement: Placement) -> Node {
Node {
kind: NodeKind::Layer,
..node(placement)
}
}
pub fn waypoint(placement: Placement) -> Node {
Node {
kind: NodeKind::Waypoint,
chainable: false,
..node(placement)
}
}
pub fn wire(source: u32, target: u32, input: u32) -> Wire {
Wire {
source: source.into(),
output: 0,
target: target.into(),
input,
}
}
pub fn at(index: u32) -> NodeIndex {
index.into()
}
pub fn chain_layers(graph: &Graph, layout: &Layout) -> Vec<Option<u32>> {
let count = u32::try_from(graph.nodes.len()).unwrap_or_default();
(0..count).map(|index| layout.node(at(index)).chain_layer.map(u32::from)).collect()
}