diff options
author | Sven Gothel <[email protected]> | 2023-09-05 02:54:42 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-09-05 02:54:42 +0200 |
commit | ddd6cac8cc658ce542cb98e85f7d262f9917d37a (patch) | |
tree | 645516bebc945b5a853fd1ce54346d8abeb0235b /src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java | |
parent | f39a084c6a34a083698ca56e9122642e839234c2 (diff) |
GraphUI Layout: Fix BoxLayout scale, margin and padding; Add same padding behavior to BoxLayout and GridLayout.
For all:
- Padding is applied to each {@Shape} via {@link Shape#setPaddding(Padding)} if passed in constructor
BoxLayout:
- Optionally centered {@link Alignment.Bit#CenterHoriz horizontally}, {@link Alignment.Bit#CenterVert vertically} or {@link Alignment#Center both}.
- Optionally scaled to cell-size if given and {@link Alignment#Fill}
- Margin is ignored on dimension with center {@link Alignment}
- Not implemented {@link Alignment}: Top, Right, Bottom, Left
GridLayout:
- Optionally centered {@link Alignment.Bit#CenterHoriz horizontally}, {@link Alignment.Bit#CenterVert vertically} or {@link Alignment#Center both}.
- Optionally scaled to cell-size if given and {@link Alignment#Fill}
- Without cell-size behaves like a grid bag using individual shape sizes including padding
- Can be filled in {@link Order#COLUMN} or {@link Order#ROW} major-order.
- Not implemented {@link Alignment}: Top, Right, Bottom, Left
Changes to Group.Layout interface:
- Added preValidate(Shape) allowing to prepare the shape before validation, used to inject Padding
Changes to Margin:
- Removed the complex CENTER property and using Alignment in BoxLayout as well
Changes to BoxLayout:
- Using Alignment
+++
Tested via UILayoutBox01 and UILayoutGrid01,
try the tooltip by clicking on the group's description label.
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java | 127 |
1 files changed, 26 insertions, 101 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java b/src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java index 240053cb5..6e4bef169 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java +++ b/src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java @@ -31,16 +31,14 @@ import com.jogamp.opengl.math.FloatUtil; /** * GraphUI CSS property Margin, space between or around elements and not included in the element's size. - * + * <p> * The CSS margin properties are used to create space around elements, outside of any defined borders. - * - * {@link Margin#CENTER} is mapped to `zero` while earmarking {@link #isCenteredHoriz()} and {@link #isCenteredVert()}. - * The container must be sized via its layout horizontally and/or vertically matching the centered axis, similar to CSS. + * </p> + * <p> + * Center alignment is defined via {@link Alignment} and {@link Margin} ignored on centered dimension. + * </p> */ public class Margin { - /** Auto margin value to horizontally and/or vertically center an element within its sized-layout container, value if {@link Float#NaN}. */ - public static final float CENTER = Float.NaN; - /** Top value */ public final float top; /** Right value */ @@ -50,20 +48,6 @@ public class Margin { /** Left value */ public final float left; - private final int bits; - static private final int CENTER_HORIZ = 1 << 0; - static private final int CENTER_VERT = 1 << 1; - static private int getBits(final float top, final float right, final float bottom, final float left) { - int b = 0; - if( FloatUtil.isEqual(CENTER, left) && FloatUtil.isEqual(CENTER, right) ) { - b |= CENTER_HORIZ; - } - if( FloatUtil.isEqual(CENTER, top) && FloatUtil.isEqual(CENTER, bottom) ) { - b |= CENTER_VERT; - } - return b; - } - /** * Ctor w/ zero values */ @@ -79,105 +63,46 @@ public class Margin { * @param left left value */ public Margin(final float top, final float right, final float bottom, final float left) { - this.bits = getBits(top, right, bottom, left); - if( isCenteredVert() ) { - this.top = 0; - this.bottom = 0; - } else { - this.top = top; - this.bottom = bottom; - } - if( isCenteredHoriz() ) { - this.right = 0; - this.left = 0; - } else { - this.right = right; - this.left = left; - } + this.top = top; + this.bottom = bottom; + this.right = right; + this.left = left; } /** * Ctor * @param top top value - * @param rl right and left value, use {@link #CENTER} to horizontally center the element in its container + * @param rl right and left value * @param bottom bottom value */ public Margin(final float top, final float rl, final float bottom) { - this.bits = getBits(top, rl, bottom, rl); - if( isCenteredVert() ) { - this.top = 0; - this.bottom = 0; - } else { - this.top = top; - this.bottom = bottom; - } - if( isCenteredHoriz() ) { - this.right = 0; - this.left = 0; - } else { - this.right = rl; - this.left = rl; - } + this.top = top; + this.bottom = bottom; + this.right = rl; + this.left = rl; } /** * Ctor - * @param tb top and bottom value, use {@link #CENTER} to vertically center the element in its container - * @param rl right and left value, use {@link #CENTER} to horizontally center the element in its container + * @param tb top and bottom value + * @param rl right and left value */ public Margin(final float tb, final float rl) { - this.bits = getBits(tb, rl, tb, rl); - if( isCenteredVert() ) { - this.top = 0; - this.bottom = 0; - } else { - this.top = tb; - this.bottom = tb; - } - if( isCenteredHoriz() ) { - this.right = 0; - this.left = 0; - } else { - this.right = rl; - this.left = rl; - } + this.top = tb; + this.bottom = tb; + this.right = rl; + this.left = rl; } /** * Ctor - * @param trbl top, right, bottom and left value, use {@link #CENTER} to horizontally and vertically center the element in its container. + * @param trbl top, right, bottom and left value */ public Margin(final float trbl) { - this.bits = getBits(trbl, trbl, trbl, trbl); - if( isCenteredVert() ) { - this.top = 0; - this.bottom = 0; - } else { - this.top = trbl; - this.bottom = trbl; - } - if( isCenteredHoriz() ) { - this.right = 0; - this.left = 0; - } else { - this.right = trbl; - this.left = trbl; - } - } - - /** Returns true if {@link #left} and {@link #right} is {@link #CENTER}. */ - public boolean isCenteredHoriz() { - return 0 != ( CENTER_HORIZ & bits ); - } - - /** Returns true if {@link #top} and {@link #bottom} is {@link #CENTER}. */ - public boolean isCenteredVert() { - return 0 != ( CENTER_VERT & bits ); - } - - /** Returns true if {@link #isCenteredHoriz()} and {@link #isCenteredVert()} is true, i.e. for horizontal and vertical center. */ - public boolean isCentered() { - return 0 != ( ( CENTER_VERT | CENTER_HORIZ ) & bits ); + this.top = trbl; + this.bottom = trbl; + this.right = trbl; + this.left = trbl; } /** Return width of horizontal values top + right. Zero if {@link #isCenteredHoriz()}. */ @@ -193,5 +118,5 @@ public class Margin { public boolean zeroSumSize() { return zeroSumWidth() && zeroSumHeight(); } @Override - public String toString() { return "Margin[t "+top+", r "+right+", b "+bottom+", l "+left+", ctr[h "+isCenteredHoriz()+", v "+isCenteredVert()+"]]"; } + public String toString() { return "Margin[t "+top+", r "+right+", b "+bottom+", l "+left+"]"; } } |