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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected float
static final Unit
static final int
protected boolean
protected Unit
protected int
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 <D extends DimensionBase>
DchainDimensions
(BiFunction<DimensionBase, DimensionBase, D> constructor, DimensionBase[] dimensions) Helper method to chain dimensions based on the given constructor.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
getFactor
(RectTransform context, boolean isHorizontal) Returns the factor based on this dimension's unit and a given context element.getUnit()
boolean
isDirty
(RectTransform context, boolean isHorizontal) 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
Parses a string into a dimension instance.static Dimension.If
predicate
(boolean predicate, DimensionBase dimensionTrue, DimensionBase dimensionFalse) Creates a dimension based on a predicate.protected int
recompute
(RectTransform context, boolean isHorizontal) Computes the value of this dimension by multiplying the original value with a factor based on the unit.void
void
void
setValue
(int value) 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 int value -
unit
-
isDirty
protected boolean isDirty -
currentFactor
protected float currentFactor -
DEFAULT_VALUE
public static final int DEFAULT_VALUE- See Also:
-
DEFAULT_UNIT
-
-
Constructor Details
-
Dimension
public Dimension() -
Dimension
public Dimension(int 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:
context
- 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(int 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
public static DimensionBase parse(String input) throws IllegalArgumentException, InvalidStringException Parses 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 stringInvalidStringException
-
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
-
multiply
Creates a dimension based on the product of the values of two or more dimensions.- Throws:
InvalidArrayException
-
chainDimensions
public static <D extends DimensionBase> D chainDimensions(BiFunction<DimensionBase, DimensionBase, throws InvalidArrayExceptionD> constructor, DimensionBase[] dimensions) Helper method to chain dimensions based on the given constructor.- Type Parameters:
D
- The type of the chain dimension- Parameters:
constructor
- A constructor that creates a part of the dimension chaindimensions
- The dimensions to create a chain of- Returns:
- The chain of dimensions
- Throws:
InvalidArrayException
- If less than two dimensions are passed
-