Class ViewStack

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

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

A view container for 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 ViewSwitcher, InlineViewSwitcher or ViewSwitcherSidebar 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 ViewSwitcher will use to let users identify which page is which. Set them using the ViewStackPage:title, ViewStackPage:icon-name, ViewStackPage:needs-attention, and ViewStackPage:badge-number properties.

AdwViewStack pages can also be grouped into sections, using the ViewStackPage:starts-section and ViewStackPage:section-title properties. Currently, only ViewSwitcherSidebar displays groups.

Unlike Stack, transitions between views can only be animated via a crossfade and size changes are always interpolated. Animations are disabled by default. Use ViewStack:enable-transitions to enable them.

AdwViewStack maintains a ViewStackPage object for each added child, which holds additional per-child properties. You obtain the ViewStackPage for a child with getPage(Widget) and you can obtain a SelectionModel containing all the pages with getPages().

AdwViewStack as GtkBuildable

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

  <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.

Accessibility

AdwViewStack uses the Gtk.AccessibleRole.tab-panel for the stack pages which are the accessible parent objects of the child widgets.

  • Constructor Details

    • ViewStack

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

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

    • getType

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

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

      protected ViewStack 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
    • add

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

      public ViewStackPage addNamed(Widget child, @Nullable 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(Widget child, @Nullable String name, String title)

      Adds a child to self.

      The child is identified by the name. The title will be used by 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(Widget child, @Nullable String name, String title, String iconName)

      Adds a child to self.

      The child is identified by the name. The title and iconName will be used by ViewSwitcher to represent child.

      Parameters:
      child - the widget to add
      name - the name for child
      title - a human-readable title for child
      iconName - an icon name for child
      Returns:
      the AdwViewStackPage for child
      Since:
      1.2
    • getChildByName

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

      public boolean getEnableTransitions()

      Gets whether this ViewStack uses a crossfade transition between pages.

      Use ViewStack:transition-duration to control the duration, and ViewStack:transition-running to know when the transition is running.

      Returns:
      whether to enable page transitions
      Since:
      1.7
    • getHhomogeneous

      public boolean getHhomogeneous()
      Gets whether this ViewStack is horizontally homogeneous.
      Returns:
      whether this ViewStack is horizontally homogeneous
    • getPage

      public ViewStackPage getPage(Widget child)
      Gets the ViewStackPage object for child.
      Parameters:
      child - a child of this ViewStack
      Returns:
      the page object for child
    • getPages

      public SelectionModel getPages()

      Returns a ListModel that contains the pages of the stack.

      This can be used to keep an up-to-date view.

      The model implements SectionModel and creates sections based on ViewStackPage:starts-section values.

      The model also implements SelectionModel and can be used to track and change the visible page.

      Returns:
      a GtkSelectionModel for the stack's children
    • getTransitionDuration

      public int getTransitionDuration()
      Gets the transition animation duration for self.
      Returns:
      the transition duration, in milliseconds
      Since:
      1.7
    • getTransitionRunning

      public boolean getTransitionRunning()

      Gets whether a transition is currently running for self.

      If a transition is impossible, the property value will be set to TRUE and then immediately to FALSE, so it's possible to rely on its notifications to know that a transition has happened.

      Returns:
      whether a transition is currently running
      Since:
      1.7
    • getVhomogeneous

      public boolean getVhomogeneous()
      Gets whether this ViewStack is vertically homogeneous.
      Returns:
      whether this ViewStack is vertically homogeneous
    • getVisibleChild

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

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

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

      public void setEnableTransitions(boolean enableTransitions)
      Sets whether this ViewStack uses a crossfade transition between pages.
      Parameters:
      enableTransitions - whether to enable page transitions
      Since:
      1.7
    • setHhomogeneous

      public void setHhomogeneous(boolean hhomogeneous)

      Sets this ViewStack 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 this ViewStack horizontally homogeneous
    • setTransitionDuration

      public void setTransitionDuration(int duration)

      Sets the transition animation duration for self.

      Only used when ViewStack:enable-transitions is set to TRUE.

      Parameters:
      duration - the new duration, in milliseconds
      Since:
      1.7
    • setVhomogeneous

      public void setVhomogeneous(boolean vhomogeneous)

      Sets this ViewStack 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 this ViewStack vertically homogeneous
    • setVisibleChild

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

      public void setVisibleChildName(String name)

      Makes the child with name visible.

      See ViewStack:visible-child.

      Parameters:
      name - the name of the child
    • builder

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