Class Stack

All Implemented Interfaces:
PointerInterface

public class Stack extends Widget
`GtkStack` is a container which only shows one of its children
at a time.

In contrast to `GtkNotebook`, `GtkStack` does not provide a means
for users to change the visible child. Instead, a separate widget
such as [class@Gtk.StackSwitcher] or [class@Gtk.StackSidebar] can
be used with `GtkStack` to provide this functionality.

Transitions between pages can be animated as slides or fades. This
can be controlled with [method@Gtk.Stack.set_transition_type].
These animations respect the [property@Gtk.Settings:gtk-enable-animations]
setting.

`GtkStack` maintains a [class@Gtk.StackPage] object for each added
child, which holds additional per-child properties. You
obtain the `GtkStackPage` for a child with [method@Gtk.Stack.get_page]
and you can obtain a `GtkSelectionModel` containing all the pages
with [method@Gtk.Stack.get_pages].

# GtkStack as GtkBuildable

To set child-specific properties in a .ui file, create `GtkStackPage`
objects explicitly, and set the child widget as a property on it:

```xml
<object class="GtkStack" id="stack">
<child>
<object class="GtkStackPage">
<property name="name">page1</property>
<property name="title">In the beginning…</property>
<property name="child">
<object class="GtkLabel">
<property name="label">It was dark</property>
</object>
</property>
</object>
</child>
```

# CSS nodes

`GtkStack` has a single CSS node named stack.

# Accessibility

`GtkStack` uses the %GTK_ACCESSIBLE_ROLE_TAB_PANEL for the stack
pages, which are the accessible parent objects of the child widgets.

