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

public sealed interface Constraint permits ConstraintImpl<T>
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 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

      @Nullable @Nullable Axis 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

      static ConstraintImpl.Literal literal(double value)
      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

      static ConstraintImpl.Dynamic dynamic(Supplier<Double> valueSupplier)
      Constrains a parameter to the value provided by the given supplier.
      Parameters:
      valueSupplier - The dynamic value supplier.
    • match

      static ConstraintImpl.Relative match(GeoRef relativeTo)
      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

      static ConstraintImpl.Relative relative(GeoRef relativeTo, double offset)
      Contains a parameter to the given reference plus the provided fixed offset.
      Parameters:
      relativeTo - The relative geometry.
      offset - The offset to apply.
    • relative

      static ConstraintImpl.RelativeDynamic relative(GeoRef relativeTo, Supplier<Double> offset)
      Contains a parameter to the given reference plus the provided dynamic offset.
      Parameters:
      relativeTo - The relative geometry.
      offset - The dynamic offset to apply.
    • between

      static ConstraintImpl.Between between(GeoRef start, GeoRef end, double position)
      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

      static ConstraintImpl.BetweenDynamic between(GeoRef start, GeoRef end, Supplier<Double> position)
      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

      static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end)
      Contains a parameter to the mid-point between the two provided references.
      Parameters:
      start - The Start position.
      end - The End position.
    • midPoint

      static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end, double offset)
      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

      static ConstraintImpl.MidPointDynamic midPoint(GeoRef start, GeoRef end, Supplier<Double> offset)
      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.