239 lines
11 KiB
Swift
239 lines
11 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.ViewSwitcher
|
|
/// An adaptive view switcher.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="view-switcher-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="view-switcher.png" alt="view-switcher">
|
|
/// </picture>
|
|
///
|
|
/// An adaptive view switcher designed to switch between multiple views
|
|
/// contained in a [class`ViewStack`] in a similar fashion to
|
|
/// [class`Gtk`.StackSwitcher].
|
|
///
|
|
/// `AdwViewSwitcher` buttons always have an icon and a label. They can be
|
|
/// displayed side by side, or icon on top of the label. This can be controlled
|
|
/// via the [property`ViewSwitcher`:policy] property.
|
|
///
|
|
/// `AdwViewSwitcher` is intended to be used in a header bar together with
|
|
/// [class`ViewSwitcherBar`] at the bottom of the window, and a [class`Breakpoint`]
|
|
/// showing the view switcher bar on narrow sizes, while removing the view
|
|
/// switcher from the header bar, as follows:
|
|
///
|
|
/// ```xml
|
|
/// <object class="AdwWindow">
|
|
/// <child>
|
|
/// <object class="AdwBreakpoint">
|
|
/// <condition>max-width: 550sp</condition>
|
|
/// <setter object="switcher_bar" property="reveal">True</setter>
|
|
/// <setter object="header_bar" property="title-widget"/>
|
|
/// </object>
|
|
/// </child>
|
|
/// <property name="content">
|
|
/// <object class="AdwToolbarView">
|
|
/// <child type="top">
|
|
/// <object class="AdwHeaderBar" id="header_bar">
|
|
/// <property name="title-widget">
|
|
/// <object class="AdwViewSwitcher">
|
|
/// <property name="stack">stack</property>
|
|
/// <property name="policy">wide</property>
|
|
/// </object>
|
|
/// </property>
|
|
/// </object>
|
|
/// </child>
|
|
/// <property name="content">
|
|
/// <object class="AdwViewStack" id="stack"/>
|
|
/// </property>
|
|
/// <child type="bottom">
|
|
/// <object class="AdwViewSwitcherBar" id="switcher_bar">
|
|
/// <property name="stack">stack</property>
|
|
/// </object>
|
|
/// </child>
|
|
/// </object>
|
|
/// </property>
|
|
/// </object>
|
|
/// ```
|
|
///
|
|
/// It's recommended to set [property`ViewSwitcher`:policy] to
|
|
/// [enum`Adw`.ViewSwitcherPolicy.wide] in this case.
|
|
///
|
|
/// You may have to adjust the breakpoint condition for your specific pages.
|
|
///
|
|
/// ## CSS nodes
|
|
///
|
|
/// `AdwViewSwitcher` has a single CSS node with name `viewswitcher`. It can have
|
|
/// the style classes `.wide` and `.narrow`, matching its policy.
|
|
///
|
|
/// ## Accessibility
|
|
///
|
|
/// `AdwViewSwitcher` uses the [enum`Gtk`.AccessibleRole.tab-list] role and the
|
|
/// [enum`Gtk`.AccessibleRole.tab] role for its buttons.
|
|
///
|
|
/// See also: [class`ViewSwitcherBar`], [class`InlineViewSwitcher`],
|
|
/// [class`ViewSwitcherSidebar`].
|
|
///
|
|
/// A Portico view that mounts a `Adw.ViewSwitcher`.
|
|
@MainActor public struct ViewSwitcher: View {
|
|
private let make: (MountContext) -> Adw.ViewSwitcher
|
|
private var configure: [(Adw.ViewSwitcher, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Adw.ViewSwitcher.init()
|
|
/// Creates a new `AdwViewSwitcher`.
|
|
///
|
|
/// 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 policy: The policy to determine which mode to use.
|
|
/// - Parameter stack: The stack the view switcher controls.
|
|
public init(policy: Adw.ViewSwitcherPolicy? = nil, stack: Adw.ViewStack? = nil) {
|
|
make = { _ in Adw.ViewSwitcher() }
|
|
configure.append { w, _ in
|
|
if let policy { w.setPolicy(policy: policy) }
|
|
if let stack { w.setStack(stack: stack) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension ViewSwitcher: WidgetView {
|
|
public typealias Target = Adw.ViewSwitcher
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Adw.ViewSwitcher, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension ViewSwitcher: 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.ViewSwitcher
|
|
/// Modifiers for `Adw.ViewSwitcher`, available on every Portico view whose
|
|
/// backing widget is `Adw.ViewSwitcher` or one of its subclasses.
|
|
extension WidgetView where Target: Adw.ViewSwitcher {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcher.setPolicy(policy:)
|
|
/// Sets the policy of `self`.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter policy: The policy to determine which mode to use.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func policy(_ policy: Adw.ViewSwitcherPolicy) -> Self {
|
|
appending { w, _ in
|
|
w.setPolicy(policy: policy)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcher.setPolicy(policy:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcher.getPolicy()
|
|
/// Sets the policy of `self`.
|
|
///
|
|
/// Applied at mount and re-applied on every change the binding publishes.
|
|
/// When `Adw.ViewSwitcherPolicy` 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 policy(_ policy: Portico.Binding<Adw.ViewSwitcherPolicy>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, policy, registry: ctx.registry, notifyDetail: "policy",
|
|
read: { [w] in w.getPolicy() },
|
|
write: { [w] v in w.setPolicy(policy: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcher.setPolicy(policy:)
|
|
/// Sets the policy of `self`.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcher.setPolicy(policy:)`.
|
|
///
|
|
/// - Parameter policy: The policy to determine which mode to use.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func policy(_ policy: @escaping () -> Adw.ViewSwitcherPolicy) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setPolicy(policy: policy()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcher.setStack(stack:)
|
|
/// Sets the stack controlled by `self`.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter stack: The stack the view switcher 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.ViewSwitcher.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcher.getStack()
|
|
/// Sets the stack controlled by `self`.
|
|
///
|
|
/// 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.ViewSwitcher.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcher.getStack()
|
|
/// Sets the stack controlled by `self`.
|
|
///
|
|
/// 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.ViewSwitcher.setStack(stack:)
|
|
/// Sets the stack controlled by `self`.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcher.setStack(stack:)`.
|
|
///
|
|
/// - Parameter stack: The stack the view switcher 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)
|
|
}
|
|
}
|
|
|
|
}
|