From 162f8e309b67c333a482d636e59d207a6c5924e7 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 19 Sep 2023 04:53:40 +0200 Subject: GraphUI GridLayout: Fix scaled non-center: Only add center offset if requested and avoid double-add. --- .../classes/com/jogamp/graph/ui/layout/BoxLayout.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java') diff --git a/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java b/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java index 67f3ff445..c45fc3bb1 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java +++ b/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java @@ -201,22 +201,22 @@ public class BoxLayout implements Group.Layout { float dxh = 0, dyh = 0; if( isScaled ) { // scaling to cell size - final float cellWidth2 = hasCellWidth ? cellSize.x() - margin.width() : shapeWidthU; - final float cellHeight2 = hasCellHeight ? cellSize.y() - margin.height() : shapeHeightU; - final float sx = cellWidth2 / shapeWidthU; - final float sy = cellHeight2/ shapeHeightU; + final float cellWidth = hasCellWidth ? cellSize.x() - margin.width() : shapeWidthU; + final float cellHeight = hasCellHeight ? cellSize.y() - margin.height() : shapeHeightU; + final float sx = cellWidth / shapeWidthU; + final float sy = cellHeight/ shapeHeightU; sxy = sx < sy ? sx : sy; if( isCenteredHoriz ) { - dxh += shapeWidthU * ( sx - sxy ) * 0.5f; // horiz-center (adjustment for scale-axis) + dxh += shapeWidthU * ( sx - sxy ) * 0.5f; // horiz-center (adjustment for scale-axis w/o margin) } if( isCenteredVert ) { - dyh += shapeHeightU * ( sy - sxy ) * 0.5f; // vert-center (adjustment for scale-axis) + dyh += shapeHeightU * ( sy - sxy ) * 0.5f; // vert-center (adjustment for scale-axis w/o margin) } - dyh += margin.bottom; - dxh += margin.left; + dyh += margin.bottom; // always consider unscaled margin when scaling + dxh += margin.left; // ditto if( TRACE_LAYOUT ) { - System.err.println("bl("+i+").s: "+sx+" x "+sy+" -> "+sxy+": +"+dxh+" / "+dyh+", U: s "+shapeWidthU+" x "+shapeHeightU+", sz "+cellWidth2+" x "+cellHeight2); + System.err.println("bl("+i+").s: "+sx+" x "+sy+" -> "+sxy+": +"+dxh+" / "+dyh+", U: s "+shapeWidthU+" x "+shapeHeightU+", sz "+cellWidth+" x "+cellHeight); } } else { sxy = 1; -- cgit v1.2.3