148 lines
6.3 KiB
Swift
148 lines
6.3 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: Gtk.StackSidebar
|
|
/// Uses a sidebar to switch between `GtkStack` pages.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="sidebar-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img alt="An example GtkStackSidebar" src="sidebar.png">
|
|
/// </picture>
|
|
///
|
|
/// In order to use a `GtkStackSidebar`, you simply use a `GtkStack` to
|
|
/// organize your UI flow, and add the sidebar to your sidebar area. You
|
|
/// can use [method`Gtk`.StackSidebar.set_stack] to connect the `GtkStackSidebar`
|
|
/// to the `GtkStack`.
|
|
///
|
|
/// # CSS nodes
|
|
///
|
|
/// `GtkStackSidebar` has a single CSS node with name stacksidebar and
|
|
/// style class .sidebar.
|
|
///
|
|
/// When circumstances require it, `GtkStackSidebar` adds the
|
|
/// .needs-attention style class to the widgets representing the stack
|
|
/// pages.
|
|
///
|
|
/// A Portico view that mounts a `Gtk.StackSidebar`.
|
|
@MainActor public struct StackSidebar: View {
|
|
private let make: (MountContext) -> Gtk.StackSidebar
|
|
private var configure: [(Gtk.StackSidebar, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Gtk.StackSidebar.init()
|
|
/// Creates a new `GtkStackSidebar`.
|
|
///
|
|
/// 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 stack: The stack.
|
|
public init(stack: Gtk.Stack? = nil) {
|
|
make = { _ in Gtk.StackSidebar() }
|
|
configure.append { w, _ in
|
|
if let stack { w.setStack(stack: stack) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension StackSidebar: WidgetView {
|
|
public typealias Target = Gtk.StackSidebar
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Gtk.StackSidebar, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension StackSidebar: 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: Gtk.StackSidebar
|
|
/// Modifiers for `Gtk.StackSidebar`, available on every Portico view whose
|
|
/// backing widget is `Gtk.StackSidebar` or one of its subclasses.
|
|
extension WidgetView where Target: Gtk.StackSidebar {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.StackSidebar.setStack(stack:)
|
|
/// Set the `GtkStack` associated with this `GtkStackSidebar`.
|
|
///
|
|
/// The sidebar widget will automatically update according to
|
|
/// the order and items within the given `GtkStack`.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter stack: The stack.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func stack(_ stack: Gtk.Stack) -> Self {
|
|
appending { w, _ in
|
|
w.setStack(stack: stack)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.StackSidebar.setStack(stack:), GObject.Object.connectNotify(detail:_:), Gtk.StackSidebar.getStack()
|
|
/// Set the `GtkStack` associated with this `GtkStackSidebar`.
|
|
///
|
|
/// The sidebar widget will automatically update according to
|
|
/// the order and items within the given `GtkStack`.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `Gtk.Stack` 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: Gtk.Stack>(_ 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(lowered) | source: Gtk.StackSidebar.setStack(stack:)
|
|
/// Set the `GtkStack` associated with this `GtkStackSidebar`.
|
|
///
|
|
/// The sidebar widget will automatically update according to
|
|
/// the order and items within the given `GtkStack`.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// `Binding` is invariant and this property has no unset state; this overload accepts a nullable binding (what a `WidgetRef` projects) and ignores `nil` values. Binds one way only.
|
|
///
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func stack<W: Gtk.Stack>(_ stack: Portico.Binding<W?>) -> Self {
|
|
appending { w, ctx in
|
|
if let v = stack.untrackedValue { w.setStack(stack: v) }
|
|
ctx.registry.add(stack.subscribe { [w] v in if let v { w.setStack(stack: v) } })
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.StackSidebar.setStack(stack:)
|
|
/// Set the `GtkStack` associated with this `GtkStackSidebar`.
|
|
///
|
|
/// The sidebar widget will automatically update according to
|
|
/// the order and items within the given `GtkStack`.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.StackSidebar.setStack(stack:)`.
|
|
///
|
|
/// - Parameter stack: The stack.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func stack(_ stack: @escaping () -> Gtk.Stack) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setStack(stack: stack()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
}
|