https://docs.gtk.org/gtk4/class.Stack.html

  • Constructor Details

    • Stack

      public Stack(PointerContainer pointer)
    • Stack

      public Stack()
      Creates a new `GtkStack`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • addChild

      public StackPage addChild(@Nonnull Widget child)
      Adds a child to @stack.
      Parameters:
      child - the widget to add
      Returns:
      the `GtkStackPage` for @child
    • addNamed

      public StackPage addNamed(@Nonnull Widget child, @Nullable Str name)
      Adds a child to @stack.

      The child is identified by the @name.
      Parameters:
      child - the widget to add
      name - the name for @child
      Returns:
      the `GtkStackPage` for @child
    • addNamed

      public StackPage addNamed(@Nonnull Widget child, String name)
      Adds a child to @stack.

      The child is identified by the @name.
      Parameters:
      child - the widget to add
      name - the name for @child
      Returns:
      the `GtkStackPage` for @child
    • addTitled

      public StackPage addTitled(@Nonnull Widget child, @Nullable Str name, @Nonnull Str title)
      Adds a child to @stack.

      The child is identified by the @name. The @title
      will be used by `GtkStackSwitcher` to represent
      @child in a tab bar, so it should be short.
      Parameters:
      child - the widget to add
      name - the name for @child
      title - a human-readable title for @child
      Returns:
      the `GtkStackPage` for @child
    • addTitled

      public StackPage addTitled(@Nonnull Widget child, String name, String title)
      Adds a child to @stack.

      The child is identified by the @name. The @title
      will be used by `GtkStackSwitcher` to represent
      @child in a tab bar, so it should be short.
      Parameters:
      child - the widget to add
      name - the name for @child
      title - a human-readable title for @child
      Returns:
      the `GtkStackPage` for @child
    • getChildByName

      public Widget getChildByName(@Nonnull Str name)
      Finds the child with the name given as the argument.

      Returns %NULL if there is no child with this name.
      Parameters:
      name - the name of the child to find
      Returns:
      the requested child of the `GtkStack`
    • getChildByName

      public Widget getChildByName(String name)
      Finds the child with the name given as the argument.

      Returns %NULL if there is no child with this name.
      Parameters:
      name - the name of the child to find
      Returns:
      the requested child of the `GtkStack`
    • getHhomogeneous

      public boolean getHhomogeneous()
      Gets whether @stack is horizontally homogeneous.
      Returns:
      whether @stack is horizontally homogeneous.
    • getInterpolateSize

      public boolean getInterpolateSize()
      Returns whether the `GtkStack` is set up to interpolate between
      the sizes of children on page switch.
      Returns:
      %TRUE if child sizes are interpolated
    • getPage

      public StackPage getPage(@Nonnull Widget child)
      Returns the `GtkStackPage` object for @child.
      Parameters:
      child - a child of @stack
      Returns:
      the `GtkStackPage` for @child
    • getPages

      public SelectionModel getPages()
      Returns a `GListModel` that contains the pages of the stack.

      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 modify the visible page.
      Returns:
      a `GtkSelectionModel` for the stack's children
    • getTransitionDuration

      public int getTransitionDuration()
      Returns the amount of time (in milliseconds) that
      transitions between pages in @stack will take.
      Returns:
      the transition duration
    • getTransitionRunning

      public boolean getTransitionRunning()
      Returns whether the @stack is currently in a transition from one page to
      another.
      Returns:
      %TRUE if the transition is currently running, %FALSE otherwise.
    • getTransitionType

      public int getTransitionType()
      Gets the type of animation that will be used
      for transitions between pages in @stack.
      Returns:
      the current transition type of @stack
    • getVhomogeneous

      public boolean getVhomogeneous()
      Gets whether @stack is vertically homogeneous.
      Returns:
      whether @stack is vertically homogeneous.
    • getVisibleChild

      public Widget getVisibleChild()
      Gets the currently visible child of @stack.

      Returns %NULL if there are no visible children.
      Returns:
      the visible child of the `GtkStack`
    • getVisibleChildName

      public Str getVisibleChildName()
      Returns the name of the currently visible child of @stack.

      Returns %NULL if there is no visible child.
      Returns:
      the name of the visible child of the `GtkStack`
    • remove

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

      public void setHhomogeneous(boolean hhomogeneous)
      Sets the `GtkStack` to be horizontally homogeneous or not.

      If it is homogeneous, the `GtkStack` will request the same
      width for all its children. If it isn't, the stack
      may change width when a different child becomes visible.
      Parameters:
      hhomogeneous - %TRUE to make @stack horizontally homogeneous
    • setInterpolateSize

      public void setInterpolateSize(boolean interpolate_size)
      Sets whether or not @stack will interpolate its size when
      changing the visible child.

      If the [property@Gtk.Stack:interpolate-size] property is set
      to %TRUE, @stack will interpolate its size between the current
      one and the one it'll take after changing the visible child,
      according to the set transition duration.
      Parameters:
      interpolate_size - the new value
    • setTransitionDuration

      public void setTransitionDuration(int duration)
      Sets the duration that transitions between pages in @stack
      will take.
      Parameters:
      duration - the new duration, in milliseconds
    • setTransitionType

      public void setTransitionType(int transition)
      Sets the type of animation that will be used for
      transitions between pages in @stack.

      Available types include various kinds of fades and slides.

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

      public void setVhomogeneous(boolean vhomogeneous)
      Sets the `GtkStack` to be vertically homogeneous or not.

      If it is homogeneous, the `GtkStack` will request the same
      height for all its children. If it isn't, the stack
      may change height when a different child becomes visible.
      Parameters:
      vhomogeneous - %TRUE to make @stack vertically homogeneous
    • setVisibleChild

      public void setVisibleChild(@Nonnull Widget child)
      Makes @child the visible child of @stack.

      If @child is different from the currently visible child,
      the transition between the two will be animated with the
      current transition type of @stack.

      Note that the @child widget has to be visible itself
      (see [method@Gtk.Widget.show]) in order to become the visible
      child of @stack.
      Parameters:
      child - a child of @stack
    • setVisibleChildFull

      public void setVisibleChildFull(@Nonnull Str name, int transition)
      Makes the child with the given name visible.

      Note that the child widget has to be visible itself
      (see [method@Gtk.Widget.show]) in order to become the visible
      child of @stack.
      Parameters:
      name - the name of the child to make visible
      transition - the transition type to use
    • setVisibleChildFull

      public void setVisibleChildFull(String name, int transition)
      Makes the child with the given name visible.

      Note that the child widget has to be visible itself
      (see [method@Gtk.Widget.show]) in order to become the visible
      child of @stack.
      Parameters:
      name - the name of the child to make visible
      transition - the transition type to use
    • setVisibleChildName

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

      If @child is different from the currently visible child,
      the transition between the two will be animated with the
      current transition type of @stack.

      Note that the child widget has to be visible itself
      (see [method@Gtk.Widget.show]) in order to become the visible
      child of @stack.
      Parameters:
      name - the name of the child to make visible
    • setVisibleChildName

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

      If @child is different from the currently visible child,
      the transition between the two will be animated with the
      current transition type of @stack.

      Note that the child widget has to be visible itself
      (see [method@Gtk.Widget.show]) in order to become the visible
      child of @stack.
      Parameters:
      name - the name of the child to make visible
    • 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
    • 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()