Class Clamp

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Orientable, Proxy

@Generated("org.javagi.JavaGI") public final class Clamp extends Widget implements Accessible, Buildable, ConstraintTarget, Orientable

A widget constraining its child to a given size.

clamp-wide clamp-narrow

The AdwClamp widget constrains the size of the widget it contains to a given maximum size. It will constrain the width if it is horizontal, or the height if it is vertical. The expansion of the child from its minimum to its maximum size is eased out for a smooth transition.

If the child requires more than the requested maximum size, it will be allocated the minimum size it can fit in instead.

AdwClamp can scale with the text scale factor, use the Clamp:unit property to enable that behavior.

See also: ClampLayout, ClampScrollable.

CSS nodes

AdwClamp has a single CSS node with name clamp.

  • Constructor Details

    • Clamp

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

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

    • getType

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

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

      protected Clamp 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 Widget
      Returns:
      the instance as if it were its parent type
    • getChild

      public @Nullable Widget getChild()
      Gets the child widget of self.
      Returns:
      the child widget of this Clamp
    • getMaximumSize

      public int getMaximumSize()
      Gets the maximum size allocated to the child.
      Returns:
      the maximum size to allocate to the child
    • getTighteningThreshold

      public int getTighteningThreshold()
      Gets the size above which the child is clamped.
      Returns:
      the size above which the child is clamped
    • getUnit

      public LengthUnit getUnit()
      Gets the length unit for maximum size and tightening threshold.
      Returns:
      the length unit
      Since:
      1.4
    • setChild

      public void setChild(@Nullable Widget child)
      Sets the child widget of self.
      Parameters:
      child - the child widget
    • setMaximumSize

      public void setMaximumSize(int maximumSize)

      Sets the maximum size allocated to the child.

      It is the width if the clamp is horizontal, or the height if it is vertical.

      Parameters:
      maximumSize - the maximum size
    • setTighteningThreshold

      public void setTighteningThreshold(int tighteningThreshold)

      Sets the size above which the child is clamped.

      Starting from this size, the clamp will tighten its grip on the child, slowly allocating less and less of the available size up to the maximum allocated size. Below that threshold and below the maximum size, the child will be allocated all the available size.

      If the threshold is greater than the maximum size to allocate to the child, the child will be allocated all the size up to the maximum. If the threshold is lower than the minimum size to allocate to the child, that size will be used as the tightening threshold.

      Effectively, tightening the grip on the child before it reaches its maximum size makes transitions to and from the maximum size smoother when resizing.

      Parameters:
      tighteningThreshold - the tightening threshold
    • setUnit

      public void setUnit(LengthUnit unit)

      Sets the length unit for maximum size and tightening threshold.

      Allows the sizes to vary depending on the text scale factor.

      Parameters:
      unit - the length unit
      Since:
      1.4
    • builder

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