MCPcopy Create free account
hub / github.com/JoshuaPostel/texaform / update_node_layout

Method update_node_layout

src/tech_tree.rs:372–399  ·  view source on GitHub ↗
(&self, area: &Rect)

Source from the content-addressed store, hash-verified

370 }
371
372 pub fn update_node_layout(&self, area: &Rect) -> Vec<Rect> {
373 let paths = bellman_ford(&self.graph, NodeIndex::new(0)).expect("non-cyclic");
374 //tracing::info!("longest: {paths:#?}");
375
376 let node_depths: Vec<usize> = paths
377 .distances
378 .into_iter()
379 .map(|f: f32| f.abs() as usize)
380 .collect();
381
382 let max_depth = node_depths.iter().max().expect("at least one element");
383
384 let inner = area.inner(Margin::new(1, 1));
385 let mut constraints: Vec<Constraint> = vec![];
386 for _ in 0..=*max_depth {
387 constraints.push(Constraint::Max(3));
388 constraints.push(Constraint::Max(5));
389 }
390 let chunks = Layout::vertical(constraints).split(inner);
391
392 // build and then order node_uis vec so that vector's idx matches graph node index
393 let mut node_areas = vec![];
394 for i in 0..=*max_depth {
395 node_areas.extend(self.row_areas(i, chunks[i * 2]));
396 }
397 node_areas.sort_by_key(|(idx, _)| *idx);
398 node_areas.into_iter().map(|(_, node_ui)| node_ui).collect()
399 }
400
401 pub fn update_edge_layout(&self, node_areas: &[Rect]) -> Vec<EdgeLayout> {
402 let mut node_layouts: Vec<NodeLayout> = node_areas.iter().map(NodeLayout::new).collect();

Callers 1

newMethod · 0.80

Calls 2

pushMethod · 0.80
row_areasMethod · 0.80

Tested by

no test coverage detected