portico/Sources/Portico/Generated/InlineViewSwitcher.swift

338 lines
17 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.InlineViewSwitcher
/// A view switcher that uses a toggle group.
///
/// <picture>
/// <source srcset="inline-view-switcher-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="inline-view-switcher.png" alt="inline-view-switcher">
/// </picture>
///
/// A view switcher showing pages of an [class`ViewStack`] within an
/// [class`ToggleGroup`], similar to [class`ViewSwitcher`].
///
/// The toggles can display either an icon, a label or both. Use the
/// [property`InlineViewSwitcher`:display-mode] to control this.
///
/// <picture>
/// <source srcset="inline-view-switcher-display-modes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="inline-view-switcher-display-modes.png" alt="inline-view-switcher-display-modes">
/// </picture>
///
/// ## CSS nodes
///
/// `AdwInlineViewSwitcher` has a single CSS node with the name
/// `inline-view-switcher`.
///
/// ## Style classes
///
/// Like `AdwToggleGroup`, it can accept the [`.flat`](style-classes.html`flat_1`)
/// and [`.round`](style-classes.html`round`) style classes.
///
/// <picture>
/// <source srcset="inline-view-switcher-style-classes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="inline-view-switcher-style-classes.png" alt="inline-view-switcher-style-classes">
/// </picture>
///
/// ## Accessibility
///
/// The internal toggle group uses the [enum`Gtk`.AccessibleRole.tab-list] role.
/// Its toggles use the [enum`Gtk`.AccessibleRole.tab] role.
///
/// See also: [class`ViewSwitcher`], [class`ViewSwitcherBar`],
/// [class`ViewSwitcherSidebar`].
///
/// A Portico view that mounts a `Adw.InlineViewSwitcher`.
@MainActor public struct InlineViewSwitcher: View {
private let make: (MountContext) -> Adw.InlineViewSwitcher
private var configure: [(Adw.InlineViewSwitcher, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.InlineViewSwitcher.init()
/// Creates a new `AdwInlineViewSwitcher`.
///
/// 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 canShrink: Whether the toggles can be smaller than the natural size of their contents.
/// - Parameter displayMode: The display mode.
/// - Parameter homogeneous: Whether all toggles take the same size.
/// - Parameter stack: The stack the view switcher controls.
public init(canShrink: Bool? = nil, displayMode: Adw.InlineViewSwitcherDisplayMode? = nil, homogeneous: Bool? = nil, stack: Adw.ViewStack? = nil) {
make = { _ in Adw.InlineViewSwitcher() }
configure.append { w, _ in
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let displayMode { w.setDisplayMode(mode: displayMode) }
if let homogeneous { w.setHomogeneous(homogeneous: homogeneous) }
if let stack { w.setStack(stack: stack) }
}
}
}
extension InlineViewSwitcher: WidgetView {
public typealias Target = Adw.InlineViewSwitcher
@_spi(Portico) public func appending(
_ step: @escaping (Adw.InlineViewSwitcher, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension InlineViewSwitcher: 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.InlineViewSwitcher
/// Modifiers for `Adw.InlineViewSwitcher`, available on every Portico view whose
/// backing widget is `Adw.InlineViewSwitcher` or one of its subclasses.
extension WidgetView where Target: Adw.InlineViewSwitcher {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.InlineViewSwitcher.setCanShrink(canShrink:)
/// Sets whether the toggles can be smaller than the natural size of their
/// contents.
///
/// If `can_shrink` is `TRUE`, the toggle labels will ellipsize.
///
/// See [property`ToggleGroup`:can-shrink].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter canShrink: Whether the toggles can be smaller than the natural size of their contents.
/// - Returns: A copy of this view with the modifier applied.
public func canShrink(_ canShrink: Bool) -> Self {
appending { w, _ in
w.setCanShrink(canShrink: canShrink)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.InlineViewSwitcher.setCanShrink(canShrink:), GObject.Object.connectNotify(detail:_:), Adw.InlineViewSwitcher.getCanShrink()
/// Sets whether the toggles can be smaller than the natural size of their
/// contents.
///
/// If `can_shrink` is `TRUE`, the toggle labels will ellipsize.
///
/// See [property`ToggleGroup`:can-shrink].
///
/// 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 canShrink(_ canShrink: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, canShrink, registry: ctx.registry, notifyDetail: "can-shrink",
read: { [w] in w.getCanShrink() },
write: { [w] v in w.setCanShrink(canShrink: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.InlineViewSwitcher.setCanShrink(canShrink:)
/// Sets whether the toggles can be smaller than the natural size of their
/// contents.
///
/// If `can_shrink` is `TRUE`, the toggle labels will ellipsize.
///
/// See [property`ToggleGroup`:can-shrink].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.InlineViewSwitcher.setCanShrink(canShrink:)`.
///
/// - Parameter canShrink: Whether the toggles can be smaller than the natural size of their contents.
/// - Returns: A copy of this view with the modifier applied.
public func canShrink(_ canShrink: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setCanShrink(canShrink: canShrink()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.InlineViewSwitcher.setDisplayMode(mode:)
/// Sets the display mode of `self`.
///
/// Determines what the toggles display: a label, an icon or both.
///
/// <picture>
/// <source srcset="inline-view-switcher-display-modes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="inline-view-switcher-display-modes.png" alt="inline-view-switcher-display-modes">
/// </picture>
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter displayMode: The display mode.
/// - Returns: A copy of this view with the modifier applied.
public func displayMode(_ displayMode: Adw.InlineViewSwitcherDisplayMode) -> Self {
appending { w, _ in
w.setDisplayMode(mode: displayMode)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.InlineViewSwitcher.setDisplayMode(mode:), GObject.Object.connectNotify(detail:_:), Adw.InlineViewSwitcher.getDisplayMode()
/// Sets the display mode of `self`.
///
/// Determines what the toggles display: a label, an icon or both.
///
/// <picture>
/// <source srcset="inline-view-switcher-display-modes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="inline-view-switcher-display-modes.png" alt="inline-view-switcher-display-modes">
/// </picture>
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.InlineViewSwitcherDisplayMode` 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 displayMode(_ displayMode: Portico.Binding<Adw.InlineViewSwitcherDisplayMode>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, displayMode, registry: ctx.registry, notifyDetail: "display-mode",
read: { [w] in w.getDisplayMode() },
write: { [w] v in w.setDisplayMode(mode: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.InlineViewSwitcher.setDisplayMode(mode:)
/// Sets the display mode of `self`.
///
/// Determines what the toggles display: a label, an icon or both.
///
/// <picture>
/// <source srcset="inline-view-switcher-display-modes-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="inline-view-switcher-display-modes.png" alt="inline-view-switcher-display-modes">
/// </picture>
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.InlineViewSwitcher.setDisplayMode(mode:)`.
///
/// - Parameter displayMode: The display mode.
/// - Returns: A copy of this view with the modifier applied.
public func displayMode(_ displayMode: @escaping () -> Adw.InlineViewSwitcherDisplayMode) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setDisplayMode(mode: displayMode()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.InlineViewSwitcher.setHomogeneous(homogeneous:)
/// Sets whether all toggles within `self` take the same size.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter homogeneous: Whether all toggles take the same size.
/// - Returns: A copy of this view with the modifier applied.
public func homogeneous(_ homogeneous: Bool) -> Self {
appending { w, _ in
w.setHomogeneous(homogeneous: homogeneous)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.InlineViewSwitcher.setHomogeneous(homogeneous:), GObject.Object.connectNotify(detail:_:), Adw.InlineViewSwitcher.getHomogeneous()
/// Sets whether all toggles within `self` take the same size.
///
/// 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 homogeneous(_ homogeneous: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, homogeneous, registry: ctx.registry, notifyDetail: "homogeneous",
read: { [w] in w.getHomogeneous() },
write: { [w] v in w.setHomogeneous(homogeneous: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.InlineViewSwitcher.setHomogeneous(homogeneous:)
/// Sets whether all toggles within `self` take the same size.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.InlineViewSwitcher.setHomogeneous(homogeneous:)`.
///
/// - Parameter homogeneous: Whether all toggles take the same size.
/// - Returns: A copy of this view with the modifier applied.
public func homogeneous(_ homogeneous: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setHomogeneous(homogeneous: homogeneous()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.InlineViewSwitcher.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 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.InlineViewSwitcher.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.InlineViewSwitcher.getStack()
/// Sets the stack to control.
///
/// 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.InlineViewSwitcher.setStack(stack:), GObject.Object.connectNotify(detail:_:), Adw.InlineViewSwitcher.getStack()
/// Sets the stack to control.
///
/// 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.InlineViewSwitcher.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 `Adw.InlineViewSwitcher.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)
}
}
}