portico/Sources/Portico/Generated/NavigationPage.swift

645 lines
36 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.NavigationPage
/// A page within [class`NavigationView`] or [class`NavigationSplitView`].
///
/// Each page has a child widget, a title and optionally a tag.
///
/// The [signal`NavigationPage`::showing], [signal`NavigationPage`::shown],
/// [signal`NavigationPage`::hiding] and [signal`NavigationPage`::hidden] signals
/// can be used to track the page's visibility within its `AdwNavigationView`.
///
/// ## Header Bar Integration
///
/// When placed inside `AdwNavigationPage`, [class`HeaderBar`] will display the
/// page title instead of window title.
///
/// When used together with [class`NavigationView`], it will also display a back
/// button that can be used to go back to the previous page. Set
/// [property`HeaderBar`:show-back-button] to `FALSE` to disable that behavior if
/// it's unwanted.
///
/// ## CSS Nodes
///
/// `AdwNavigationPage` has a single CSS node with name
/// `navigation-view-page`.
///
/// ## Accessibility
///
/// `AdwNavigationPage` uses the [enum`Gtk`.AccessibleRole.group] role.
///
/// A Portico view that mounts a `Adw.NavigationPage`.
@MainActor public struct NavigationPage: View {
private let make: (MountContext) -> Adw.NavigationPage
private var configure: [(Adw.NavigationPage, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.NavigationPage.init(child:title:)
/// Creates a new `AdwNavigationPage`.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for values that change.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 title: The page title.
/// - Parameter canPop: Whether the page can be popped from navigation stack.
/// - Parameter child: A closure supplying the single view passed to `Adw.NavigationPage.init` as `child`. Exactly one view is required; an empty closure is a compile-time error.
/// - Parameter onHidden: Invoked when the widget emits the `hidden` signal.
/// - Parameter onHiding: Invoked when the widget emits the `hiding` signal.
/// - Parameter onShowing: Invoked when the widget emits the `showing` signal.
/// - Parameter onShown: Invoked when the widget emits the `shown` signal.
@_disfavoredOverload
public init<S: StringProtocol>(title: S, canPop: Bool? = nil, @SingleViewBuilder child: @escaping () -> AnyView, onHidden: (() -> Void)? = nil, onHiding: (() -> Void)? = nil, onShowing: (() -> Void)? = nil, onShown: (() -> Void)? = nil) {
var __slot_child: Portico.SingleChildSlot?
make = { ctx in
let __newSlot_child = Portico.SingleChildSlot(child, ctx)
__slot_child = __newSlot_child
return Adw.NavigationPage(child: __slot_child!.widget!, title: String(title))
}
configure.append { w, ctx in
__slot_child?.attach { v in w.setChild(child: v) }
if let canPop { w.setCanPop(canPop: canPop) }
if let onHidden { ctx.registry.add(w.connectHidden { _ in onHidden() }) }
if let onHiding { ctx.registry.add(w.connectHiding { _ in onHiding() }) }
if let onShowing { ctx.registry.add(w.connectShowing { _ in onShowing() }) }
if let onShown { ctx.registry.add(w.connectShown { _ in onShown() }) }
}
}
// PorticoGen: generateInits(binding) | source: Adw.NavigationPage.init(child:title:), Adw.NavigationPage.setTitle(title:)
/// Creates a new `AdwNavigationPage`.
///
/// The initial value is the binding's current value; every later change is pushed into the widget through `Adw.NavigationPage.setTitle(title:)` without rebuilding the view.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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.
/// Optional `Binding` parameters bind through `Portico.bindProperty`, so they are two-way wherever the wrapper exposes a safe getter.
///
/// - Parameter title: The page title.
/// - Parameter canPop: Whether the page can be popped from navigation stack.
/// - Parameter child: A closure supplying the single view passed to `Adw.NavigationPage.init` as `child`. Exactly one view is required; an empty closure is a compile-time error.
/// - Parameter onHidden: Invoked when the widget emits the `hidden` signal.
/// - Parameter onHiding: Invoked when the widget emits the `hiding` signal.
/// - Parameter onShowing: Invoked when the widget emits the `showing` signal.
/// - Parameter onShown: Invoked when the widget emits the `shown` signal.
public init(title: Portico.Binding<String>, canPop: Portico.Binding<Bool>? = nil, @SingleViewBuilder child: @escaping () -> AnyView, onHidden: (() -> Void)? = nil, onHiding: (() -> Void)? = nil, onShowing: (() -> Void)? = nil, onShown: (() -> Void)? = nil) {
var __slot_child: Portico.SingleChildSlot?
make = { ctx in
let __newSlot_child = Portico.SingleChildSlot(child, ctx)
__slot_child = __newSlot_child
return Adw.NavigationPage(child: __slot_child!.widget!, title: title.wrappedValue)
}
configure.append { w, ctx in
ctx.registry.add(title.subscribe { [w] v in w.setTitle(title: v) })
__slot_child?.attach { v in w.setChild(child: v) }
if let canPop {
Portico.bindProperty(w, canPop, registry: ctx.registry, notifyDetail: "can-pop", read: { [w] in w.getCanPop() }, write: { [w] v in w.setCanPop(canPop: v) })
}
if let onHidden { ctx.registry.add(w.connectHidden { _ in onHidden() }) }
if let onHiding { ctx.registry.add(w.connectHiding { _ in onHiding() }) }
if let onShowing { ctx.registry.add(w.connectShowing { _ in onShowing() }) }
if let onShown { ctx.registry.add(w.connectShown { _ in onShown() }) }
}
}
// PorticoGen: generateInits(closure) | source: Adw.NavigationPage.init(child:title:), Adw.NavigationPage.setTitle(title:)
/// Creates a new `AdwNavigationPage`.
///
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationPage.setTitle(title:)`.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 title: The page title.
/// - Parameter canPop: Whether the page can be popped from navigation stack.
/// - Parameter child: A closure supplying the single view passed to `Adw.NavigationPage.init` as `child`. Exactly one view is required; an empty closure is a compile-time error.
/// - Parameter onHidden: Invoked when the widget emits the `hidden` signal.
/// - Parameter onHiding: Invoked when the widget emits the `hiding` signal.
/// - Parameter onShowing: Invoked when the widget emits the `showing` signal.
/// - Parameter onShown: Invoked when the widget emits the `shown` signal.
public init(title: @escaping () -> String, canPop: Bool? = nil, @SingleViewBuilder child: @escaping () -> AnyView, onHidden: (() -> Void)? = nil, onHiding: (() -> Void)? = nil, onShowing: (() -> Void)? = nil, onShown: (() -> Void)? = nil) {
var __slot_child: Portico.SingleChildSlot?
make = { ctx in
let __newSlot_child = Portico.SingleChildSlot(child, ctx)
__slot_child = __newSlot_child
return Adw.NavigationPage(child: __slot_child!.widget!, title: title())
}
configure.append { w, ctx in
let t0 = DependencyTracker { [w] in w.setTitle(title: title()) }
t0.run()
ctx.registry.add(t0)
__slot_child?.attach { v in w.setChild(child: v) }
if let canPop { w.setCanPop(canPop: canPop) }
if let onHidden { ctx.registry.add(w.connectHidden { _ in onHidden() }) }
if let onHiding { ctx.registry.add(w.connectHiding { _ in onHiding() }) }
if let onShowing { ctx.registry.add(w.connectShowing { _ in onShowing() }) }
if let onShown { ctx.registry.add(w.connectShown { _ in onShown() }) }
}
}
// PorticoGen: generateInits(interpolation) | source: Adw.NavigationPage.init(child:title:), Adw.NavigationPage.setTitle(title:)
/// Creates a new `AdwNavigationPage`.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.NavigationPage.setTitle(title:)`. A literal with no interpolation is applied once, with no subscription.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 title: The page title.
/// - Parameter canPop: Whether the page can be popped from navigation stack.
/// - Parameter child: A closure supplying the single view passed to `Adw.NavigationPage.init` as `child`. Exactly one view is required; an empty closure is a compile-time error.
/// - Parameter onHidden: Invoked when the widget emits the `hidden` signal.
/// - Parameter onHiding: Invoked when the widget emits the `hiding` signal.
/// - Parameter onShowing: Invoked when the widget emits the `showing` signal.
/// - Parameter onShown: Invoked when the widget emits the `shown` signal.
public init(title: Portico.InterpolatedText, canPop: Bool? = nil, @SingleViewBuilder child: @escaping () -> AnyView, onHidden: (() -> Void)? = nil, onHiding: (() -> Void)? = nil, onShowing: (() -> Void)? = nil, onShown: (() -> Void)? = nil) {
var __slot_child: Portico.SingleChildSlot?
make = { ctx in
let __newSlot_child = Portico.SingleChildSlot(child, ctx)
__slot_child = __newSlot_child
return Adw.NavigationPage(child: __slot_child!.widget!, title: title.untrackedText)
}
configure.append { w, ctx in
Portico.bindInterpolation(title, registry: ctx.registry) { [w] v in w.setTitle(title: v) }
__slot_child?.attach { v in w.setChild(child: v) }
if let canPop { w.setCanPop(canPop: canPop) }
if let onHidden { ctx.registry.add(w.connectHidden { _ in onHidden() }) }
if let onHiding { ctx.registry.add(w.connectHiding { _ in onHiding() }) }
if let onShowing { ctx.registry.add(w.connectShowing { _ in onShowing() }) }
if let onShown { ctx.registry.add(w.connectShown { _ in onShown() }) }
}
}
// PorticoGen: generateInits(static) | source: Adw.NavigationPage.init(child:title:tag:)
/// Creates a new `AdwNavigationPage` with provided tag.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 title: The page title.
/// - Parameter tag: The page tag.
/// - Parameter canPop: Whether the page can be popped from navigation stack.
/// - Parameter child: A closure supplying the single view passed to `Adw.NavigationPage.init` as `child`. Exactly one view is required; an empty closure is a compile-time error.
/// - Parameter onHidden: Invoked when the widget emits the `hidden` signal.
/// - Parameter onHiding: Invoked when the widget emits the `hiding` signal.
/// - Parameter onShowing: Invoked when the widget emits the `showing` signal.
/// - Parameter onShown: Invoked when the widget emits the `shown` signal.
public init(title: String, tag: String, canPop: Bool? = nil, @SingleViewBuilder child: @escaping () -> AnyView, onHidden: (() -> Void)? = nil, onHiding: (() -> Void)? = nil, onShowing: (() -> Void)? = nil, onShown: (() -> Void)? = nil) {
var __slot_child: Portico.SingleChildSlot?
make = { ctx in
let __newSlot_child = Portico.SingleChildSlot(child, ctx)
__slot_child = __newSlot_child
return Adw.NavigationPage(child: __slot_child!.widget!, title: title, tag: tag)
}
configure.append { w, ctx in
__slot_child?.attach { v in w.setChild(child: v) }
if let canPop { w.setCanPop(canPop: canPop) }
if let onHidden { ctx.registry.add(w.connectHidden { _ in onHidden() }) }
if let onHiding { ctx.registry.add(w.connectHiding { _ in onHiding() }) }
if let onShowing { ctx.registry.add(w.connectShowing { _ in onShowing() }) }
if let onShown { ctx.registry.add(w.connectShown { _ in onShown() }) }
}
}
}
extension NavigationPage: WidgetView {
public typealias Target = Adw.NavigationPage
@_spi(Portico) public func appending(
_ step: @escaping (Adw.NavigationPage, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension NavigationPage: 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.NavigationPage
/// Modifiers for `Adw.NavigationPage`, available on every Portico view whose
/// backing widget is `Adw.NavigationPage` or one of its subclasses.
extension WidgetView where Target: Adw.NavigationPage {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.NavigationPage.setCanPop(canPop:)
/// Sets whether `self` can be popped from navigation stack.
///
/// Set it to `FALSE` to disable shortcuts and gestures, as well as remove the
/// back button from [class`HeaderBar`].
///
/// Manually calling [method`NavigationView`.pop] or using the `navigation.pop`
/// action will still work.
///
/// See [property`HeaderBar`:show-back-button] for removing only the back button,
/// but not shortcuts.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter canPop: Whether the page can be popped from navigation stack.
/// - Returns: A copy of this view with the modifier applied.
public func canPop(_ canPop: Bool) -> Self {
appending { w, _ in
w.setCanPop(canPop: canPop)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.NavigationPage.setCanPop(canPop:), GObject.Object.connectNotify(detail:_:), Adw.NavigationPage.getCanPop()
/// Sets whether `self` can be popped from navigation stack.
///
/// Set it to `FALSE` to disable shortcuts and gestures, as well as remove the
/// back button from [class`HeaderBar`].
///
/// Manually calling [method`NavigationView`.pop] or using the `navigation.pop`
/// action will still work.
///
/// See [property`HeaderBar`:show-back-button] for removing only the back button,
/// but not shortcuts.
///
/// 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 canPop(_ canPop: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, canPop, registry: ctx.registry, notifyDetail: "can-pop",
read: { [w] in w.getCanPop() },
write: { [w] v in w.setCanPop(canPop: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.NavigationPage.setCanPop(canPop:)
/// Sets whether `self` can be popped from navigation stack.
///
/// Set it to `FALSE` to disable shortcuts and gestures, as well as remove the
/// back button from [class`HeaderBar`].
///
/// Manually calling [method`NavigationView`.pop] or using the `navigation.pop`
/// action will still work.
///
/// See [property`HeaderBar`:show-back-button] for removing only the back button,
/// but not shortcuts.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationPage.setCanPop(canPop:)`.
///
/// - Parameter canPop: Whether the page can be popped from navigation stack.
/// - Returns: A copy of this view with the modifier applied.
public func canPop(_ canPop: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setCanPop(canPop: canPop()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.NavigationPage.setChild(child:)
/// Sets the child widget of `self`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: Adw.Widget?) -> Self {
appending { w, _ in
w.setChild(child: child)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Adw.NavigationPage.setChild(child:)
/// Sets the child widget of `self`.
///
/// The closure is evaluated once when the modifier is applied. Its first view is mounted into the slot.
/// Additional views are ignored; an empty closure leaves the slot unset.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
guard let v = childViews.first else { return }
w.setChild(child: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.NavigationPage.setChild(child:), GObject.Object.connectNotify(detail:_:), Adw.NavigationPage.getChild()
/// Sets the child widget of `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.Widget?` 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 child<W: Gtk.Widget>(_ child: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.NavigationPage.setChild(child:), GObject.Object.connectNotify(detail:_:), Adw.NavigationPage.getChild()
/// Sets the child widget of `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Adw.Widget>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.Widget?>` to be able to clear the property.
/// When `Adw.Widget` 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.
/// A `nil` widget value is never written back into the binding.
///
/// - Returns: A copy of this view with the modifier applied.
public func child<W: Gtk.Widget>(_ child: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.NavigationPage.setChild(child:)
/// Sets the child widget of `self`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationPage.setChild(child:)`.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: @escaping () -> Adw.Widget?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setChild(child: child()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.NavigationPage.setTag(tag:)
/// Sets the tag for `self`.
///
/// The tag can be used to retrieve the page with
/// [method`NavigationView`.find_page], as well as with
/// [method`NavigationView`.push_by_tag], [method`NavigationView`.pop_to_tag] or
/// [method`NavigationView`.replace_with_tags].
///
/// Tags must be unique within each [class`NavigationView`].
///
/// The tag also must be set to use the `navigation.push` action.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter tag: The page tag.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func tag<S: StringProtocol>(_ tag: S?) -> Self {
appending { w, _ in
w.setTag(tag: tag.map { String($0) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.NavigationPage.setTag(tag:), GObject.Object.connectNotify(detail:_:), Adw.NavigationPage.getTag()
/// Sets the tag for `self`.
///
/// The tag can be used to retrieve the page with
/// [method`NavigationView`.find_page], as well as with
/// [method`NavigationView`.push_by_tag], [method`NavigationView`.pop_to_tag] or
/// [method`NavigationView`.replace_with_tags].
///
/// Tags must be unique within each [class`NavigationView`].
///
/// The tag also must be set to use the `navigation.push` action.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String?` 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 tag(_ tag: Portico.Binding<String?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, tag, registry: ctx.registry, notifyDetail: "tag",
read: { [w] in w.getTag() },
write: { [w] v in w.setTag(tag: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.NavigationPage.setTag(tag:), GObject.Object.connectNotify(detail:_:), Adw.NavigationPage.getTag()
/// Sets the tag for `self`.
///
/// The tag can be used to retrieve the page with
/// [method`NavigationView`.find_page], as well as with
/// [method`NavigationView`.push_by_tag], [method`NavigationView`.pop_to_tag] or
/// [method`NavigationView`.replace_with_tags].
///
/// Tags must be unique within each [class`NavigationView`].
///
/// The tag also must be set to use the `navigation.push` action.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<String>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<String?>` to be able to clear the property.
/// When `String` 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.
/// A `nil` widget value is never written back into the binding.
///
/// - Returns: A copy of this view with the modifier applied.
public func tag(_ tag: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, tag, registry: ctx.registry, notifyDetail: "tag",
read: { [w] in w.getTag() },
write: { [w] v in w.setTag(tag: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.NavigationPage.setTag(tag:)
/// Sets the tag for `self`.
///
/// The tag can be used to retrieve the page with
/// [method`NavigationView`.find_page], as well as with
/// [method`NavigationView`.push_by_tag], [method`NavigationView`.pop_to_tag] or
/// [method`NavigationView`.replace_with_tags].
///
/// Tags must be unique within each [class`NavigationView`].
///
/// The tag also must be set to use the `navigation.push` action.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationPage.setTag(tag:)`.
///
/// - Parameter tag: The page tag.
/// - Returns: A copy of this view with the modifier applied.
public func tag(_ tag: @escaping () -> String?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setTag(tag: tag()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.NavigationPage.setTag(tag:)
/// Sets the tag for `self`.
///
/// The tag can be used to retrieve the page with
/// [method`NavigationView`.find_page], as well as with
/// [method`NavigationView`.push_by_tag], [method`NavigationView`.pop_to_tag] or
/// [method`NavigationView`.replace_with_tags].
///
/// Tags must be unique within each [class`NavigationView`].
///
/// The tag also must be set to use the `navigation.push` action.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.NavigationPage.setTag(tag:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter tag: The page tag.
/// - Returns: A copy of this view with the modifier applied.
public func tag(_ tag: Portico.InterpolatedText?) -> Self {
appending { w, ctx in
Portico.bindOptionalInterpolation(tag, registry: ctx.registry) { [w] v in w.setTag(tag: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.NavigationPage.setTitle(title:)
/// Sets the title of `self`.
///
/// It's displayed in [class`HeaderBar`] instead of the window title, and used as
/// the tooltip on the next page's back button, as well as by screen reader.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter title: The page title.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func title<S: StringProtocol>(_ title: S) -> Self {
appending { w, _ in
w.setTitle(title: String(title))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.NavigationPage.setTitle(title:), GObject.Object.connectNotify(detail:_:), Adw.NavigationPage.getTitle()
/// Sets the title of `self`.
///
/// It's displayed in [class`HeaderBar`] instead of the window title, and used as
/// the tooltip on the next page's back button, as well as by screen reader.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String` 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 title(_ title: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, title, registry: ctx.registry, notifyDetail: "title",
read: { [w] in w.getTitle() },
write: { [w] v in w.setTitle(title: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.NavigationPage.setTitle(title:)
/// Sets the title of `self`.
///
/// It's displayed in [class`HeaderBar`] instead of the window title, and used as
/// the tooltip on the next page's back button, as well as by screen reader.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.NavigationPage.setTitle(title:)`.
///
/// - Parameter title: The page title.
/// - Returns: A copy of this view with the modifier applied.
public func title(_ title: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setTitle(title: title()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.NavigationPage.setTitle(title:)
/// Sets the title of `self`.
///
/// It's displayed in [class`HeaderBar`] instead of the window title, and used as
/// the tooltip on the next page's back button, as well as by screen reader.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.NavigationPage.setTitle(title:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter title: The page title.
/// - Returns: A copy of this view with the modifier applied.
public func title(_ title: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(title, registry: ctx.registry) { [w] v in w.setTitle(title: v) }
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.NavigationPage.connectHidden(_:)
/// Emitted when the navigation view transition has been completed and the page
/// is fully hidden.
///
/// It will always be preceded by [signal`NavigationPage`::hiding] or
/// [signal`NavigationPage`::showing].
///
/// - Parameter handler: Invoked when the widget emits the `hidden` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onHidden(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectHidden { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.NavigationPage.connectHiding(_:)
/// Emitted when the page starts hiding at the beginning of the navigation view
/// transition.
///
/// It will always be followed by [signal`NavigationPage`::hidden] or
/// [signal`NavigationPage`::shown].
///
/// - Parameter handler: Invoked when the widget emits the `hiding` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onHiding(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectHiding { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.NavigationPage.connectShowing(_:)
/// Emitted when the page shows at the beginning of the navigation view
/// transition.
///
/// It will always be followed by [signal`NavigationPage`::shown] or
/// [signal`NavigationPage`::hidden].
///
/// - Parameter handler: Invoked when the widget emits the `showing` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onShowing(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectShowing { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.NavigationPage.connectShown(_:)
/// Emitted when the navigation view transition has been completed and the page
/// is fully shown.
///
/// It will always be preceded by [signal`NavigationPage`::showing] or
/// [signal`NavigationPage`::hiding].
///
/// - Parameter handler: Invoked when the widget emits the `shown` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onShown(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectShown { _ in handler() })
}
}
}