28package com.jogamp.graph.ui.layout;
32import com.jogamp.graph.ui.Group;
33import com.jogamp.graph.ui.Shape;
34import com.jogamp.math.FloatUtil;
35import com.jogamp.math.Vec2f;
36import com.jogamp.math.Vec3f;
37import com.jogamp.math.geom.AABBox;
38import com.jogamp.math.util.PMVMatrix4f;
54 private final Vec2f cellSize;
57 private final Margin margin;
61 private static final boolean TRACE_LAYOUT =
false;
85 this(cellWidth, cellHeight, alignment,
Margin.
None,
null);
94 public BoxLayout(
final float cellWidth,
final float cellHeight,
final Margin margin) {
116 this(cellWidth, cellHeight,
Alignment.
None, margin, padding);
126 this(cellWidth, cellHeight, alignment, margin,
null);
137 this(cellWidth, cellHeight, alignment,
Margin.
None, padding);
149 this.cellSize =
new Vec2f(Math.max(0f, cellWidth), Math.max(0f, cellHeight));
150 this.alignment = alignment;
151 this.margin = margin;
152 this.padding = padding;
167 if(
null != padding && !padding.
zeroSize() ) {
180 final List<Shape> shapes = g.
getShapes();
182 for(
int i=0; i < shapes.size(); ++i) {
183 final Shape s = shapes.get(i);
191 final float x = 0, y = 0;
193 System.err.println(
"bl("+i+
").0: sbox "+sbox+
", s "+s);
197 final float shapeWidthU = sbox.
getWidth();
198 final float shapeHeightU = sbox.
getHeight();
203 float dxh = 0, dyh = 0;
206 final float cellWidth = hasCellWidth ? cellSize.x() - margin.
width() : shapeWidthU;
207 final float cellHeight = hasCellHeight ? cellSize.y() - margin.
height() : shapeHeightU;
208 final float sx = cellWidth / shapeWidthU;
209 final float sy = cellHeight/ shapeHeightU;
210 sxy = sx < sy ? sx : sy;
212 if( isCenteredHoriz ) {
213 dxh += shapeWidthU * ( sx - sxy ) * 0.5f;
215 if( isCenteredVert ) {
216 dyh += shapeHeightU * ( sy - sxy ) * 0.5f;
221 System.err.println(
"bl("+i+
").s: "+sx+
" x "+sy+
" -> "+sxy+
": +"+dxh+
" / "+dyh+
", U: s "+shapeWidthU+
" x "+shapeHeightU+
", sz "+cellWidth+
" x "+cellHeight);
226 final float shapeWidthS = sxy * shapeWidthU;
227 final float shapeHeightS = sxy * shapeHeightU;
228 final float cellWidthS = hasCellWidth ? cellSize.x() : shapeWidthS;
229 final float cellHeightS = hasCellHeight ? cellSize.y() : shapeHeightS;
233 if( isCenteredHoriz ) {
234 dxh += 0.5f * ( cellWidthS - shapeWidthS );
238 if( isCenteredVert ) {
239 dyh += 0.5f * ( cellHeightS - shapeHeightS );
246 System.err.println(
"bl("+i+
").m: "+x+
" / "+y+
" + "+dxh+
" / "+dyh+
", sxy "+sxy+
", S: s "+shapeWidthS+
" x "+shapeHeightS+
", sz "+cellWidthS+
" x "+cellHeightS);
257 if( isCenteredHoriz || isCenteredVert ) {
258 if( !isCenteredVert && diffBL.y() > 0 ) {
260 }
else if( !isCenteredHoriz && diffBL.x() > 0 ) {
269 System.err.println(
"bl("+i+
").bl: sbox0 "+s.
getBounds()+
", diffBL_ "+diffBL);
274 box.
resize( x + cellWidthS, y + cellHeightS, sbox.
getMaxZ());
276 s.scale( sxy, sxy, 1f);
279 System.err.println(
"bl("+i+
").x: "+dxh+
" / "+dyh+
" -> "+s.
getPosition()+
", p3 "+shapeWidthS+
" x "+shapeHeightS+
", sz3 "+cellWidthS+
" x "+cellHeightS+
", box "+box.
getWidth()+
" x "+box.
getHeight());
280 System.err.println(
"bl("+i+
").x: "+s);
281 System.err.println(
"bl("+i+
").x: "+box);
288 System.err.println(
"bl(X).x: "+box);
294 final String p_s = (
null == padding || padding.
zeroSize() ) ?
"" :
", "+padding.
toString();
296 return "Box[cell "+cellSize+
", a "+alignment+m_s+p_s+
"]";
Group of Shapes, optionally utilizing a Group.Layout.
List< Shape > getShapes()
Returns added Shapes.
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
final Shape move(final float dtx, final float dty, final float dtz)
Move about scaled distance.
final Vec3f getScale()
Returns scale Vec3f reference.
final Shape moveTo(final float tx, final float ty, final float tz)
Move to scaled position.
final Vec3f getPosition()
Returns position Vec3f reference, i.e.
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
final Shape setPaddding(final Padding padding)
Sets the unscaled padding for this shape, which is included in unscaled getBounds() and also includes...
final void applyMatToMv(final PMVMatrix4f pmv)
Applies the internal Matrix4f to the given modelview matrix, i.e.
Immutable layout alignment options, including Bit#Fill.
boolean isSet(final Bit bit)
static final Alignment None
No alignment constant.
GraphUI Stack Group.Layout.
Margin getMargin()
Returns given scaled Margin.
BoxLayout(final float cellWidth, final float cellHeight, final Padding padding)
BoxLayout(final float cellWidth, final float cellHeight, final Margin margin, final Padding padding)
Padding getPadding()
Returns given unscaled Padding, may be null if not given via constructor.
BoxLayout(final float cellWidth, final float cellHeight, final Margin margin)
Alignment getAlignment()
Returns given Alignment.
void preValidate(final Shape s)
Prepare given Shape before validation, e.g.
void layout(final Group g, final AABBox box, final PMVMatrix4f pmv)
Performing the layout of Group#getShapes(), called @ Shape#validate(GL2ES2) or Shape#validate(GLProfi...
BoxLayout(final float cellWidth, final float cellHeight, final Alignment alignment, final Padding padding)
BoxLayout(final float cellWidth, final float cellHeight, final Alignment alignment, final Margin margin, final Padding padding)
BoxLayout(final float cellWidth, final float cellHeight, final Alignment alignment)
BoxLayout(final Padding padding)
BoxLayout(final float cellWidth, final float cellHeight, final Alignment alignment, final Margin margin)
Vec2f getCellSize()
Returns the preset cell size.
GraphUI CSS property Margin, scaled space between or around elements and not included in the element'...
final float left
Scaled left value.
float height()
Return scaled height of vertical values bottom + top.
final float bottom
Scaled bottom value.
static final Margin None
Zero margin constant.
float width()
Return scaled width of horizontal values top + right.
GraphUI CSS property Padding, unscaled space belonging to the element and included in the element's s...
Basic Float math utility functions.
static boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.
2D Vector based upon two float components.
3D Vector based upon three float components.
Vec3f mul(final float val)
Returns this * val; creates new vector.
Vec3f scale(final float s)
this = this * s, returns this.
Vec3f min(final Vec3f m)
this = min(this, m), returns this.
Axis Aligned Bounding Box.
final Vec3f getLow()
Returns the minimum left-bottom-far (xyz) coordinate.
AABBox transform(final Matrix4f mat, final AABBox out)
Transform this box using the given Matrix4f into out @endiliteral.
final AABBox resize(final AABBox newBox)
Resize the AABBox to encapsulate another AABox.
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final Matrix4f getMv()
Returns the modelview matrix (Mv).
final PMVMatrix4f popMv()
Pop the modelview matrix from its stack.
final PMVMatrix4f pushMv()
Push the modelview matrix to its stack, while preserving its values.
CenterHoriz
Horizontal center alignment.
CenterVert
Vertical center alignment.
Fill
Scale object to parent size, e.g.
Layout for the GraphUI Group, called @ Shape#validate(GL2ES2) or Shape#validate(GLProfile).