Skip to content

Commit

Permalink
[Zest 2.0] Ignore node size when calculating position in layout
Browse files Browse the repository at this point in the history
The location of a node describes its top-left pixel, rather than its
center. When using layout algorithms that are based on the grid layout,
this causes the offset to be half the space between the rows and columns
plus the half the width and height of the nodes.
Latter is undesirable and may cause nodes to be partially moved outside
the client area.

The same issue can be observed in the other layout algorithms
(Spring/Tree/Radial) when fitting the nodes into the client area,
because the same mistake is repeated in the AlgorithmHelper class.
  • Loading branch information
ptziegler authored and azoitl committed Sep 28, 2024
1 parent b324b39 commit 9bd2cb9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public static void fitWithinBounds(EntityLayout[] entities, DisplayIndependentRe
entity.setSize(size.width, size.height);
}

location.x = destinationBounds.x + size.width / 2 + percentX * (destinationBounds.width - size.width);
location.y = destinationBounds.y + size.height / 2
+ percentY * (destinationBounds.height - size.height);
location.x = destinationBounds.x + percentX * (destinationBounds.width - size.width);
location.y = destinationBounds.y + percentY * (destinationBounds.height - size.height);
entity.setLocation(location.x, location.y);

} else if (resize && entity.isResizable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,8 @@ protected synchronized void applyLayoutInternal(EntityLayout[] entitiesToLayout,
node.setSize(Math.max(childrenWidth, MIN_ENTITY_SIZE),
Math.max(childrenHeight, MIN_ENTITY_SIZE));
}
DisplayIndependentDimension size = node.getSize();
double xmove = bounds.x + j * colWidth + offsetX + size.width / 2;
double ymove = bounds.y + i * rowHeight + offsetY + size.height / 2;
double xmove = bounds.x + j * colWidth + offsetX;
double ymove = bounds.y + i * rowHeight + offsetY;
if (node.isMovable()) {
node.setLocation(xmove, ymove);
}
Expand Down

0 comments on commit 9bd2cb9

Please sign in to comment.