Interface Constraint
- All Known Implementing Classes:
ConstraintImpl,ConstraintImpl.Between,ConstraintImpl.BetweenDynamic,ConstraintImpl.BetweenOffset,ConstraintImpl.BetweenOffsetDynamic,ConstraintImpl.Dynamic,ConstraintImpl.Literal,ConstraintImpl.MidPoint,ConstraintImpl.MidPointDynamic,ConstraintImpl.Relative,ConstraintImpl.RelativeDynamic
Constraints are used to define an elements position and shape by constraining the elements geometry parameters.
GeoParam
Constraints can be as simple as literal values representing an elements exact position and / or size in screen space,
They can be relative coordinates, (Relative to another element's Geometry)
Or they can be used to supply completely custom dynamic values.
All the built-in constraints are implemented and documented in this class.
Created by brandon3055 on 30/06/2023
- See Also:
-
Method Summary
Modifier and TypeMethodDescription@Nullable Axisaxis()static ConstraintImpl.BetweenContains a parameter to a fixed position between the two provided references.static ConstraintImpl.BetweenOffsetContains a parameter to a fixed position between the two provided references.Contains a parameter to a dynamic position between the two provided references.Contains a parameter to a dynamic position between the two provided references.static ConstraintImpl.DynamicConstrains a parameter to the value provided by the given supplier.doubleget()This method will return the current value of this constraint.static ConstraintImpl.Literalliteral(double value) This is the most basic constraint.voidThis is part of a late addition to improve performance.static ConstraintImpl.RelativeContains a parameter to the exact value of the given reference.static ConstraintImpl.MidPointContains a parameter to the mid-point between the two provided references.static ConstraintImpl.MidPointContains a parameter to the mid-point between the two provided references with a fixed offset.Contains a parameter to the mid-point between the two provided references with a dynamic offset.static ConstraintImpl.RelativeContains a parameter to the given reference plus the provided fixed offset.Contains a parameter to the given reference plus the provided dynamic offset.
-
Method Details
-
get
double get()This method will return the current value of this constraint. This could be a fixed stored value, or a dynamically computed value depending on the type of constraint.All position and size values in ModularGui are doubles. However, by default, all the builtin constraints will cast their outputs to integer values. This avoids a lot of random visual artifacts that can occur when using floating point values in MC Screens.
If you need floating-point precision, it can be enabled calling .precise() on any of the builtin constraints.
- Returns:
- The computed or stored value of this constraint.
-
axis
- Returns:
- the axis this constraint applies to, Ether X, Y or null for undefined.
-
markDirty
void markDirty()This is part of a late addition to improve performance. Rather than computing a constraint value every single time it is queried, which can be many, many times per render frame, We now cache the constraint value, and that cache is cleared at the start of each render frame. -
literal
This is the most basic constraint. It constrains a parameter to a single fixed value.- Parameters:
value- The fixed value that will be returned by this constraint.
-
dynamic
Constrains a parameter to the value provided by the given supplier.- Parameters:
valueSupplier- The dynamic value supplier.
-
match
Contains a parameter to the exact value of the given reference. This is effectively a relative constraint with no offset.- Parameters:
relativeTo- The relative geometry.
-
relative
Contains a parameter to the given reference plus the provided fixed offset.- Parameters:
relativeTo- The relative geometry.offset- The offset to apply.
-
relative
Contains a parameter to the given reference plus the provided dynamic offset.- Parameters:
relativeTo- The relative geometry.offset- The dynamic offset to apply.
-
between
Contains a parameter to a fixed position between the two provided references. Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0. To prevent this call .clamp() on the returned constraint.- Parameters:
start- The Start position.end- The End position.position- The position between start and end. (0=start to 1=end)
-
between
static ConstraintImpl.BetweenOffset between(GeoRef start, GeoRef end, double position, double offset) Contains a parameter to a fixed position between the two provided references. Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0. To prevent this call .clamp() on the returned constraint.This variant also allows a pixel offset.
- Parameters:
start- The Start position.end- The End position.position- The position between start and end. (0=start to 1=end)offset- position offset in pixels
-
between
Contains a parameter to a dynamic position between the two provided references. Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0. To prevent this call .clamp() on the returned constraint.- Parameters:
start- The Start position.end- The End position.position- The dynamic position between start and end. (0=start to 1=end)
-
between
static ConstraintImpl.BetweenDynamic between(GeoRef start, GeoRef end, Supplier<Double> position, Supplier<Double> offset) Contains a parameter to a dynamic position between the two provided references. Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0. To prevent this call .clamp() on the returned constraint.This variant also allows a pixel offset.
- Parameters:
start- The Start position.end- The End position.position- The dynamic position between start and end. (0=start to 1=end)offset- Dynamic position offset in pixels
-
midPoint
Contains a parameter to the mid-point between the two provided references.- Parameters:
start- The Start position.end- The End position.
-
midPoint
Contains a parameter to the mid-point between the two provided references with a fixed offset.- Parameters:
start- The Start position.end- The End position.offset- offset distance.
-
midPoint
Contains a parameter to the mid-point between the two provided references with a dynamic offset.- Parameters:
start- The Start position.end- The End position.offset- offset distance suppler.
-