230 lines
11 KiB
Swift
230 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.ViewSwitcherBar
|
|
/// A view switcher action bar.
|
|
///
|
|
/// <picture>
|
|
/// <source srcset="view-switcher-bar-dark.png" media="(prefers-color-scheme: dark)">
|
|
/// <img src="view-switcher-bar.png" alt="view-switcher-bar">
|
|
/// </picture>
|
|
///
|
|
/// An action bar letting you switch between multiple views contained in a
|
|
/// [class`ViewStack`], via an [class`ViewSwitcher`]. It is designed to be put at
|
|
/// the bottom of a window and to be revealed only on really narrow windows, e.g.
|
|
/// on mobile phones. It can't be revealed if there are less than two pages.
|
|
///
|
|
/// `AdwViewSwitcherBar` is intended to be used together with
|
|
/// `AdwViewSwitcher` in a header bar, 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
|
|
///
|
|
/// `AdwViewSwitcherBar` has a single CSS node with name` viewswitcherbar`.
|
|
///
|
|
/// See also: [class`ViewSwitcher`], [class`InlineViewSwitcher`],
|
|
/// [class`ViewSwitcherSidebar`].
|
|
///
|
|
/// A Portico view that mounts a `Adw.ViewSwitcherBar`.
|
|
@MainActor public struct ViewSwitcherBar: View {
|
|
private let make: (MountContext) -> Adw.ViewSwitcherBar
|
|
private var configure: [(Adw.ViewSwitcherBar, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Adw.ViewSwitcherBar.init()
|
|
/// Creates a new `AdwViewSwitcherBar`.
|
|
///
|
|
/// 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 reveal: Whether the bar should be revealed or hidden.
|
|
/// - Parameter stack: The stack the view switcher controls.
|
|
public init(reveal: Bool? = nil, stack: Adw.ViewStack? = nil) {
|
|
make = { _ in Adw.ViewSwitcherBar() }
|
|
configure.append { w, _ in
|
|
if let reveal { w.setReveal(reveal: reveal) }
|
|
if let stack { w.setStack(stack: stack) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension ViewSwitcherBar: WidgetView {
|
|
public typealias Target = Adw.ViewSwitcherBar
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Adw.ViewSwitcherBar, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension ViewSwitcherBar: 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.ViewSwitcherBar
|
|
/// Modifiers for `Adw.ViewSwitcherBar`, available on every Portico view whose
|
|
/// backing widget is `Adw.ViewSwitcherBar` or one of its subclasses.
|
|
extension WidgetView where Target: Adw.ViewSwitcherBar {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherBar.setReveal(reveal:)
|
|
/// Sets whether `self` should be revealed or hidden.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter reveal: Whether the bar should be revealed or hidden.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func reveal(_ reveal: Bool) -> Self {
|
|
appending { w, _ in
|
|
w.setReveal(reveal: reveal)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.ViewSwitcherBar.setReveal(reveal:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherBar.getReveal()
|
|
/// Sets whether `self` should be revealed or hidden.
|
|
///
|
|
/// 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 reveal(_ reveal: Portico.Binding<Bool>) -> Self {
|
|
appending { w, ctx in
|
|
Portico.bindProperty(
|
|
w, reveal, registry: ctx.registry, notifyDetail: "reveal",
|
|
read: { [w] in w.getReveal() },
|
|
write: { [w] v in w.setReveal(reveal: v) }
|
|
)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.ViewSwitcherBar.setReveal(reveal:)
|
|
/// Sets whether `self` should be revealed or hidden.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.ViewSwitcherBar.setReveal(reveal:)`.
|
|
///
|
|
/// - Parameter reveal: Whether the bar should be revealed or hidden.
|
|
/// - Returns: A copy of this view with the modifier applied.
|
|
public func reveal(_ reveal: @escaping () -> Bool) -> Self {
|
|
appending { w, ctx in
|
|
let tracker = DependencyTracker { [w] in w.setReveal(reveal: reveal()) }
|
|
tracker.run()
|
|
ctx.registry.add(tracker)
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.ViewSwitcherBar.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.ViewSwitcherBar.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherBar.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.ViewSwitcherBar.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.ViewSwitcherBar.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.ViewSwitcherBar.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.ViewSwitcherBar.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)
|
|
}
|
|
}
|
|
|
|
}
|