Class Constraints

java.lang.Object
codechicken.lib.gui.modular.lib.Constraints

public class Constraints extends Object
This class contains a bunch of static helper methods that can be used to quickly apply common constraints. The plan is to keep adding common constraints to this class as they pop up.

Created by brandon3055 on 28/08/2023

  • Constructor Details

    • Constraints

      public Constraints()
  • Method Details

    • bind

      public static void bind(ConstrainedGeometry<?> element, ConstrainedGeometry<?> reference)
      Bind an elements geometry to a reference element.
      Parameters:
      element - The element to be bound.
      reference - The element to be bound to.
    • bind

      public static void bind(ConstrainedGeometry<?> element, ConstrainedGeometry<?> reference, double borders)
      Bind an elements geometry to a reference element with border offsets. (Border offsets may be positive or negative)
      Parameters:
      element - The element to be bound.
      reference - The element to be bound to.
    • bind

      public static void bind(ConstrainedGeometry<?> element, ConstrainedGeometry<?> reference, double top, double left, double bottom, double right)
      Bind an elements geometry to a reference element with border offsets. (Border offsets may be positive or negative)
      Parameters:
      element - The element to be bound.
      reference - The element to be bound to.
    • bind

      public static void bind(ConstrainedGeometry<?> element, ConstrainedGeometry<?> reference, Borders borders)
      Bind an elements geometry to a reference element with border offsets. (Border offsets may be positive or negative) The border offsets are dynamic, meaning if the values stored in the Borders object are updated, this binding will reflect those changes automatically.
      Parameters:
      element - The element to be bound.
      reference - The element to be bound to.
      borders - Border offsets.
    • size

      public static void size(ConstrainedGeometry<?> element, double width, double height)
    • size

      public static void size(ConstrainedGeometry<?> element, Supplier<Double> width, Supplier<Double> height)
    • pos

      public static void pos(ConstrainedGeometry<?> element, double left, double top)
    • pos

      public static void pos(ConstrainedGeometry<?> element, Supplier<Double> left, Supplier<Double> top)
    • center

      public static void center(ConstrainedGeometry<?> element, ConstrainedGeometry<?> centerOn)
    • center

      public static void center(ConstrainedGeometry<?> element, ConstrainedGeometry<?> centerOn, double xOffset, double yOffset)
    • placeInside

      @Deprecated public static void placeInside(ConstrainedGeometry<?> target, ConstrainedGeometry<?> reference, Constraints.LayoutPos position)
      Deprecated.
      Constrain the specified element to a position inside the specified targetElement. See the following image for an example of what each LayoutPos does: https://ss.brandon3055.com/e89a6
      Parameters:
      target - The element whose position we are setting.
      reference - The reference element, the element that target will be placed inside.
      position - The layout position.
    • placeInside

      @Deprecated public static void placeInside(ConstrainedGeometry<?> target, ConstrainedGeometry<?> reference, Constraints.LayoutPos position, double xOffset, double yOffset)
      Deprecated.
      Constrain the specified element to a position inside the specified targetElement. See the following image for an example of what each LayoutPos does: https://ss.brandon3055.com/e89a6
      Parameters:
      target - The element whose position we are setting.
      reference - The reference element, the element that target will be placed inside.
      position - The layout position.
      xOffset - Optional X offset to be applied to the final position.
      yOffset - Optional Y offset to be applied to the final position.
    • placeOutside

      @Deprecated public static void placeOutside(ConstrainedGeometry<?> target, ConstrainedGeometry<?> reference, Constraints.LayoutPos position)
      Deprecated.
      Constrain the specified element to a position outside the specified targetElement. See the following image for an example of what each LayoutPos does: https://ss.brandon3055.com/baa7c
      Parameters:
      target - The element whose position we are setting.
      reference - The reference element, the element that target will be placed outside of.
      position - The layout position.
    • placeOutside

      @Deprecated public static void placeOutside(ConstrainedGeometry<?> target, ConstrainedGeometry<?> reference, Constraints.LayoutPos position, double xOffset, double yOffset)
      Deprecated.
      Constrain the specified element to a position outside the specified targetElement. See the following image for an example of what each LayoutPos does: https://ss.brandon3055.com/baa7c
      Parameters:
      target - The element whose position we are setting.
      reference - The reference element, the element that target will be placed outside of.
      position - The layout position.
      xOffset - Optional X offset to be applied to the final position.
      yOffset - Optional Y offset to be applied to the final position.