JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
Margin.java
Go to the documentation of this file.
1/**
2 * Copyright 2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.graph.ui.layout;
29
30import com.jogamp.math.FloatUtil;
31
32/**
33 * GraphUI CSS property Margin, scaled space between or around elements and not included in the element's size.
34 * <p>
35 * The CSS margin properties are used to create space around elements, outside of any defined borders.
36 * </p>
37 * <p>
38 * Center alignment is defined via {@link Alignment} and {@link Margin} ignored with only center {@link Alignment} w/o {@link Alignment.Bit#Fill} scale.
39 * </p>
40 */
41public class Margin {
42 /** Zero margin constant. */
43 public static final Margin None = new Margin();
44
45 /** Scaled top value */
46 public final float top;
47 /** Scaled right value */
48 public final float right;
49 /** Scaled bottom value */
50 public final float bottom;
51 /** Scaled left value */
52 public final float left;
53
54 private Margin() {
55 this(0f);
56 }
57
58 /**
59 * Ctor
60 * @param top scaled top value
61 * @param right scaled right value
62 * @param bottom scaled bottom value
63 * @param left scaled left value
64 */
65 public Margin(final float top, final float right, final float bottom, final float left) {
66 this.top = top;
67 this.bottom = bottom;
68 this.right = right;
69 this.left = left;
70 }
71
72 /**
73 * Ctor
74 * @param top scaled top value
75 * @param rl scaled right and left value
76 * @param bottom scaled bottom value
77 */
78 public Margin(final float top, final float rl, final float bottom) {
79 this.top = top;
80 this.bottom = bottom;
81 this.right = rl;
82 this.left = rl;
83 }
84
85 /**
86 * Ctor
87 * @param tb scaled top and bottom value
88 * @param rl scaled right and left value
89 */
90 public Margin(final float tb, final float rl) {
91 this.top = tb;
92 this.bottom = tb;
93 this.right = rl;
94 this.left = rl;
95 }
96
97 /**
98 * Ctor
99 * @param trbl scaled top, right, bottom and left value
100 */
101 public Margin(final float trbl) {
102 this.top = trbl;
103 this.bottom = trbl;
104 this.right = trbl;
105 this.left = trbl;
106 }
107
108 /** Return scaled width of horizontal values top + right. Zero if {@link #isCenteredHoriz()}. */
109 public float width() { return left + right; }
110
111 /** Return scaled height of vertical values bottom + top. Zero if {@link #isCenteredVert()}. */
112 public float height() { return bottom + top; }
113
114 public boolean zeroWidth() { return FloatUtil.isZero( width() ); };
115
116 public boolean zeroHeight() { return FloatUtil.isZero( height() ); };
117
118 public boolean zeroSize() { return zeroWidth() && zeroHeight(); }
119
120 @Override
121 public String toString() { return "Margin[t "+top+", r "+right+", b "+bottom+", l "+left+"]"; }
122}
GraphUI CSS property Margin, scaled space between or around elements and not included in the element'...
Definition: Margin.java:41
Margin(final float top, final float right, final float bottom, final float left)
Ctor.
Definition: Margin.java:65
Margin(final float trbl)
Ctor.
Definition: Margin.java:101
final float top
Scaled top value.
Definition: Margin.java:46
final float left
Scaled left value.
Definition: Margin.java:52
Margin(final float top, final float rl, final float bottom)
Ctor.
Definition: Margin.java:78
float height()
Return scaled height of vertical values bottom + top.
Definition: Margin.java:112
final float right
Scaled right value.
Definition: Margin.java:48
Margin(final float tb, final float rl)
Ctor.
Definition: Margin.java:90
final float bottom
Scaled bottom value.
Definition: Margin.java:50
static final Margin None
Zero margin constant.
Definition: Margin.java:43
float width()
Return scaled width of horizontal values top + right.
Definition: Margin.java:109
Basic Float math utility functions.
Definition: FloatUtil.java:83
static boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.