portico/Sources/Portico/Generated/StackSwitcher.swift

156 lines
6.9 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.StackSwitcher
/// Shows a row of buttons to switch between `GtkStack` pages.
///
/// <picture>
/// <source srcset="stackswitcher-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkStackSwitcher" src="stackswitcher.png">
/// </picture>
///
/// It acts as a controller for the associated `GtkStack`.
///
/// All the content for the buttons comes from the properties of the stacks
/// [class`Gtk`.StackPage] objects; the button visibility in a `GtkStackSwitcher`
/// widget is controlled by the visibility of the child in the `GtkStack`.
///
/// It is possible to associate multiple `GtkStackSwitcher` widgets
/// with the same `GtkStack` widget.
///
/// # CSS nodes
///
/// `GtkStackSwitcher` has a single CSS node named stackswitcher and
/// style class .stack-switcher.
///
/// When circumstances require it, `GtkStackSwitcher` adds the
/// .needs-attention style class to the widgets representing the
/// stack pages.
///
/// # Accessibility
///
/// `GtkStackSwitcher` uses the [enum`Gtk`.AccessibleRole.tab_list] role
/// and uses the [enum`Gtk`.AccessibleRole.tab] role for its buttons.
///
/// # Orientable
///
/// Since GTK 4.4, `GtkStackSwitcher` implements `GtkOrientable` allowing
/// the stack switcher to be made vertical with
/// `gtk_orientable_set_orientation()`.
///
/// A Portico view that mounts a `Gtk.StackSwitcher`.
@MainActor public struct StackSwitcher: View {
private let make: (MountContext) -> Gtk.StackSwitcher
private var configure: [(Gtk.StackSwitcher, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.StackSwitcher.init()
/// Create a new `GtkStackSwitcher`.
///
/// 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.StackSwitcher() }
configure.append { w, _ in
if let stack { w.setStack(stack: stack) }
}
}
}
extension StackSwitcher: WidgetView {
public typealias Target = Gtk.StackSwitcher
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.StackSwitcher, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension StackSwitcher: 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.StackSwitcher
/// Modifiers for `Gtk.StackSwitcher`, available on every Portico view whose
/// backing widget is `Gtk.StackSwitcher` or one of its subclasses.
extension WidgetView where Target: Gtk.StackSwitcher {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.StackSwitcher.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.
/// - 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.StackSwitcher.setStack(stack:), GObject.Object.connectNotify(detail:_:), Gtk.StackSwitcher.getStack()
/// Sets the stack to control.
///
/// 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(lifted,twoWay) | source: Gtk.StackSwitcher.setStack(stack:), GObject.Object.connectNotify(detail:_:), Gtk.StackSwitcher.getStack()
/// Sets the stack to control.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Gtk.Stack>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.Stack?>` to be able to clear the property.
/// 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.
/// 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: 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(closure) | source: Gtk.StackSwitcher.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 `Gtk.StackSwitcher.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)
}
}
}