adw.navigation_view

Module for NavigationView class

Types 3

A page-based navigation container.

navigation-view

adw.navigation_view.NavigationView presents one child at a time, similar to gtk.stack.Stack.

adw.navigation_view.NavigationView can only contain adw.navigation_page.NavigationPage children.

It maintains a navigation stack that can be controlled with adw.navigation_view.NavigationView.push and adw.navigation_view.NavigationView.pop. The whole navigation stack can also be replaced using adw.navigation_view.NavigationView.replace.

adw.navigation_view.NavigationView allows to manage pages statically or dynamically.

Static pages can be added using the adw.navigation_view.NavigationView.add method. The adw.navigation_view.NavigationView will keep a reference to these pages, but they aren't accessible to the user until adw.navigation_view.NavigationView.push is called (except for the first page, which is pushed automatically). Use the adw.navigation_view.NavigationView.remove method to remove them. This is useful for applications that have a small number of unique pages and just need navigation between them.

Dynamic pages are automatically destroyed once they are popped off the navigation stack. To add a page like this, push it using the adw.navigation_view.NavigationView.push method without calling adw.navigation_view.NavigationView.add first.

Tags

Static pages, as well as any pages in the navigation stack, can be accessed by their adw.navigation_page.NavigationPage.tag. For example, adw.navigation_view.NavigationView.pushByTag can be used to push a static page that's not in the navigation stack without having to keep a reference to it manually.

Header Bar Integration

When used inside adw.navigation_view.NavigationView, adw.header_bar.HeaderBar will automatically display a back button that can be used to go back to the previous page when possible. The button also has a context menu, allowing to pop multiple pages at once, potentially across multiple navigation views.

Set adw.header_bar.HeaderBar.showBackButton to FALSE to disable this behavior in rare scenarios where it's unwanted.

adw.header_bar.HeaderBar will also display the title of the adw.navigation_page.NavigationPage it's placed into, so most applications shouldn't need to customize it at all.

Shortcuts and Gestures

adw.navigation_view.NavigationView supports the following shortcuts for going to the previous page:

Additionally, it supports interactive gestures:

  • One-finger swipe towards the right on touchscreens
  • Scrolling towards the right on touchpads (usually two-finger swipe)

These gestures have transitions enabled regardless of the adw.navigation_view.NavigationView.animateTransitions value.

Applications can also enable shortcuts for pushing another page onto the navigation stack via connecting to the adw.navigation_view.NavigationView.getNextPage signal, in that case the following shortcuts are supported:

  • <kbd>Alt</kbd>+<kbd>→</kbd>
  • Forward mouse button
  • Swipe/scrolling towards the left

For right-to-left locales, the gestures and shortcuts are reversed.

adw.navigation_page.NavigationPage.canPop can be used to disable them, along with the header bar back buttons.

Actions

adw.navigation_view.NavigationView defines actions for controlling the navigation stack. actions for controlling the navigation stack:

adw.navigation_view.NavigationView as gtk.buildable.Buildable

adw.navigation_view.NavigationView allows to add pages as children, equivalent to using the adw.navigation_view.NavigationView.add method.

Example of an adw.navigation_view.NavigationView UI definition:

<object class="AdwNavigationView">
  <child>
    <object class="AdwNavigationPage">
      <property name="title" translatable="yes">Page 1</property>
      <property name="child">
        <object class="AdwToolbarView">
          <child type="top">
            <object class="AdwHeaderBar"/>
          </child>
          <property name="content">
            <object class="GtkButton">
              <property name="label" translatable="yes">Open Page 2</property>
              <property name="halign">center</property>
              <property name="valign">center</property>
              <property name="action-name">navigation.push</property>
              <property name="action-target">'page-2'</property>
              <style>
                <class name="pill"/>
               </style>
            </object>
          </property>
        </object>
      </property>
    </object>
  </child>
  <child>
    <object class="AdwNavigationPage">
      <property name="title" translatable="yes">Page 2</property>
      <property name="tag">page-2</property>
      <property name="child">
        <object class="AdwToolbarView">
          <child type="top">
            <object class="AdwHeaderBar"/>
          </child>
          <property name="content">
            <!-- ... -->
          </property>
        </object>
      </property>
    </object>
  </child>
