Class ViewStack

All Implemented Interfaces:
PointerInterface

public class ViewStack extends Widget
A view container for [class@ViewSwitcher].

`AdwViewStack` is a container which only shows one page at a time.
It is typically used to hold an application's main views.

It doesn't provide a way to transition between pages.
Instead, a separate widget such as [class@ViewSwitcher] can be used with
`AdwViewStack` to provide this functionality.

`AdwViewStack` pages can have a title, an icon, an attention request, and a
numbered badge that [class@ViewSwitcher] will use to let users identify which
page is which. Set them using the [property@ViewStackPage:title],
[property@ViewStackPage:icon-name],
[property@ViewStackPage:needs-attention], and
[property@ViewStackPage:badge-number] properties.

Unlike [class@Gtk.Stack], transitions between views are not animated.

`AdwViewStack` maintains a [class@ViewStackPage] object for each added child,
which holds additional per-child properties. You obtain the
[class@ViewStackPage] for a child with [method@ViewStack.get_page] and you
can obtain a [iface@Gtk.SelectionModel] containing all the pages with
[method@ViewStack.get_pages].

## AdwViewStack as GtkBuildable

To set child-specific properties in a .ui file, create
[class@ViewStackPage] objects explicitly, and set the child widget as a
property on it:

```xml
<object class="AdwViewStack" id="stack">
<child>
<object class="AdwViewStackPage">
<property name="name">overview</property>
<property name="title">Overview</property>
<property name="child">
<object class="AdwStatusPage">
<property name="title">Welcome!</property>
</object>
</property>
</object>
</child>
</object>
```

## CSS nodes

`AdwViewStack` has a single CSS node named `stack`.

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

  • Constructor Details

    • ViewStack

      public ViewStack(PointerContainer pointer)
    • ViewStack

      public ViewStack()
      Creates a new `AdwViewStack`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • add

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

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

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

      public ViewStackPage addNamed(@Nonnull Widget child, String name)
      Adds a child to @self.

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

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

      The child is identified by the @name. The @title will be used by
      [class@ViewSwitcher] to represent @child, 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 `AdwViewStackPage` for @child
    • addTitled

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

      The child is identified by the @name. The @title will be used by
      [class@ViewSwitcher] to represent @child, 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 `AdwViewStackPage` for @child
    • addTitledWithIcon

      public ViewStackPage addTitledWithIcon(@Nonnull Widget child, @Nullable Str name, @Nonnull Str title, @Nonnull Str icon_name)
      Adds a child to @self.

      The child is identified by the @name. The @title and @icon_name will be used
      by [class@ViewSwitcher] to represent @child.
      Parameters:
      child - the widget to add
      name - the name for @child
      title - a human-readable title for @child
      icon_name - an icon name for @child
      Returns:
      the `AdwViewStackPage` for @child
    • addTitledWithIcon

      public ViewStackPage addTitledWithIcon(@Nonnull Widget child, String name, String title, String icon_name)
      Adds a child to @self.

      The child is identified by the @name. The @title and @icon_name will be used
      by [class@ViewSwitcher] to represent @child.
      Parameters:
      child - the widget to add
      name - the name for @child
      title - a human-readable title for @child
      icon_name - an icon name for @child
      Returns:
      the `AdwViewStackPage` for @child
    • getChildByName

      public Widget getChildByName(@Nonnull Str name)
      Finds the child with @name in @self.
      Parameters:
      name - the name of the child to find
      Returns:
      the requested child
    • getChildByName

      public Widget getChildByName(String name)
      Finds the child with @name in @self.
      Parameters:
      name - the name of the child to find
      Returns:
      the requested child
    • getHhomogeneous

      public boolean getHhomogeneous()
      Gets whether @self is horizontally homogeneous.
      Returns:
      whether @self is horizontally homogeneous
    • getPage

      public ViewStackPage getPage(@Nonnull Widget child)
      Gets the [class@ViewStackPage] 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 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 change the visible
      page.
      Returns:
      a `GtkSelectionModel` for the stack's children
    • getVhomogeneous

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

      public Widget getVisibleChild()
      Gets the currently visible child of @self, .
      Returns:
      the visible child
    • getVisibleChildName

      public Str getVisibleChildName()
      Returns the name of the currently visible child of @self.
      Returns:
      the name of the visible child
    • remove

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

      public void setHhomogeneous(boolean hhomogeneous)
      Sets @self to be horizontally homogeneous or not.

      If the stack is horizontally homogeneous, it allocates the same width for
      all children.

      If it's `FALSE`, the stack may change width when a different child becomes
      visible.
      Parameters:
      hhomogeneous - whether to make @self horizontally homogeneous
    • setVhomogeneous

      public void setVhomogeneous(boolean vhomogeneous)
      Sets @self to be vertically homogeneous or not.

      If the stack is vertically homogeneous, it allocates the same height for
      all children.

      If it's `FALSE`, the stack may change height when a different child becomes
      visible.
      Parameters:
      vhomogeneous - whether to make @self vertically homogeneous
    • setVisibleChild

      public void setVisibleChild(@Nonnull Widget child)
      Makes @child the visible child of @self.
      Parameters:
      child - a child of @self
    • setVisibleChildName

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

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

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

      See [property@ViewStack:visible-child].
      Parameters:
      name - the name of the child
    • 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()