Class Constraint

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Constraint extends GObject

Describes a constraint between attributes of two widgets, expressed as a linear equation.

The typical equation for a constraint is:

  target.target_attr = source.source_attr × multiplier + constant

Each GtkConstraint is part of a system that will be solved by a ConstraintLayout in order to allocate and position each child widget or guide.

The source and target, as well as their attributes, of a GtkConstraint instance are immutable after creation.

  • Constructor Details

    • Constraint

      public Constraint(MemorySegment address)
      Create a Constraint instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Constraint

      public Constraint(@Nullable ConstraintTarget target, ConstraintAttribute targetAttribute, ConstraintRelation relation, @Nullable ConstraintTarget source, ConstraintAttribute sourceAttribute, double multiplier, double constant, int strength)
      Creates a new constraint representing a relation between a layout attribute on a source and a layout attribute on a target.
      Parameters:
      target - the target of the constraint
      targetAttribute - the attribute of target to be set
      relation - the relation equivalence between target_attribute and source_attribute
      source - the source of the constraint
      sourceAttribute - the attribute of source to be read
      multiplier - a multiplication factor to be applied to source_attribute
      constant - a constant factor to be added to source_attribute
      strength - the strength of the constraint
    • Constraint

      public Constraint()
      Create a new Constraint.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Constraint class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Constraint asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • constant

      public static Constraint constant(@Nullable ConstraintTarget target, ConstraintAttribute targetAttribute, ConstraintRelation relation, double constant, int strength)
      Creates a new constraint representing a relation between a layout attribute on a target and a constant value.
      Parameters:
      target - a the target of the constraint
      targetAttribute - the attribute of target to be set
      relation - the relation equivalence between target_attribute and constant
      constant - a constant factor to be set on target_attribute
      strength - the strength of the constraint
      Returns:
      the newly created constraint
    • getConstant

      public double getConstant()
      Retrieves the constant factor added to the source attributes' value.
      Returns:
      a constant factor
    • getMultiplier

      public double getMultiplier()
      Retrieves the multiplication factor applied to the source attribute's value.
      Returns:
      a multiplication factor
    • getRelation

      public ConstraintRelation getRelation()
      The order relation between the terms of the constraint.
      Returns:
      a relation type
    • getSource

      public @Nullable ConstraintTarget getSource()

      Retrieves the ConstraintTarget used as the source for the constraint.

      If the source is set to NULL at creation, the constraint will use the widget using the ConstraintLayout as the source.

      Returns:
      the source of the constraint
    • getSourceAttribute

      public ConstraintAttribute getSourceAttribute()
      Retrieves the attribute of the source to be read by the constraint.
      Returns:
      the source's attribute
    • getStrength

      public int getStrength()
      Retrieves the strength of the constraint.
      Returns:
      the strength value
    • getTarget

      public @Nullable ConstraintTarget getTarget()

      Retrieves the ConstraintTarget used as the target for the constraint.

      If the targe is set to NULL at creation, the constraint will use the widget using the ConstraintLayout as the target.

      Returns:
      a GtkConstraintTarget
    • getTargetAttribute

      public ConstraintAttribute getTargetAttribute()
      Retrieves the attribute of the target to be set by the constraint.
      Returns:
      the target's attribute
    • isAttached

      public boolean isAttached()
      Checks whether the constraint is attached to a ConstraintLayout, and it is contributing to the layout.
      Returns:
      TRUE if the constraint is attached
    • isConstant

      public boolean isConstant()
      Checks whether the constraint describes a relation between an attribute on the Gtk.Constraint:target and a constant value.
      Returns:
      TRUE if the constraint is a constant relation
    • isRequired

      public boolean isRequired()
      Checks whether the constraint is a required relation for solving the constraint layout.
      Returns:
      true if the constraint is required
    • builder

      public static Constraint.Builder<? extends Constraint.Builder> builder()
      A Constraint.Builder object constructs a Constraint with the specified properties. Use the various set...() methods to set properties, and finish construction with Constraint.Builder.build().
      Returns:
      the builder object