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 classstatic classstatic classstatic classstatic classstatic classstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected floatstatic final Unitstatic final floatprotected booleanprotected Unitprotected floatFields inherited from class dev.prozilla.pine.common.math.dimension.DimensionBase
computedValue, DEFAULT_DIRTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Dimension.Addadd(DimensionBase... dimensions) Creates a dimension based on the sum of the values of two or more dimensions.static Dimensionauto()Creates a dimension that automatically computes, regardless of its value.static Dimension.Clampclamp(DimensionBase dimension, DimensionBase dimensionMin, DimensionBase dimensionMax) Creates a dimension based on the lowest value of two dimensions.clone()Returns a clone of this dimension.booleanequals(DimensionBase dimensionBase) Checks whether this dimension is equal to a given dimension.protected floatReturns the factor based on this dimension's unit and a given context element.getUnit()booleanChecks whether this dimension has been modified since the last calculation.static booleanstatic Dimension.Maxmax(DimensionBase... dimensions) Creates a dimension based on the highest value of two or more dimensions.static Dimension.Minmin(DimensionBase... dimensions) Creates a dimension based on the lowest value of two or more dimensions.static Dimension.Multiplymultiply(DimensionBase... dimensions) Creates a dimension based on the product of the values of two or more dimensions.static Dimensionstatic DimensionBaseDeprecated.static Dimension.Ifpredicate(boolean predicate, DimensionBase dimensionTrue, DimensionBase dimensionFalse) Creates a dimension based on a predicate.protected floatComputes the value of this dimension by multiplying the original value with a factor based on the unit.voidvoidvoidsetValue(float value) static Dimension.Subtractsubtract(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 DimensionCreates a dimension based on the viewport height.static DimensionCreates a dimension based on the viewport width.static Dimensionzero()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:
recomputein 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:DimensionBaseChecks whether this dimension has been modified since the last calculation.- Overrides:
isDirtyin classDimensionBase- Returns:
- True if this dimension has been modified.
-
getUnit
- Overrides:
getUnitin classDimensionBase
-
equals
Description copied from class:DimensionBaseChecks whether this dimension is equal to a given dimension.- Specified by:
equalsin interfaceCloneable<DimensionBase>- Specified by:
equalsin classDimensionBase- Parameters:
dimensionBase- Other dimension- Returns:
trueif both objects are equal.
-
toString
Description copied from class:DimensionBaseReturns the string representation of this dimension.- Specified by:
toStringin interfacePrintable- Specified by:
toStringin 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:DimensionBaseReturns a clone of this dimension.- Specified by:
clonein interfaceCloneable<DimensionBase>- Specified by:
clonein classDimensionBase- Returns:
- New dimension instance
-
isValid
-
parse
Deprecated.Replaced byDimensionParseras of 1.2.0Parses a string into a dimension instance.- Parameters:
input- Input string- Returns:
- New dimension with based on input string
- Throws:
IllegalArgumentException- Wheninputis 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
-
DimensionParseras of 1.2.0