</object>

navigation-view-example

CSS nodes

adw.navigation_view.NavigationView has a single CSS node with the name navigation-view.

Accessibility

adw.navigation_view.NavigationView uses the gtk.types.AccessibleRole.Group role.

Methods
GType _gType() @property
NavigationView self()Returns `this`, for use in `with` statements.
NavigationViewGidBuilder builder()Get builder for [adw.navigation_view.NavigationView] Returns: New builder object
bool animateTransitions() @propertyGet `animateTransitions` property. Returns: Whether to animate page transitions.
void animateTransitions(bool propval) @propertySet `animateTransitions` property. Params: propval = Whether to animate page transitions.
gio.list_model.ListModel navigationStack() @propertyGet `navigationStack` property. Returns: A list model that contains the pages in navigation stack.
bool popOnEscape() @propertyGet `popOnEscape` property. Returns: Whether pressing Escape pops the current page.
void popOnEscape(bool propval) @propertySet `popOnEscape` property. Params: propval = Whether pressing Escape pops the current page.
adw.navigation_page.NavigationPage visiblePage() @propertyGet `visiblePage` property. Returns: The currently visible page.
void add(adw.navigation_page.NavigationPage page)Permanently adds page to self.
adw.navigation_page.NavigationPage findPage(string tag)Finds a page in self by its tag.
bool getAnimateTransitions()Gets whether self animates page transitions. Returns: whether to animate page transitions
gio.list_model.ListModel getNavigationStack()Returns a [gio.list_model.ListModel] that contains the pages in navigation stack.
bool getPopOnEscape()Gets whether pressing Escape pops the current page on self. Returns: whether to pop the current page
adw.navigation_page.NavigationPage getVisiblePage()Gets the currently visible page in self. Returns: the currently visible page
bool pop()Pops the visible page from the navigation stack.
bool popToPage(adw.navigation_page.NavigationPage page)Pops pages from the navigation stack until page is visible.
bool popToTag(string tag)Pops pages from the navigation stack until page with the tag tag is visible.
void push(adw.navigation_page.NavigationPage page)Pushes page onto the navigation stack.
void pushByTag(string tag)Pushes the page with the tag tag onto the navigation stack.
void remove(adw.navigation_page.NavigationPage page)Removes page from self.
void replace(adw.navigation_page.NavigationPage[] pages)Replaces the current navigation stack with pages.
void replaceWithTags(string[] tags)Replaces the current navigation stack with pages with the tags tags.
void setAnimateTransitions(bool animateTransitions)Sets whether self should animate page transitions.
void setPopOnEscape(bool popOnEscape)Sets whether pressing Escape pops the current page on self.
gulong connectGetNextPage(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T : adw.navigation_page.NavigationPage) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : adw.navigation_view.NavigationView))) && Parameters!T.length < 2)Connect to `GetNextPage` signal.
gulong connectPopped(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : adw.navigation_page.NavigationPage))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : adw.navigation_view.NavigationView))) && Parameters!T.length < 3)Connect to `Popped` signal.
gulong connectPushed(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : adw.navigation_view.NavigationView))) && Parameters!T.length < 2)Connect to `Pushed` signal.
gulong connectReplaced(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : adw.navigation_view.NavigationView))) && Parameters!T.length < 2)Connect to `Replaced` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new [adw.navigation_view.NavigationView]. Returns: the new created [adw.navigation_view.NavigationView]

Fluent builder implementation template for adw.navigation_view.NavigationView

Methods
T animateTransitions(bool propval)Set `animateTransitions` property. Params: propval = Whether to animate page transitions.
T popOnEscape(bool propval)Set `popOnEscape` property. Params: propval = Whether pressing Escape pops the current page.