portico/Sources/Portico/Generated/NavigationView.swift

520 lines
25 KiB
Swift

// Generated by PorticoGen. DO NOT EDIT. See Sources/PorticoGen to make changes.
import Adw
import Gtk
import Gio
import Gdk
// PorticoGen: generateStruct | source: Adw.NavigationView
/// 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 [enum`Gtk`.AccessibleRole.group] role.
///
/// A Portico view that mounts a `Adw.NavigationView`.
@MainActor public struct NavigationView: View {
private let make: (MountContext) -> Adw.NavigationView
private var configure: [(Adw.NavigationView, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.NavigationView.init()
/// Creates a new `AdwNavigationView`.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// Optional value parameters are applied only when non-`nil`; a `nil` argument leaves the widget's own default in place and cannot clear a nullable property - use the matching modifier for that.
///
/// - Parameter animateTransitions: Whether to animate page transitions.
/// - Parameter hhomogeneous: Whether the view is horizontally homogeneous.
/// - Parameter popOnEscape: Whether pressing Escape pops the current page.
/// - Parameter vhomogeneous: Whether the view is vertically homogeneous.
/// - Parameter onGetNextPage: Invoked when the widget emits the `get-next-page` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onPopped: Invoked when the widget emits the `popped` signal. The closure receives the signal's arguments in order.
/// - Parameter onPushed: Invoked when the widget emits the `pushed` signal.
/// - Parameter onReplaced: Invoked when the widget emits the `replaced` signal.
public init(animateTransitions: Bool? = nil, hhomogeneous: Bool? = nil, popOnEscape: Bool? = nil, vhomogeneous: Bool? = nil, onGetNextPage: (() -> Adw.NavigationPage?)? = nil, onPopped: ((Adw.NavigationPage) -> Void)? = nil, onPushed: (() -> Void)? = nil, onReplaced: (() -> Void)? = nil) {
make = { _ in Adw.NavigationView() }
configure.append { w, ctx in
if let animateTransitions { w.setAnimateTransitions(animateTransitions: animateTransitions) }
if let hhomogeneous { w.setHhomogeneous(hhomogeneous: hhomogeneous) }
if let popOnEscape { w.setPopOnEscape(popOnEscape: popOnEscape) }
if let vhomogeneous { w.setVhomogeneous(vhomogeneous: vhomogeneous) }
if let onGetNextPage { ctx.registry.add(w.connectGetNextPage { _ in onGetNextPage() }) }
if let onPopped { ctx.registry.add(w.connectPopped { _, a0 in onPopped(a0) }) }
if let onPushed { ctx.registry.add(w.connectPushed { _ in onPushed() }) }
if let onReplaced { ctx.registry.add(w.connectReplaced { _ in onReplaced() }) }
}
}
}
extension NavigationView: WidgetView {
public typealias Target = Adw.NavigationView
@_spi(Portico) public func appending(
_ step: @escaping (Adw.NavigationView, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension NavigationView: Mountable {
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
let w = make(ctx)
for step in configure { step(w, ctx) }
return w
}
}
// PorticoGen: generateModifierExtension | source: Adw.NavigationView
/// Modifiers for `Adw.NavigationView`, available on every Portico view whose
/// backing widget is `Adw.NavigationView` or one of its subclasses.
extension WidgetView where Target: Adw.NavigationView {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.NavigationView.setAnimateTransitions(animateTransitions:)
/// Sets whether `self` should animate page transitions.
///
/// Gesture-based transitions are always animated.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter animateTransitions: Whether to animate page transitions.
/// - Returns: A copy of this view with the modifier applied.
public func animateTransitions(_ animateTransitions: Bool) -> Self {
appending { w, _ in
w.setAnimateTransitions(animateTransitions: animateTransitions)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.NavigationView.setAnimateTransitions(animateTransitions:), GObject.Object.connectNotify(detail:_:), Adw.NavigationView.getAnimateTransitions()
/// Sets whether `self` should animate page transitions.
///
/// Gesture-based transitions are always animated.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func animateTransitions(_ animateTransitions: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, animateTransitions, registry: ctx.registry, notifyDetail: "animate-transitions",
read: { [w] in w.getAnimateTransitions() },
write: { [w] v in w.setAnimateTransitions(animateTransitions: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.NavigationView.setAnimateTransitions(animateTransitions:)
/// Sets whether `self` should animate page transitions.
///
/// Gesture-based transitions are always animated.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationView.setAnimateTransitions(animateTransitions:)`.
///
/// - Parameter animateTransitions: Whether to animate page transitions.
/// - Returns: A copy of this view with the modifier applied.
public func animateTransitions(_ animateTransitions: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setAnimateTransitions(animateTransitions: animateTransitions()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.NavigationView.setHhomogeneous(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.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter hhomogeneous: Whether the view is horizontally homogeneous.
/// - Returns: A copy of this view with the modifier applied.
public func hhomogeneous(_ hhomogeneous: Bool) -> Self {
appending { w, _ in
w.setHhomogeneous(hhomogeneous: hhomogeneous)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.NavigationView.setHhomogeneous(hhomogeneous:), GObject.Object.connectNotify(detail:_:), Adw.NavigationView.getHhomogeneous()
/// 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.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func hhomogeneous(_ hhomogeneous: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, hhomogeneous, registry: ctx.registry, notifyDetail: "hhomogeneous",
read: { [w] in w.getHhomogeneous() },
write: { [w] v in w.setHhomogeneous(hhomogeneous: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.NavigationView.setHhomogeneous(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.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationView.setHhomogeneous(hhomogeneous:)`.
///
/// - Parameter hhomogeneous: Whether the view is horizontally homogeneous.
/// - Returns: A copy of this view with the modifier applied.
public func hhomogeneous(_ hhomogeneous: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setHhomogeneous(hhomogeneous: hhomogeneous()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.NavigationView.setPopOnEscape(popOnEscape:)
/// Sets whether pressing Escape pops the current page on `self`.
///
/// Applications using `AdwNavigationView` to implement a browser may want to
/// disable it.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter popOnEscape: Whether pressing Escape pops the current page.
/// - Returns: A copy of this view with the modifier applied.
public func popOnEscape(_ popOnEscape: Bool) -> Self {
appending { w, _ in
w.setPopOnEscape(popOnEscape: popOnEscape)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.NavigationView.setPopOnEscape(popOnEscape:), GObject.Object.connectNotify(detail:_:), Adw.NavigationView.getPopOnEscape()
/// Sets whether pressing Escape pops the current page on `self`.
///
/// Applications using `AdwNavigationView` to implement a browser may want to
/// disable it.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func popOnEscape(_ popOnEscape: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, popOnEscape, registry: ctx.registry, notifyDetail: "pop-on-escape",
read: { [w] in w.getPopOnEscape() },
write: { [w] v in w.setPopOnEscape(popOnEscape: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.NavigationView.setPopOnEscape(popOnEscape:)
/// Sets whether pressing Escape pops the current page on `self`.
///
/// Applications using `AdwNavigationView` to implement a browser may want to
/// disable it.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationView.setPopOnEscape(popOnEscape:)`.
///
/// - Parameter popOnEscape: Whether pressing Escape pops the current page.
/// - Returns: A copy of this view with the modifier applied.
public func popOnEscape(_ popOnEscape: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setPopOnEscape(popOnEscape: popOnEscape()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.NavigationView.setVhomogeneous(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.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter vhomogeneous: Whether the view is vertically homogeneous.
/// - Returns: A copy of this view with the modifier applied.
public func vhomogeneous(_ vhomogeneous: Bool) -> Self {
appending { w, _ in
w.setVhomogeneous(vhomogeneous: vhomogeneous)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.NavigationView.setVhomogeneous(vhomogeneous:), GObject.Object.connectNotify(detail:_:), Adw.NavigationView.getVhomogeneous()
/// 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.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func vhomogeneous(_ vhomogeneous: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, vhomogeneous, registry: ctx.registry, notifyDetail: "vhomogeneous",
read: { [w] in w.getVhomogeneous() },
write: { [w] v in w.setVhomogeneous(vhomogeneous: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.NavigationView.setVhomogeneous(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.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationView.setVhomogeneous(vhomogeneous:)`.
///
/// - Parameter vhomogeneous: Whether the view is vertically homogeneous.
/// - Returns: A copy of this view with the modifier applied.
public func vhomogeneous(_ vhomogeneous: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setVhomogeneous(vhomogeneous: vhomogeneous()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.NavigationView.connectGetNextPage(_:)
/// Emitted when a push shortcut or a gesture is triggered.
///
/// To support the push shortcuts and gestures, the application is expected to
/// return the page to push in the handler.
///
/// This signal can be emitted multiple times for the gestures, for example
/// when the gesture is cancelled by the user. As such, the application must
/// not make any irreversible changes in the handler, such as removing the page
/// from a forward stack.
///
/// Instead, it should be done in the [signal`NavigationView`::pushed] handler.
///
/// - Parameter handler: Invoked when the widget emits the `get-next-page` signal. Its return value is forwarded to GTK as the signal's result.
/// - Returns: A copy of this view with the modifier applied.
public func onGetNextPage(_ handler: @escaping () -> Adw.NavigationPage?) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectGetNextPage { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.NavigationView.connectPopped(_:)
/// Emitted after `page` has been popped from the navigation stack.
///
/// See [method`NavigationView`.pop].
///
/// When using [method`NavigationView`.pop_to_page] or
/// [method`NavigationView`.pop_to_tag], this signal is emitted for each of the
/// popped pages.
///
/// - Parameter handler: Invoked when the widget emits the `popped` signal. The closure receives the signal's arguments in order.
/// - Returns: A copy of this view with the modifier applied.
public func onPopped(_ handler: @escaping (Adw.NavigationPage) -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectPopped { _, a0 in handler(a0) })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.NavigationView.connectPushed(_:)
/// Emitted after a page has been pushed to the navigation stack.
///
/// See [method`NavigationView`.push].
///
/// - Parameter handler: Invoked when the widget emits the `pushed` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onPushed(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectPushed { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.NavigationView.connectReplaced(_:)
/// Emitted after the navigation stack has been replaced.
///
/// See [method`NavigationView`.replace].
///
/// - Parameter handler: Invoked when the widget emits the `replaced` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onReplaced(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectReplaced { _ in handler() })
}
}
}