First nodes that GraphView::add_node creates, get pushed

to the left side of the screen. So by adding a constant offset,
we can avoid having possible links that are partly out of the view
just after starting the program
This commit is contained in:
er888kh
2021-07-06 08:31:31 +00:00
committed by Ryuukyu
parent e29ffdeea8
commit be9339472e

View File

@@ -237,8 +237,8 @@ impl GraphView {
// Place widgets in colums of 4, growing down, then right.
// TODO: Make a better positioning algorithm.
let x = (private.nodes.borrow().len() / 4) as f32 * 400.0; // This relies on integer division rounding down.
let y = private.nodes.borrow().len() as f32 % 4.0 * 100.0;
let x = ((private.nodes.borrow().len() / 4) as f32 * 400.0) + 20.0; // This relies on integer division rounding down.
let y = (private.nodes.borrow().len() as f32 % 4.0 * 100.0) + 20.0;
self.move_node(&node.clone().upcast(), x, y);