portico/Sources/Portico/Generated/ViewSwitcherSidebar.swift

482 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.ViewSwitcherSidebar
/// An adaptive sidebar that controls an [class`ViewStack`].
///
/// <picture>
/// <source srcset="view-switcher-sidebar-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="view-switcher-sidebar.png" alt="view-switcher-sidebar">
/// </picture>
///
/// `AdwViewSwitcherSidebar` is a view switcher implemented using a
/// [class`Sidebar`], in a similar fashion to [class`Gtk`.StackSidebar].
///
/// `AdwViewSwitcherSidebar` items have an icon, a label, as well as an unread
/// dot or a badge.
///
/// Unlike other switchers, `AdwViewSwitcherSidebar` supports grouping pages into
/// sections, using the [property`ViewStackPage`:starts-section] and
/// [property`ViewStackPage`:section-title] properties.
///
/// Like [class`Sidebar`], `AdwViewSwitcherSidebar` is adaptive and can behave as
/// a sidebar or a page, via the [property`ViewSwitcherSidebar`:mode] property.
///
/// <picture>
/// <source srcset="view-switcher-sidebar-modes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="view-switcher-sidebar-modes.png" alt="view-switcher-sidebar-modes">
/// </picture>
///
/// Connect to the [signal`ViewSwitcherSidebar`::activated] signal to run code when
/// an item has been activated. This can be used to toggle the visible pane when
/// used in a split view.
///
/// Like `AdwSidebar`, `AdwViewSwitcherSidebar` supports filtering items via the
/// [property`ViewSwitcherSidebar`:filter] property.
///
/// Use [property`ViewSwitcherSidebar`:placeholder] to provide an empty state
/// widget. It will be shown when all items have been filtered out, or the
/// sidebar has no items otherwise.
///
/// ## CSS nodes
///
/// `AdwViewSwitcherSidebar` has a single CSS node with name
/// `view-switcher-sidebar`.
///
/// See also: [class`ViewSwitcher`], [class`ViewSwitcherBar`],
/// [class`InlineViewSwitcher`].
///
/// A Portico view that mounts a `Adw.ViewSwitcherSidebar`.
@MainActor public struct ViewSwitcherSidebar: View {
private let make: (MountContext) -> Adw.ViewSwitcherSidebar
private var configure: [(Adw.ViewSwitcherSidebar, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.ViewSwitcherSidebar.init()
/// Creates a new `AdwViewSwitcherSidebar`.
///
/// 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 filter: The item filter.
/// - Parameter mode: Determines the sidebar's look and behavior.
/// - Parameter stack: The stack the sidebar controls.
/// - Parameter placeholder: A `ViewBuilder` closure whose first view is mounted into the `placeholder` slot.
/// - Parameter onActivated: Invoked when the widget emits the `activated` signal.
public init(filter: Adw.Filter? = nil, mode: Adw.SidebarMode? = nil, stack: Adw.ViewStack? = nil, @ViewBuilder placeholder: @escaping () -> [AnyView] = { [] }, onActivated: (() -> Void)? = nil) {
make = { _ in Adw.ViewSwitcherSidebar() }
configure.append { w, ctx in
if let filter { w.setFilter(filter: filter) }
if let mode { w.setMode(mode: mode) }
if let stack { w.setStack(stack: stack) }
if let v = Portico.mountSlotChild(placeholder, ctx, onUpdate: { v in w.setPlaceholder(placeholder: v) }) { w.setPlaceholder(placeholder: v) }
if let onActivated { ctx.registry.add(w.connectActivated { _ in onActivated() }) }
}
}
}
extension ViewSwitcherSidebar: WidgetView {
public typealias Target = Adw.ViewSwitcherSidebar
@_spi(Portico) public func appending(
_ step: @escaping (Adw.ViewSwitcherSidebar, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension ViewSwitcherSidebar: 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.ViewSwitcherSidebar
/// Modifiers for `Adw.ViewSwitcherSidebar`, available on every Portico view whose
/// backing widget is `Adw.ViewSwitcherSidebar` or one of its subclasses.
extension WidgetView where Target: Adw.ViewSwitcherSidebar {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherSidebar.setFilter(filter:)
/// Sets the item filter for `self`.
///
/// Can be used to implement search within the sidebar.
///
/// Use [property`ViewSwitcherSidebar`:placeholder] to provide an empty state.
///
/// See [method`Sidebar`.set_filter].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter filter: The item filter.
/// - Returns: A copy of this view with the modifier applied.
public func filter(_ filter: Adw.Filter?) -> Self {
appending { w, _ in
w.setFilter(filter: filter)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherSidebar.setFilter(filter:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherSidebar.getFilter()
/// Sets the item filter for `self`.
///
/// Can be used to implement search within the sidebar.
///
/// Use [property`ViewSwitcherSidebar`:placeholder] to provide an empty state.
///
/// See [method`Sidebar`.set_filter].
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.Filter?` 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 filter(_ filter: Portico.Binding<Adw.Filter?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, filter, registry: ctx.registry, notifyDetail: "filter",
read: { [w] in w.getFilter() },
write: { [w] v in w.setFilter(filter: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.ViewSwitcherSidebar.setFilter(filter:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherSidebar.getFilter()
/// Sets the item filter for `self`.
///
/// Can be used to implement search within the sidebar.
///
/// Use [property`ViewSwitcherSidebar`:placeholder] to provide an empty state.
///
/// See [method`Sidebar`.set_filter].
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Adw.Filter>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.Filter?>` to be able to clear the property.
/// When `Adw.Filter` 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 filter(_ filter: Portico.Binding<Adw.Filter>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, filter, registry: ctx.registry, notifyDetail: "filter",
read: { [w] in w.getFilter() },
write: { [w] v in w.setFilter(filter: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherSidebar.setFilter(filter:)
/// Sets the item filter for `self`.
///
/// Can be used to implement search within the sidebar.
///
/// Use [property`ViewSwitcherSidebar`:placeholder] to provide an empty state.
///
/// See [method`Sidebar`.set_filter].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherSidebar.setFilter(filter:)`.
///
/// - Parameter filter: The item filter.
/// - Returns: A copy of this view with the modifier applied.
public func filter(_ filter: @escaping () -> Adw.Filter?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setFilter(filter: filter()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherSidebar.setMode(mode:)
/// Sets `self`'s look and behavior.
///
/// <picture>
/// <source srcset="view-switcher-sidebar-modes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="view-switcher-sidebar-modes.png" alt="view-switcher-sidebar-modes">
/// </picture>
///
/// If set to [enum`Adw`.SidebarMode.sidebar], behaves like a sidebar: with a
/// sidebar style and a persistent selection.
///
/// If set to [enum`Adw`.SidebarMode.page], behaves like a page of boxed lists.
/// In this mode, the selection is invisible and only tracked to determine the
/// initially selected item once switched back to sidebar mode.
///
/// The page mode is intended to be used with [class`NavigationSplitView`] when
/// collapsed, as the sidebar pane becomes a page there.
///
/// When used with [class`OverlaySplitView`], the sidebar should stay in sidebar
/// mode, as the sidebar pane is still a sidebar when collapsed.
///
/// See [method`Sidebar`.set_mode].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter mode: Determines the sidebar's look and behavior.
/// - Returns: A copy of this view with the modifier applied.
public func mode(_ mode: Adw.SidebarMode) -> Self {
appending { w, _ in
w.setMode(mode: mode)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherSidebar.setMode(mode:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherSidebar.getMode()
/// Sets `self`'s look and behavior.
///
/// <picture>
/// <source srcset="view-switcher-sidebar-modes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="view-switcher-sidebar-modes.png" alt="view-switcher-sidebar-modes">
/// </picture>
///
/// If set to [enum`Adw`.SidebarMode.sidebar], behaves like a sidebar: with a
/// sidebar style and a persistent selection.
///
/// If set to [enum`Adw`.SidebarMode.page], behaves like a page of boxed lists.
/// In this mode, the selection is invisible and only tracked to determine the
/// initially selected item once switched back to sidebar mode.
///
/// The page mode is intended to be used with [class`NavigationSplitView`] when
/// collapsed, as the sidebar pane becomes a page there.
///
/// When used with [class`OverlaySplitView`], the sidebar should stay in sidebar
/// mode, as the sidebar pane is still a sidebar when collapsed.
///
/// See [method`Sidebar`.set_mode].
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.SidebarMode` 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 mode(_ mode: Portico.Binding<Adw.SidebarMode>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, mode, registry: ctx.registry, notifyDetail: "mode",
read: { [w] in w.getMode() },
write: { [w] v in w.setMode(mode: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherSidebar.setMode(mode:)
/// Sets `self`'s look and behavior.
///
/// <picture>
/// <source srcset="view-switcher-sidebar-modes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="view-switcher-sidebar-modes.png" alt="view-switcher-sidebar-modes">
/// </picture>
///
/// If set to [enum`Adw`.SidebarMode.sidebar], behaves like a sidebar: with a
/// sidebar style and a persistent selection.
///
/// If set to [enum`Adw`.SidebarMode.page], behaves like a page of boxed lists.
/// In this mode, the selection is invisible and only tracked to determine the
/// initially selected item once switched back to sidebar mode.
///
/// The page mode is intended to be used with [class`NavigationSplitView`] when
/// collapsed, as the sidebar pane becomes a page there.
///
/// When used with [class`OverlaySplitView`], the sidebar should stay in sidebar
/// mode, as the sidebar pane is still a sidebar when collapsed.
///
/// See [method`Sidebar`.set_mode].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherSidebar.setMode(mode:)`.
///
/// - Parameter mode: Determines the sidebar's look and behavior.
/// - Returns: A copy of this view with the modifier applied.
public func mode(_ mode: @escaping () -> Adw.SidebarMode) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setMode(mode: mode()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherSidebar.setPlaceholder(placeholder:)
/// Sets the placeholder widget for `self`.
///
/// This widget will be shown if `self` has no items, or all of its items have
/// been filtered out by [property`ViewSwitcherSidebar`:filter].
///
/// See [method`Sidebar`.set_placeholder].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter placeholder: The placeholder widget.
/// - Returns: A copy of this view with the modifier applied.
public func placeholder(_ placeholder: Adw.Widget?) -> Self {
appending { w, _ in
w.setPlaceholder(placeholder: placeholder)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Adw.ViewSwitcherSidebar.setPlaceholder(placeholder:)
/// Sets the placeholder widget for `self`.
///
/// This widget will be shown if `self` has no items, or all of its items have
/// been filtered out by [property`ViewSwitcherSidebar`:filter].
///
/// See [method`Sidebar`.set_placeholder].
///
/// 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 placeholder: The placeholder widget.
/// - Returns: A copy of this view with the modifier applied.
public func placeholder(@ViewBuilder _ placeholder: () -> [AnyView]) -> Self {
let placeholderViews = placeholder()
return appending { w, ctx in
guard let v = placeholderViews.first else { return }
w.setPlaceholder(placeholder: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherSidebar.setPlaceholder(placeholder:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherSidebar.getPlaceholder()
/// Sets the placeholder widget for `self`.
///
/// This widget will be shown if `self` has no items, or all of its items have
/// been filtered out by [property`ViewSwitcherSidebar`:filter].
///
/// See [method`Sidebar`.set_placeholder].
///
/// 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 placeholder<W: Gtk.Widget>(_ placeholder: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, placeholder, registry: ctx.registry, notifyDetail: "placeholder",
read: { [w] in w.getPlaceholder() as? W },
write: { [w] v in w.setPlaceholder(placeholder: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.ViewSwitcherSidebar.setPlaceholder(placeholder:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherSidebar.getPlaceholder()
/// Sets the placeholder widget for `self`.
///
/// This widget will be shown if `self` has no items, or all of its items have
/// been filtered out by [property`ViewSwitcherSidebar`:filter].
///
/// See [method`Sidebar`.set_placeholder].
///
/// 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 placeholder<W: Gtk.Widget>(_ placeholder: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, placeholder, registry: ctx.registry, notifyDetail: "placeholder",
read: { [w] in w.getPlaceholder() as? W },
write: { [w] v in w.setPlaceholder(placeholder: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherSidebar.setPlaceholder(placeholder:)
/// Sets the placeholder widget for `self`.
///
/// This widget will be shown if `self` has no items, or all of its items have
/// been filtered out by [property`ViewSwitcherSidebar`:filter].
///
/// See [method`Sidebar`.set_placeholder].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherSidebar.setPlaceholder(placeholder:)`.
///
/// - Parameter placeholder: The placeholder widget.
/// - Returns: A copy of this view with the modifier applied.
public func placeholder(_ placeholder: @escaping () -> Adw.Widget?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setPlaceholder(placeholder: placeholder()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherSidebar.setStack(stack:)
/// Sets the stack to control.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter stack: The stack the sidebar controls.
/// - Returns: A copy of this view with the modifier applied.
public func stack(_ stack: Adw.ViewStack?) -> Self {
appending { w, _ in
w.setStack(stack: stack)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherSidebar.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherSidebar.getStack()
/// Sets the stack to control.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.ViewStack?` 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 stack<W: Adw.ViewStack>(_ stack: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, stack, registry: ctx.registry, notifyDetail: "stack",
read: { [w] in w.getStack() as? W },
write: { [w] v in w.setStack(stack: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.ViewSwitcherSidebar.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherSidebar.getStack()
/// Sets the stack to control.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Adw.ViewStack>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.ViewStack?>` to be able to clear the property.
/// When `Adw.ViewStack` 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 stack<W: Adw.ViewStack>(_ stack: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, stack, registry: ctx.registry, notifyDetail: "stack",
read: { [w] in w.getStack() as? W },
write: { [w] v in w.setStack(stack: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherSidebar.setStack(stack:)
/// Sets the stack to control.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherSidebar.setStack(stack:)`.
///
/// - Parameter stack: The stack the sidebar controls.
/// - Returns: A copy of this view with the modifier applied.
public func stack(_ stack: @escaping () -> Adw.ViewStack?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setStack(stack: stack()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.ViewSwitcherSidebar.connectActivated(_:)
/// Emitted when an item has been activated.
///
/// - Parameter handler: Invoked when the widget emits the `activated` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onActivated(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectActivated { _ in handler() })
}
}
}