Skip to content

Commit

Permalink
Fixes #989. Content alignment for rectpacking.
Browse files Browse the repository at this point in the history
Translate inner content based on the real width and the width of the
parent.
  • Loading branch information
soerendomroes committed Feb 13, 2024
1 parent 715b2f4 commit d56d34d
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.elk.core.alg.ILayoutProcessor;
import org.eclipse.elk.core.alg.LayoutProcessorConfiguration;
import org.eclipse.elk.core.math.ElkPadding;
import org.eclipse.elk.core.math.KVector;
import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.core.util.BasicProgressMonitor;
import org.eclipse.elk.core.util.BoxLayoutProvider;
Expand Down Expand Up @@ -124,6 +125,20 @@ public void layout(final ElkNode layoutGraph, final IElkProgressMonitor progress
progressMonitor.logGraph(layoutGraph, slotIndex + "-Finished");
}
// elkjs-exclude-end

// Content alignment
double realWidth = 0;
double realHeight = 0;
for (ElkNode rect : rectangles) {
realWidth = Math.max(realWidth, rect.getX() + rect.getWidth());
realHeight = Math.max(realHeight, rect.getY() + rect.getHeight());
}

ElkUtil.translate(layoutGraph,
new KVector(
layoutGraph.getProperty(InternalProperties.DRAWING_WIDTH),
layoutGraph.getProperty(InternalProperties.DRAWING_HEIGHT)),
new KVector(realWidth, realHeight));

// Final touch.
applyPadding(rectangles, padding);
Expand Down

0 comments on commit d56d34d

Please sign in to comment.