Class Leaflet

All Implemented Interfaces:
PointerInterface

public class Leaflet extends Widget
An adaptive container acting like a box or a stack.

<picture>
<source srcset="leaflet-wide-dark.png" media="(prefers-color-scheme: dark)">
<img src="leaflet-wide.png" alt="leaflet-wide">
</picture>
<picture>
<source srcset="leaflet-narrow-dark.png" media="(prefers-color-scheme: dark)">
<img src="leaflet-narrow.png" alt="leaflet-narrow">
</picture>

The `AdwLeaflet` widget can display its children like a [class@Gtk.Box] does
or like a [class@Gtk.Stack] does, adapting to size changes by switching
between the two modes.

When there is enough space the children are displayed side by side, otherwise
only one is displayed and the leaflet is said to be “folded”.
The threshold is dictated by the preferred minimum sizes of the children.
When a leaflet is folded, the children can be navigated using swipe gestures.

The “over” and “under” transition types stack the children one on top of the
other, while the “slide” transition puts the children side by side. While
navigating to a child on the side or below can be performed by swiping the
current child away, navigating to an upper child requires dragging it from
the edge where it resides. This doesn't affect non-dragging swipes.

## CSS nodes

`AdwLeaflet` has a single CSS node with name `leaflet`. The node will get the
style classes `.folded` when it is folded, `.unfolded` when it's not, or none
if it hasn't computed its fold yet.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Leaflet.html

  • Constructor Details

    • Leaflet

      public Leaflet(PointerContainer pointer)
    • Leaflet

      public Leaflet()
      Creates a new `AdwLeaflet`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • append

      public LeafletPage append(@Nonnull Widget child)
      Adds a child to @self.
      Parameters:
      child - the widget to add
      Returns:
      the [class@LeafletPage] for @child
    • getAdjacentChild

      public Widget getAdjacentChild(int direction)
      Finds the previous or next navigatable child.

      This will be the same child [method@Leaflet.navigate] or swipe gestures will
      navigate to.

      If there's no child to navigate to, `NULL` will be returned instead.

      See [property@LeafletPage:navigatable].
      Parameters:
      direction - the direction
      Returns:
      the previous or next child
    • getCanNavigateBack

      public boolean getCanNavigateBack()
      Gets whether gestures and shortcuts for navigating backward are enabled.
      Returns:
      Whether gestures and shortcuts are enabled.
    • getCanNavigateForward

      public boolean getCanNavigateForward()
      Gets whether gestures and shortcuts for navigating forward are enabled.
      Returns:
      Whether gestures and shortcuts are enabled.
    • getCanUnfold

      public boolean getCanUnfold()
      Gets whether @self can unfold.
      Returns:
      whether @self can unfold
    • getChildByName

      public Widget getChildByName(@Nonnull Str name)
      Finds the child of @self with @name.

      Returns `NULL` if there is no child with this name.

      See [property@LeafletPage:name].
      Parameters:
      name - the name of the child to find
      Returns:
      the requested child of @self
    • getChildByName

      public Widget getChildByName(String name)
      Finds the child of @self with @name.

      Returns `NULL` if there is no child with this name.

      See [property@LeafletPage:name].
      Parameters:
      name - the name of the child to find
      Returns:
      the requested child of @self
    • getChildTransitionParams

      public SpringParams getChildTransitionParams()
      Gets the child transition spring parameters for @self.
      Returns:
      the child transition parameters
    • getChildTransitionRunning

      public boolean getChildTransitionRunning()
      Gets whether a child transition is currently running for @self.
      Returns:
      whether a transition is currently running
    • getFoldThresholdPolicy

      public int getFoldThresholdPolicy()
      Gets the fold threshold policy for @self.
      Returns:
    • getFolded

      public boolean getFolded()
      Gets whether @self is folded.

      The leaflet will be folded if the size allocated to it is smaller than the
      sum of the minimum or natural sizes of the children (see
      [property@Leaflet:fold-threshold-policy]), it will be unfolded otherwise.
      Returns:
      whether @self is folded.
    • getHomogeneous

      public boolean getHomogeneous()
      Gets whether @self is homogeneous.
      Returns:
      whether @self is homogeneous
    • getModeTransitionDuration

      public int getModeTransitionDuration()
      Gets the mode transition animation duration for @self.
      Returns:
      the mode transition duration, in milliseconds.
    • getPage

      public LeafletPage getPage(@Nonnull Widget child)
      Returns the [class@LeafletPage] object for @child.
      Parameters:
      child - a child of @self
      Returns:
      the page object for @child
    • getPages

      public SelectionModel getPages()
      Returns a [iface@Gio.ListModel] that contains the pages of the leaflet.

      This can be used to keep an up-to-date view. The model also implements
      [iface@Gtk.SelectionModel] and can be used to track and change the visible
      page.
      Returns:
      a `GtkSelectionModel` for the leaflet's children
    • getTransitionType

      public int getTransitionType()
      Gets the type of animation used for transitions between modes and children.
      Returns:
      the current transition type of @self
    • getVisibleChild

      public Widget getVisibleChild()
      Gets the widget currently visible when the leaflet is folded.
      Returns:
      the visible child
    • getVisibleChildName

      public Str getVisibleChildName()
      Gets the name of the currently visible child widget.
      Returns:
      the name of the visible child
    • insertChildAfter

      public LeafletPage insertChildAfter(@Nonnull Widget child, @Nullable Widget sibling)
      Inserts @child in the position after @sibling in the list of children.

      If @sibling is `NULL`, inserts @child at the first position.
      Parameters:
      child - the widget to insert
      sibling - the sibling after which to insert @child
      Returns:
      the [class@LeafletPage] for @child
    • prepend

      public LeafletPage prepend(@Nonnull Widget child)
      Inserts @child at the first position in @self.
      Parameters:
      child - the widget to prepend
      Returns:
      the [class@LeafletPage] for @child
    • remove

      public void remove(@Nonnull Widget child)
      Removes a child widget from @self.
      Parameters:
      child - the child to remove
    • reorderChildAfter

      public void reorderChildAfter(@Nonnull Widget child, @Nullable Widget sibling)
      Moves @child to the position after @sibling in the list of children.

      If @sibling is `NULL`, moves @child to the first position.
      Parameters:
      child - the widget to move, must be a child of @self
      sibling - the sibling to move @child after
    • setCanNavigateBack

      public void setCanNavigateBack(boolean can_navigate_back)
      Sets whether gestures and shortcuts for navigating backward are enabled.

      The supported gestures are:

      - One-finger swipe on touchscreens
      - Horizontal scrolling on touchpads (usually two-finger swipe)
      - Back/forward mouse buttons

      The keyboard back/forward keys are also supported, as well as the
      <kbd>Alt</kbd>+<kbd>←</kbd> shortcut for horizontal orientation, or
      <kbd>Alt</kbd>+<kbd>↑</kbd> for vertical orientation.

      If the orientation is horizontal, for right-to-left locales, gestures and
      shortcuts are reversed.

      Only children that have [property@LeafletPage:navigatable] set to `TRUE` can
      be navigated to.
      Parameters:
      can_navigate_back - the new value
    • setCanNavigateForward

      public void setCanNavigateForward(boolean can_navigate_forward)
      Sets whether gestures and shortcuts for navigating forward are enabled.

      The supported gestures are:

      - One-finger swipe on touchscreens
      - Horizontal scrolling on touchpads (usually two-finger swipe)
      - Back/forward mouse buttons

      The keyboard back/forward keys are also supported, as well as the
      <kbd>Alt</kbd>+<kbd>→</kbd> shortcut for horizontal orientation, or
      <kbd>Alt</kbd>+<kbd>↓</kbd> for vertical orientation.

      If the orientation is horizontal, for right-to-left locales, gestures and
      shortcuts are reversed.

      Only children that have [property@LeafletPage:navigatable] set to `TRUE` can
      be navigated to.
      Parameters:
      can_navigate_forward - the new value
    • setCanUnfold

      public void setCanUnfold(boolean can_unfold)
      Sets whether @self can unfold.
      Parameters:
      can_unfold - whether @self can unfold
    • setChildTransitionParams

      public void setChildTransitionParams(@Nonnull SpringParams params)
      Sets the child transition spring parameters for @self.

      The default value is equivalent to:

      ```c
      adw_spring_params_new (1, 0.5, 500)
      ```
      Parameters:
      params - the new parameters
    • setFoldThresholdPolicy

      public void setFoldThresholdPolicy(int policy)
      Sets the fold threshold policy for @self.

      If set to `ADW_FOLD_THRESHOLD_POLICY_MINIMUM`, it will only fold when the
      children cannot fit anymore. With `ADW_FOLD_THRESHOLD_POLICY_NATURAL`, it
      will fold as soon as children don't get their natural size.

      This can be useful if you have a long ellipsizing label and want to let it
      ellipsize instead of immediately folding.
      Parameters:
      policy - the policy to use
    • setHomogeneous

      public void setHomogeneous(boolean homogeneous)
      Sets @self to be homogeneous or not.

      If set to `FALSE`, different children can have different size along the
      opposite orientation.
      Parameters:
      homogeneous - whether to make @self homogeneous
    • setModeTransitionDuration

      public void setModeTransitionDuration(int duration)
      Sets the mode transition animation duration for @self.
      Parameters:
      duration - the new duration, in milliseconds
    • setTransitionType

      public void setTransitionType(int transition)
      Sets the type of animation used for transitions between modes and children.

      The transition type can be changed without problems at runtime, so it is
      possible to change the animation based on the mode or child that is about to
      become current.
      Parameters:
      transition - the new transition type
    • setVisibleChild

      public void setVisibleChild(@Nonnull Widget visible_child)
      Sets the widget currently visible when the leaflet is folded.

      The transition is determined by [property@Leaflet:transition-type] and
      [property@Leaflet:child-transition-params]. The transition can be cancelled
      by the user, in which case visible child will change back to the previously
      visible child.
      Parameters:
      visible_child - the new child
    • setVisibleChildName

      public void setVisibleChildName(@Nonnull Str name)
      Makes the child with the name @name visible.

      See [property@Leaflet:visible-child].
      Parameters:
      name - the name of a child
    • setVisibleChildName

      public void setVisibleChildName(String name)
      Makes the child with the name @name visible.

      See [property@Leaflet:visible-child].
      Parameters:
      name - the name of a child
    • asSwipeable

      public Swipeable asSwipeable()
      Implements interface Swipeable. Call this to get access to interface functions.
      Returns:
      Swipeable
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • asOrientable

      public Orientable asOrientable()
      Implements interface Orientable. Call this to get access to interface functions.
      Returns:
      Orientable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()