Class Dimension
java.lang.Object
dev.prozilla.pine.common.math.dimension.DimensionBase
dev.prozilla.pine.common.math.dimension.Dimension
- All Implemented Interfaces:
Cloneable<DimensionBase>
,Printable
Dimension of a UI element, defined by the combination of a value and a unit or by a function that computes the value of a dimension.
The dimension system is based on the CSS length data type,
and has similar features and conventions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
static class
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected float
static final Unit
static final float
protected boolean
protected Unit
protected float
Fields inherited from class dev.prozilla.pine.common.math.dimension.DimensionBase
computedValue, DEFAULT_DIRTY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Dimension.Add
add
(DimensionBase... dimensions) Creates a dimension based on the sum of the values of two or more dimensions.static Dimension
auto()
Creates a dimension that automatically computes, regardless of its value.static Dimension.Clamp
clamp
(DimensionBase dimension, DimensionBase dimensionMin, DimensionBase dimensionMax) Creates a dimension based on the lowest value of two dimensions.clone()
Returns a clone of this dimension.boolean
equals
(DimensionBase dimensionBase) Checks whether this dimension is equal to a given dimension.protected float
Returns the factor based on this dimension's unit and a given context element.getUnit()
boolean
Checks whether this dimension has been modified since the last calculation.static boolean
static Dimension.Max
max
(DimensionBase... dimensions) Creates a dimension based on the highest value of two or more dimensions.static Dimension.Min
min
(DimensionBase... dimensions) Creates a dimension based on the lowest value of two or more dimensions.static Dimension.Multiply
multiply
(DimensionBase... dimensions) Creates a dimension based on the product of the values of two or more dimensions.static Dimension
static DimensionBase
Deprecated.static Dimension.If
predicate
(boolean predicate, DimensionBase dimensionTrue, DimensionBase dimensionFalse) Creates a dimension based on a predicate.protected float
Computes the value of this dimension by multiplying the original value with a factor based on the unit.void
void
void
setValue
(float value) static Dimension.Subtract
subtract
(DimensionBase... dimensions) Creates a dimension based on the difference of the values of two or more dimensions.toString()
Returns the string representation of this dimension.static Dimension
Creates a dimension based on the viewport height.static Dimension
Creates a dimension based on the viewport width.static Dimension
zero()
Creates a dimension with value0
.Methods inherited from class dev.prozilla.pine.common.math.dimension.DimensionBase
compute, equals, hashCode
-
Field Details
-
value
protected float value -
unit
-
isDirty
protected boolean isDirty -
currentFactor
protected float currentFactor -
DEFAULT_VALUE
public static final float DEFAULT_VALUE- See Also:
-
DEFAULT_UNIT
-
-
Constructor Details
-
Dimension
public Dimension() -
Dimension
public Dimension(float value) -
Dimension
-
-
Method Details
-
recompute
Computes the value of this dimension by multiplying the original value with a factor based on the unit.- Specified by:
recompute
in classDimensionBase
- Parameters:
node
- UI element, serving as the context of this dimension.- Returns:
- The computed value of this dimension in pixels.
-
isDirty
Description copied from class:DimensionBase
Checks whether this dimension has been modified since the last calculation.- Overrides:
isDirty
in classDimensionBase
- Returns:
- True if this dimension has been modified.
-
getUnit
- Overrides:
getUnit
in classDimensionBase
-
equals
Description copied from class:DimensionBase
Checks whether this dimension is equal to a given dimension.- Specified by:
equals
in interfaceCloneable<DimensionBase>
- Specified by:
equals
in classDimensionBase
- Parameters:
dimensionBase
- Other dimension- Returns:
true
if both objects are equal.
-
toString
Description copied from class:DimensionBase
Returns the string representation of this dimension.- Specified by:
toString
in interfacePrintable
- Specified by:
toString
in classDimensionBase
- Returns:
- String representation of this object.
-
getFactor
Returns the factor based on this dimension's unit and a given context element. -
set
-
setValue
public void setValue(float value) -
setUnit
-
clone
Description copied from class:DimensionBase
Returns a clone of this dimension.- Specified by:
clone
in interfaceCloneable<DimensionBase>
- Specified by:
clone
in classDimensionBase
- Returns:
- New dimension instance
-
isValid
-
parse
Deprecated.Replaced byDimensionParser
as of 1.2.0Parses a string into a dimension instance.- Parameters:
input
- Input string- Returns:
- New dimension with based on input string
- Throws:
IllegalArgumentException
- Wheninput
is not a valid dimension string
-
zero
Creates a dimension with value0
. -
auto
Creates a dimension that automatically computes, regardless of its value. -
viewportWidth
Creates a dimension based on the viewport width. -
viewportHeight
Creates a dimension based on the viewport height. -
parentSize
-
max
Creates a dimension based on the highest value of two or more dimensions.- Throws:
InvalidArrayException
-
min
Creates a dimension based on the lowest value of two or more dimensions.- Throws:
InvalidArrayException
-
clamp
public static Dimension.Clamp clamp(DimensionBase dimension, DimensionBase dimensionMin, DimensionBase dimensionMax) Creates a dimension based on the lowest value of two dimensions. -
predicate
public static Dimension.If predicate(boolean predicate, DimensionBase dimensionTrue, DimensionBase dimensionFalse) Creates a dimension based on a predicate. -
add
Creates a dimension based on the sum of the values of two or more dimensions.- Throws:
InvalidArrayException
-
subtract
Creates a dimension based on the difference of the values of two or more dimensions.- Throws:
InvalidArrayException
-
multiply
Creates a dimension based on the product of the values of two or more dimensions.- Throws:
InvalidArrayException
-
DimensionParser
as of 1.2.0