Better sibling constraints
This commit is contained in:
parent
33bf08d4c1
commit
14f432543a
|
@ -183,9 +183,15 @@ impl MenuNode {
|
|||
|
||||
pub fn build_force_graph(&self, graph: &mut ForceGraph, parent: usize) {
|
||||
let mut siblings = Vec::new();
|
||||
let mut first_sibling = None;
|
||||
let mut last_sibling = None;
|
||||
|
||||
const SIBLING_LENGTH: f32 = 60.0;
|
||||
const SIBLING_STRENGTH: f32 = 0.1;
|
||||
|
||||
for child in self.children.iter() {
|
||||
let id = graph.nodes.len();
|
||||
let _ = first_sibling.get_or_insert(id);
|
||||
|
||||
graph.nodes.push(Node {
|
||||
body: Body {
|
||||
|
@ -206,16 +212,17 @@ impl MenuNode {
|
|||
strength: 1.0,
|
||||
});
|
||||
|
||||
for sibling in siblings.iter() {
|
||||
if let Some(last) = last_sibling {
|
||||
graph.springs.push(Constraint {
|
||||
from: *sibling,
|
||||
from: last,
|
||||
to: id,
|
||||
length: 60.0,
|
||||
strength: 0.1,
|
||||
length: SIBLING_LENGTH,
|
||||
strength: SIBLING_STRENGTH,
|
||||
});
|
||||
}
|
||||
|
||||
siblings.push(id);
|
||||
last_sibling = Some(id);
|
||||
|
||||
graph.connections.push(Connection {
|
||||
from: parent,
|
||||
|
@ -227,6 +234,15 @@ impl MenuNode {
|
|||
child.build_force_graph(graph, id);
|
||||
}
|
||||
|
||||
if let (Some(first), Some(last)) = (first_sibling, last_sibling) {
|
||||
graph.springs.push(Constraint {
|
||||
from: first,
|
||||
to: last,
|
||||
length: SIBLING_LENGTH,
|
||||
strength: SIBLING_STRENGTH,
|
||||
});
|
||||
}
|
||||
|
||||
graph.nodes[parent].info.unhide.extend_from_slice(&siblings);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue