Klasse NavigationView

Alle implementierten Schnittstellen:
PointerInterface

public class NavigationView extends Widget
A page-based navigation container.

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

`AdwNavigationView` presents one child at a time, similar to
[class@Gtk.Stack].

`AdwNavigationView` can only contain [class@NavigationPage] children.

It maintains a navigation stack that can be controlled with
[method@NavigationView.push] and [method@NavigationView.pop]. The whole
navigation stack can also be replaced using [method@NavigationView.replace].

`AdwNavigationView` allows to manage pages statically or dynamically.

Static pages can be added using the [method@NavigationView.add] method. The
`AdwNavigationView` will keep a reference to these pages, but they aren't
accessible to the user until [method@NavigationView.push] is called (except
for the first page, which is pushed automatically). Use the
[method@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
[method@NavigationView.push] method without calling
[method@NavigationView.add] first.

## Tags

Static pages, as well as any pages in the navigation stack, can be accessed
by their [property@NavigationPage:tag]. For example,
[method@NavigationView.push_by_tag] 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 `AdwNavigationView`, [class@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 [property@HeaderBar:show-back-button] to `FALSE` to disable this behavior
in rare scenarios where it's unwanted.

`AdwHeaderBar` will also display the title of the `AdwNavigationPage` it's
placed into, so most applications shouldn't need to customize it at all.

## Shortcuts and Gestures

`AdwNavigationView` supports the following shortcuts for going to the
previous page:

- <kbd>Escape</kbd> (unless [property@NavigationView:pop-on-escape] is set to
`FALSE`)
- <kbd>Alt</kbd>+<kbd>←</kbd>
- Back mouse button

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
[property@NavigationView:animate-transitions] value.

Applications can also enable shortcuts for pushing another page onto the
navigation stack via connecting to the [signal@NavigationView::get-next-page]
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.

[property@NavigationPage:can-pop] can be used to disable them, along with the
header bar back buttons.

## Actions

`AdwNavigationView` defines actions for controlling the navigation stack.
actions for controlling the navigation stack:

- `navigation.push` takes a string parameter specifying the tag of the page to
push, and is equivalent to calling [method@NavigationView.push_by_tag].

- `navigation.pop` doesn't take any parameters and pops the current page from
the navigation stack, equivalent to calling [method@NavigationView.pop].

## `AdwNavigationView` as `GtkBuildable`

`AdwNavigationView` allows to add pages as children, equivalent to using the
[method@NavigationView.add] method.

Example of an `AdwNavigationView` UI definition:

```xml
<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>
```

<picture>
<source srcset="navigation-view-example-dark.png" media="(prefers-color-scheme: dark)">
<img src="navigation-view-example.png" alt="navigation-view-example">
</picture>

## CSS nodes

`AdwNavigationView` has a single CSS node with the name `navigation-view`.

## Accessibility

`AdwNavigationView` uses the `GTK_ACCESSIBLE_ROLE_GROUP` role.

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

  • Felddetails

  • Konstruktordetails

    • NavigationView

      public NavigationView(PointerContainer pointer)
    • NavigationView

      public NavigationView()
      Creates a new `AdwNavigationView`.
  • Methodendetails

    • getClassHandler

      public static ClassHandler getClassHandler()
    • add

      public void add(@Nonnull NavigationPage page)
      Permanently adds @page to @self.

      Any page that has been added will stay in @self even after being popped from
      the navigation stack.

      Adding a page while no page is visible will automatically push it to the
      navigation stack.

      See [method@NavigationView.remove].
      Parameter:
      page - the page to add
    • findPage

      public NavigationPage findPage(@Nonnull Str tag)
      Finds a page in @self by its tag.

      See [property@NavigationPage:tag].
      Parameter:
      tag - a page tag
      Gibt zurück:
      the page with the given tag
    • findPage

      public NavigationPage findPage(String tag)
      Finds a page in @self by its tag.

      See [property@NavigationPage:tag].
      Parameter:
      tag - a page tag
      Gibt zurück:
      the page with the given tag
    • getAnimateTransitions

      public boolean getAnimateTransitions()
      Gets whether @self animates page transitions.
      Gibt zurück:
      whether to animate page transitions
    • getHhomogeneous

      public boolean getHhomogeneous()
      Gets whether @self is horizontally homogeneous.
      Gibt zurück:
      whether @self is horizontally homogeneous
    • getNavigationStack

      public ListModel getNavigationStack()
      Returns a [iface@Gio.ListModel] that contains the pages in navigation stack.

      The pages are sorted from root page to visible page.

      This can be used to keep an up-to-date view.
      Gibt zurück:
      a list model for the navigation stack
    • getPopOnEscape

      public boolean getPopOnEscape()
      Gets whether pressing Escape pops the current page on @self.
      Gibt zurück:
      whether to pop the current page
    • getPreviousPage

      public NavigationPage getPreviousPage(@Nonnull NavigationPage page)
      Gets the previous page for @page.

      If @page is in the navigation stack, returns the page popping @page will
      reveal.

      If @page is the root page or is not in the navigation stack, returns `NULL`.
      Parameter:
      page - a page in @self
      Gibt zurück:
      the previous page
    • getVhomogeneous

      public boolean getVhomogeneous()
      Gets whether @self is vertically homogeneous.
      Gibt zurück:
      whether @self is vertically homogeneous
    • getVisiblePage

      public NavigationPage getVisiblePage()
      Gets the currently visible page in @self.
      Gibt zurück:
      the currently visible page
    • getVisiblePageTag

      public Str getVisiblePageTag()
      Gets the tag of the currently visible page in @self.
      Gibt zurück:
      the tag of the currently visible page
    • pop

      public boolean pop()
      Pops the visible page from the navigation stack.

      Does nothing if the navigation stack contains less than two pages.

      If [method@NavigationView.add] hasn't been called, the page is automatically
      removed.

      [signal@NavigationView::popped] will be emitted for the current visible page.

      See [method@NavigationView.pop_to_page] and
      [method@NavigationView.pop_to_tag].
      Gibt zurück:
      `TRUE` if a page has been popped
    • popToPage

      public boolean popToPage(@Nonnull NavigationPage page)
      Pops pages from the navigation stack until @page is visible.

      @page must be in the navigation stack.

      If [method@NavigationView.add] hasn't been called for any of the popped pages,
      they are automatically removed.

      [signal@NavigationView::popped] will be be emitted for each of the popped
      pages.

      See [method@NavigationView.pop] and [method@NavigationView.pop_to_tag].
      Parameter:
      page - the page to pop to
      Gibt zurück:
      `TRUE` if any pages have been popped
    • popToTag

      public boolean popToTag(@Nonnull Str tag)
      Pops pages from the navigation stack until page with the tag @tag is visible.

      The page must be in the navigation stack.

      If [method@NavigationView.add] hasn't been called for any of the popped pages,
      they are automatically removed.

      [signal@NavigationView::popped] will be emitted for each of the popped pages.

      See [method@NavigationView.pop_to_page] and [property@NavigationPage:tag].
      Parameter:
      tag - a page tag
      Gibt zurück:
      `TRUE` if any pages have been popped
    • popToTag

      public boolean popToTag(String tag)
      Pops pages from the navigation stack until page with the tag @tag is visible.

      The page must be in the navigation stack.

      If [method@NavigationView.add] hasn't been called for any of the popped pages,
      they are automatically removed.

      [signal@NavigationView::popped] will be emitted for each of the popped pages.

      See [method@NavigationView.pop_to_page] and [property@NavigationPage:tag].
      Parameter:
      tag - a page tag
      Gibt zurück:
      `TRUE` if any pages have been popped
    • push

      public void push(@Nonnull NavigationPage page)
      Pushes @page onto the navigation stack.

      If [method@NavigationView.add] hasn't been called, the page is automatically
      removed once it's popped.

      [signal@NavigationView::pushed] will be emitted for @page.

      See [method@NavigationView.push_by_tag].
      Parameter:
      page - the page to push
    • pushByTag

      public void pushByTag(@Nonnull Str tag)
      Pushes the page with the tag @tag onto the navigation stack.

      If [method@NavigationView.add] hasn't been called, the page is automatically
      removed once it's popped.

      [signal@NavigationView::pushed] will be emitted for the page.

      See [method@NavigationView.push] and [property@NavigationPage:tag].
      Parameter:
      tag - the page tag
    • pushByTag

      public void pushByTag(String tag)
      Pushes the page with the tag @tag onto the navigation stack.

      If [method@NavigationView.add] hasn't been called, the page is automatically
      removed once it's popped.

      [signal@NavigationView::pushed] will be emitted for the page.

      See [method@NavigationView.push] and [property@NavigationPage:tag].
      Parameter:
      tag - the page tag
    • remove

      public void remove(@Nonnull NavigationPage page)
      Removes @page from @self.

      If @page is currently in the navigation stack, it will be removed once it's
      popped. Otherwise, it's removed immediately.

      See [method@NavigationView.add].
      Parameter:
      page - the page to remove
    • replaceWithTags

      public void replaceWithTags(@Nonnull Strs tags, int n_tags)
      Replaces the current navigation stack with pages with the tags @tags.

      The last page becomes the visible page.

      Replacing the navigation stack has no animation.

      If [method@NavigationView.add] hasn't been called for any pages that are no
      longer in the navigation stack, they are automatically removed.

      @n_tags can be 0, in that case no page will be visible after calling this
      method. This can be useful for removing all pages from @self.

      The [signal@NavigationView::replaced] signal will be emitted.

      See [method@NavigationView.replace] and [property@NavigationPage:tag].
      Parameter:
      tags - tags of the pages in the navigation stack
      n_tags - the number of tags
    • setAnimateTransitions

      public void setAnimateTransitions(boolean animate_transitions)
      Sets whether @self should animate page transitions.

      Gesture-based transitions are always animated.
      Parameter:
      animate_transitions - whether to animate page transitions
    • setHhomogeneous

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

      If the view is horizontally homogeneous, it allocates the same width for
      all pages.

      If it's not, the view may change width when a different page becomes visible.
      Parameter:
      hhomogeneous - whether to make @self horizontally homogeneous
    • setPopOnEscape

      public void setPopOnEscape(boolean pop_on_escape)
      Sets whether pressing Escape pops the current page on @self.

      Applications using `AdwNavigationView` to implement a browser may want to
      disable it.
      Parameter:
      pop_on_escape - whether to pop the current page when pressing Escape
    • setVhomogeneous

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

      If the view is vertically homogeneous, it allocates the same height for
      all pages.

      If it's not, the view may change height when a different page becomes
      visible.
      Parameter:
      vhomogeneous - whether to make @self vertically homogeneous
    • onGetNextPage

      public SignalHandler onGetNextPage(NavigationView.OnGetNextPage signal)
      Connect to signal "get-next-page".
      See NavigationView.OnGetNextPage.onGetNextPage() for signal description.
      Field SIGNAL_ON_GET_NEXT_PAGE contains original signal name and can be used as resource reference.
      Parameter:
      signal - callback function (lambda).
      Gibt zurück:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onPopped

      public SignalHandler onPopped(NavigationView.OnPopped signal)
      Connect to signal "popped".
      See NavigationView.OnPopped.onPopped(ch.bailu.gtk.adw.NavigationPage) for signal description.
      Field SIGNAL_ON_POPPED contains original signal name and can be used as resource reference.
      Parameter:
      signal - callback function (lambda).
      Gibt zurück:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onPushed

      public SignalHandler onPushed(NavigationView.OnPushed signal)
      Connect to signal "pushed".
      See NavigationView.OnPushed.onPushed() for signal description.
      Field SIGNAL_ON_PUSHED contains original signal name and can be used as resource reference.
      Parameter:
      signal - callback function (lambda).
      Gibt zurück:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onReplaced

      public SignalHandler onReplaced(NavigationView.OnReplaced signal)
      Connect to signal "replaced".
      See NavigationView.OnReplaced.onReplaced() for signal description.
      Field SIGNAL_ON_REPLACED contains original signal name and can be used as resource reference.
      Parameter:
      signal - callback function (lambda).
      Gibt zurück:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asSwipeable

      public Swipeable asSwipeable()
      Implements interface Swipeable. Call this to get access to interface functions.
      Gibt zurück:
      Swipeable
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Setzt außer Kraft:
      asAccessible in Klasse Widget
      Gibt zurück:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Setzt außer Kraft:
      asBuildable in Klasse Widget
      Gibt zurück:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Setzt außer Kraft:
      asConstraintTarget in Klasse Widget
      Gibt zurück:
      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()