portico/Sources/Portico/Generated/MultiLayoutView.swift

265 lines
12 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.MultiLayoutView
/// A widget for switching between different layouts.
///
/// `AdwMultiLayoutView` contains layouts and children. Each child has
/// an ID, each layout has slots inside it, each slot also has an ID. When
/// switching layouts, children are inserted into slots with matching IDs. The
/// [property`Gtk`.Widget:visible] property of each slot is updated to match
/// that of the inserted child.
///
/// This can be useful for rearranging children when it's difficult to do so
/// otherwise, for example to move a child from a sidebar to a bottom bar.
///
/// The currently used layout can be switched using the
/// [property`MultiLayoutView`:layout] or [property`MultiLayoutView`:layout-name]
/// properties. For example, it can be done via a [class`Adw`.Breakpoint] setter
/// to change layouts depending on the window size.
///
/// ## AdwMultiLayoutView as GtkBuildable
///
/// The `AdwMultiLayoutView` implementation of the [iface`Gtk`.Buildable]
/// interface supports adding layouts via `<child>` element with the `type`
/// attribute omitted.
///
/// It also supports setting children via `<child type="ID">`.
///
/// Example of an `AdwMultiLayoutView` UI definition that can display a secondary
/// child as either a sidebar or a bottom sheet.
///
/// ```xml
/// <object class="AdwMultiLayoutView">
/// <child>
/// <object class="AdwLayout">
/// <property name="name">sidebar</property>
/// <property name="content">
/// <object class="AdwOverlaySplitView">
/// <property name="sidebar">
/// <object class="AdwLayoutSlot">
/// <property name="id">secondary</property>
/// </object>
/// </property>
/// <property name="content">
/// <object class="AdwLayoutSlot">
/// <property name="id">primary</property>
/// </object>
/// </property>
/// </object>
/// </property>
/// </object>
/// </child>
/// <child>
/// <object class="AdwLayout">
/// <property name="name">bottom-sheet</property>
/// <property name="content">
/// <object class="AdwBottomSheet">
/// <property name="open">True</property>
/// <property name="content">
/// <object class="AdwLayoutSlot">
/// <property name="id">primary</property>
/// </object>
/// </property>
/// <property name="sheet">
/// <object class="AdwLayoutSlot">
/// <property name="id">secondary</property>
/// </object>
/// </property>
/// </object>
/// </property>
/// </object>
/// </child>
/// <child type="primary">
/// <!-- ... -->
/// </child>
/// <child type="secondary">
/// <!-- ... -->
/// </child>
/// </object>
/// ```
///
/// ## CSS nodes
///
/// `AdwMultiLayoutView` has a single CSS node with name `multi-layout-view`.
///
/// A Portico view that mounts a `Adw.MultiLayoutView`.
@MainActor public struct MultiLayoutView: View {
private let make: (MountContext) -> Adw.MultiLayoutView
private var configure: [(Adw.MultiLayoutView, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.MultiLayoutView.init()
/// Creates a new `AdwMultiLayoutView`.
///
/// 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 layout: The currently used layout.
/// - Parameter layoutName: The name of the currently used layout.
public init(layout: Adw.Layout? = nil, layoutName: String? = nil) {
make = { _ in Adw.MultiLayoutView() }
configure.append { w, _ in
if let layout { w.setLayout(layout: layout) }
if let layoutName { w.setLayoutName(name: layoutName) }
}
}
}
extension MultiLayoutView: WidgetView {
public typealias Target = Adw.MultiLayoutView
@_spi(Portico) public func appending(
_ step: @escaping (Adw.MultiLayoutView, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension MultiLayoutView: 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.MultiLayoutView
/// Modifiers for `Adw.MultiLayoutView`, available on every Portico view whose
/// backing widget is `Adw.MultiLayoutView` or one of its subclasses.
extension WidgetView where Target: Adw.MultiLayoutView {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.MultiLayoutView.setLayout(layout:)
/// Makes `layout` the current layout of `self`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter layout: The currently used layout.
/// - Returns: A copy of this view with the modifier applied.
public func layout(_ layout: Adw.Layout) -> Self {
appending { w, _ in
w.setLayout(layout: layout)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.MultiLayoutView.setLayout(layout:), GObject.Object.connectNotify(detail:_:), Adw.MultiLayoutView.getLayout()
/// Makes `layout` the current layout of `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.Layout` 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 layout(_ layout: Portico.Binding<Adw.Layout>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, layout, registry: ctx.registry, notifyDetail: "layout",
read: { [w] in w.getLayout() },
write: { [w] v in w.setLayout(layout: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lowered) | source: Adw.MultiLayoutView.setLayout(layout:)
/// Makes `layout` the current layout of `self`.
///
/// 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 and ignores `nil` values. Binds one way only.
///
/// - Returns: A copy of this view with the modifier applied.
public func layout(_ layout: Portico.Binding<Adw.Layout?>) -> Self {
appending { w, ctx in
if let v = layout.untrackedValue { w.setLayout(layout: v) }
ctx.registry.add(layout.subscribe { [w] v in if let v { w.setLayout(layout: v) } })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.MultiLayoutView.setLayout(layout:)
/// Makes `layout` the current layout of `self`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.MultiLayoutView.setLayout(layout:)`.
///
/// - Parameter layout: The currently used layout.
/// - Returns: A copy of this view with the modifier applied.
public func layout(_ layout: @escaping () -> Adw.Layout) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setLayout(layout: layout()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.MultiLayoutView.setLayoutName(name:)
/// Makes the layout with `name` the current layout of `self`.
///
/// See [property`Layout`:name].
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter layoutName: The name of the currently used layout.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func layoutName<S: StringProtocol>(_ layoutName: S) -> Self {
appending { w, _ in
w.setLayoutName(name: String(layoutName))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.MultiLayoutView.setLayoutName(name:), GObject.Object.connectNotify(detail:_:), Adw.MultiLayoutView.getLayoutName()
/// Makes the layout with `name` the current layout of `self`.
///
/// See [property`Layout`:name].
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String` 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 layoutName(_ layoutName: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, layoutName, registry: ctx.registry, notifyDetail: "layout-name",
read: { [w] in w.getLayoutName() },
write: { [w] v in w.setLayoutName(name: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.MultiLayoutView.setLayoutName(name:)
/// Makes the layout with `name` the current layout of `self`.
///
/// See [property`Layout`:name].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.MultiLayoutView.setLayoutName(name:)`.
///
/// - Parameter layoutName: The name of the currently used layout.
/// - Returns: A copy of this view with the modifier applied.
public func layoutName(_ layoutName: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setLayoutName(name: layoutName()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.MultiLayoutView.setLayoutName(name:)
/// Makes the layout with `name` the current layout of `self`.
///
/// See [property`Layout`:name].
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.MultiLayoutView.setLayoutName(name:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter layoutName: The name of the currently used layout.
/// - Returns: A copy of this view with the modifier applied.
public func layoutName(_ layoutName: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(layoutName, registry: ctx.registry) { [w] v in w.setLayoutName(name: v) }
}
}
}