aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-09-16 15:38:21 +0200
committerSven Gothel <[email protected]>2023-09-16 15:38:21 +0200
commite5de90b67efe8e8ca518159b3a73295d751764c1 (patch)
tree49b751489dda73b510e4db37abed6b8824ec0372 /src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java
parent1e55d2a6a157cb9d70f7a879cc9a9bc97db5413d (diff)
GraphUI BoxLayout: Margin is only ignored for center Alignment w/o Fill scale. {Box,Grid}Layout: Always remove Bottom-Left delta and refine API doc of incl scale behavior
GraphUI BoxLayout: Margin is only ignored for center Alignment w/o Fill scale. Margin outside of a shape is not scaled and hence must be considered when using Fill scale. {Box,Grid}Layout: Always remove Bottom-Left delta Previously we were only dropping the negative extend. However, since our scale and center algo uses the AABBox width and height, which excludes the bottom-left delta, we have to drop such offset. TODO: Otherwise, we would need adjust for the bottom-left extend when NOT centering for each direction! This might be a useful enhancement in case one likes to drop shapes as-is w/o centering. {Box,Grid}Layout: Refine API doc of incl scale behavior
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java b/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java
index 8f83678c1..50f847df4 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java
@@ -44,8 +44,9 @@ import com.jogamp.opengl.util.PMVMatrix;
* <ul>
* <li>Optionally centered {@link Alignment.Bit#CenterHoriz horizontally}, {@link Alignment.Bit#CenterVert vertically} or {@link Alignment#Center both}.</li>
* <li>Optionally scaled to cell-size if given and {@link Alignment#Fill}</li>
- * <li>Padding is applied to each {@Shape} via {@link Shape#setPaddding(Padding)} if passed in constructor</li>
- * <li>Without cell-size behaves like a grid bag using individual shape sizes including padding</li>
+ * <li>{@link Padding} is applied to each {@Shape} via {@link Shape#setPaddding(Padding)} if passed in constructor and is scaled if {@link Alignment.Bit#Fill}</li>
+ * <li>Without cell-size behaves like a grid bag using individual shape sizes including {@link Padding}</li>
+ * <li>{@link Gap} is applied unscaled if used.</li>
* <li>Can be filled in {@link Order#COLUMN} or {@link Order#ROW} major-order.</li>
* <li>Not implemented {@link Alignment}: {@link Alignment.Bit#Top Top}, {@link Alignment.Bit#Right Right}, {@link Alignment.Bit#Bottom Bottom}, {@link Alignment.Bit#Left Left}</li>
* <li>..</li>
@@ -66,7 +67,7 @@ public class GridLayout implements Group.Layout {
private final Vec2f cellSize;
private final Alignment alignment;
private final Gap gap;
- private final Padding padding;
+ private final Padding padding; // scaled!
private int row_count, col_count;
private static final boolean TRACE_LAYOUT = false;
@@ -88,7 +89,7 @@ public class GridLayout implements Group.Layout {
* @param cellWidth
* @param cellHeight
* @param alignment TODO
- * @param gap
+ * @param gap {@link Gap} is applied unscaled
*/
public GridLayout(final int column_limit, final float cellWidth, final float cellHeight, final Alignment alignment, final Gap gap) {
this(alignment, Math.max(1, column_limit), -1, cellWidth, cellHeight, gap, null);
@@ -100,8 +101,8 @@ public class GridLayout implements Group.Layout {
* @param cellWidth
* @param cellHeight
* @param alignment TODO
- * @param gap
- * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)}
+ * @param gap {@link Gap} is applied unscaled
+ * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)} and is scaled if {@link Alignment.Bit#Fill}
*/
public GridLayout(final int column_limit, final float cellWidth, final float cellHeight, final Alignment alignment, final Gap gap, final Padding padding) {
this(alignment, Math.max(1, column_limit), -1, cellWidth, cellHeight, gap, padding);
@@ -112,7 +113,7 @@ public class GridLayout implements Group.Layout {
* @param cellWidth
* @param cellHeight
* @param alignment TODO
- * @param gap
+ * @param gap {@link Gap} is applied unscaled
* @param row_limit [1..inf)
*/
public GridLayout(final float cellWidth, final float cellHeight, final Alignment alignment, final Gap gap, final int row_limit) {
@@ -124,8 +125,8 @@ public class GridLayout implements Group.Layout {
* @param cellWidth
* @param cellHeight
* @param alignment TODO
- * @param gap
- * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)}
+ * @param gap {@link Gap} is applied unscaled
+ * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)} and is scaled if {@link Alignment.Bit#Fill}
* @param row_limit [1..inf)
*/
public GridLayout(final float cellWidth, final float cellHeight, final Alignment alignment, final Gap gap, final Padding padding, final int row_limit) {
@@ -205,11 +206,11 @@ public class GridLayout implements Group.Layout {
pmv.glPopMatrix();
final AABBox sbox = sboxes[i];
+ final float shapeWidthU = sbox.getWidth();
+ final float shapeHeightU = sbox.getHeight();
final float sxy;
if( isScaled ) {
// scaling to cell size
- final float shapeWidthU = sbox.getWidth();
- final float shapeHeightU = sbox.getHeight();
final float cellWidthU = hasCellWidth ? cellSize.x() : shapeWidthU;
final float cellHeightU = hasCellHeight ? cellSize.y() : shapeHeightU;
final float sx = cellWidthU / shapeWidthU;
@@ -218,8 +219,8 @@ public class GridLayout implements Group.Layout {
} else {
sxy = 1;
}
- final float shapeWidthS = sxy*sbox.getWidth();
- final float shapeHeightS = sxy*sbox.getHeight();
+ final float shapeWidthS = sxy * shapeWidthU;
+ final float shapeHeightS = sxy * shapeHeightU;
final float cellWidthS = hasCellWidth ? cellSize.x() : shapeWidthS;
final float cellHeightS = hasCellHeight ? cellSize.y() : shapeHeightS;
@@ -274,12 +275,12 @@ public class GridLayout implements Group.Layout {
}
// IF isScaled: Uniform scale w/ lowest axis scale and center position on lower-scale axis
+ final float shapeWidthU = sbox.getWidth();
+ final float shapeHeightU = sbox.getHeight();
final float sxy;
float dxh = 0, dyh = 0;
if( isScaled ) {
// scaling to cell size
- final float shapeWidthU = sbox.getWidth();
- final float shapeHeightU = sbox.getHeight();
final float cellWidth2 = hasCellWidth ? cellSize.x() : shapeWidthU;
final float cellHeight2 = hasCellHeight ? cellSize.y() : shapeHeightU;
final float sx = cellWidth2 / shapeWidthU;
@@ -293,8 +294,8 @@ public class GridLayout implements Group.Layout {
} else {
sxy = 1;
}
- final float shapeWidthS = sxy*sbox.getWidth();
- final float shapeHeightS = sxy*sbox.getHeight();
+ final float shapeWidthS = sxy * shapeWidthU;
+ final float shapeHeightS = sxy * shapeHeightU;
final float cellWidthS = hasCellWidth ? cellSize.x() : shapeWidthS;
final float cellHeightS = hasCellHeight ? cellSize.y() : shapeHeightS;
@@ -317,17 +318,11 @@ public class GridLayout implements Group.Layout {
s.moveTo( aX, aY, s.getPosition().z() );
// Remove the bottom-left delta
- final Vec3f diffBL = new Vec3f();
- {
- final AABBox sbox0 = s.getBounds();
- if( !diffBL.set( sbox0.getLow().x(), sbox0.getLow().y(), 0).min( zeroVec3 ).isZero() ) {
- // pmv.mulMvMatVec3f(diffBL_).scale(-1f, -1f, 0f);
- final Vec3f ss = s.getScale();
- diffBL.scale(-1f*ss.x(), -1f*ss.y(), 0f);
- }
- if( TRACE_LAYOUT ) {
- System.err.println("gl("+i+")["+col_i+"]["+row_i+"].bl: sbox0 "+sbox0+", diffBL_ "+diffBL);
- }
+ final Vec3f diffBL = new Vec3f(s.getBounds().getLow());
+ diffBL.setZ(0);
+ diffBL.scale(s.getScale()).scale(-1f);
+ if( TRACE_LAYOUT ) {
+ System.err.println("gl("+i+")["+col_i+"]["+row_i+"].bl: sbox0 "+s.getBounds()+", diffBL_ "+diffBL);
}
s.move( diffBL.scale(sxy) );