pub fn layout_and_apply<T>(
treeize: &mut Treeize<T>,
config: LayoutConfig,
has_output: impl FnMut(NodeId) -> bool,
has_input: impl FnMut(NodeId) -> bool,
node_sizes: Option<&HashMap<NodeId, Vec2>>,
)Expand description
Convenience function that performs layout and applies it in one step.
§Arguments
treeize- The tree graph to layout and updateconfig- Layout configuration parametershas_output- Function to check if a node has output pinshas_input- Function to check if a node has input pinsnode_sizes- Optional map from node ID to node size (width, height). If provided, the layout will consider actual node sizes to avoid overlaps.
§Example
use egui_treeize::{Treeize, layout::{LayoutConfig, layout_and_apply}};
use std::collections::HashMap;
struct MyNode;
let mut treeize = Treeize::<MyNode>::new();
let config = LayoutConfig {
horizontal_spacing: 200.0,
vertical_spacing: 150.0,
start_pos: egui::pos2(0.0, 0.0),
};
// Optional: provide node sizes
let mut node_sizes = HashMap::new();
// node_sizes.insert(node_id, egui::vec2(100.0, 50.0));
layout_and_apply(
&mut treeize,
config,
|node_id| {
// Check if node has output pins
let node = &treeize[node_id];
// Your logic here
true
},
|node_id| {
// Check if node has input pins
let node = &treeize[node_id];
// Your logic here
true
},
Some(&node_sizes), // or None to ignore sizes
);