portico/Sources/Portico/Generated/PreferencesGroup.swift

424 lines
23 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.PreferencesGroup
/// A group of preference rows.
///
/// <picture>
/// <source srcset="preferences-group-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="preferences-group.png" alt="preferences-group">
/// </picture>
///
/// An `AdwPreferencesGroup` represents a group or tightly related preferences,
/// which in turn are represented by [class`PreferencesRow`].
///
/// To summarize the role of the preferences it gathers, a group can have both a
/// title and a description. The title will be used by [class`PreferencesDialog`]
/// to let the user look for a preference.
///
/// The [property`PreferencesGroup`:separate-rows] property can be used to
/// separate the rows within the group, same as when using the
/// [`.boxed-list-separate`](style-classes.html`boxed`-lists-cards) style class
/// instead of `.boxed-list`.
///
/// ## AdwPreferencesGroup as GtkBuildable
///
/// The `AdwPreferencesGroup` implementation of the [iface`Gtk`.Buildable] interface
/// supports adding [class`PreferencesRow`]s to the list by omitting "type". If "type"
/// is omitted and the widget isn't a [class`PreferencesRow`] the child is added to
/// a box below the list.
///
/// When the "type" attribute of a child is `header-suffix`, the child
/// is set as the suffix on the end of the title and description.
///
/// ## CSS nodes
///
/// `AdwPreferencesGroup` has a single CSS node with name `preferencesgroup`.
///
/// ## Accessibility
///
/// `AdwPreferencesGroup` uses the [enum`Gtk`.AccessibleRole.group] role.
///
/// A Portico view that mounts a `Adw.PreferencesGroup`.
@MainActor public struct PreferencesGroup: View {
private let make: (MountContext) -> Adw.PreferencesGroup
private var configure: [(Adw.PreferencesGroup, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.PreferencesGroup.init()
/// Creates a new `AdwPreferencesGroup`.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// A `ForEach` in the `children:` closure spreads its rows directly into this widget, with no wrapper, when the widget supports ordered insertion.
/// 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 description: The description for this group of preferences.
/// - Parameter separateRows: Whether to separate rows.
/// - Parameter title: The title for this group of preferences.
/// - Parameter children: A `ViewBuilder` closure whose views are added in order.
/// - Parameter headerSuffix: A `ViewBuilder` closure whose first view is mounted into the `headerSuffix` slot.
public init(description: String? = nil, separateRows: Bool? = nil, title: String? = nil, @ViewBuilder children: @escaping () -> [AnyView] = { [] }, @ViewBuilder headerSuffix: @escaping () -> [AnyView] = { [] }) {
make = { _ in Adw.PreferencesGroup() }
configure.append { w, ctx in
if let description { w.setDescription(description: description) }
if let separateRows { w.setSeparateRows(separateRows: separateRows) }
if let title { w.setTitle(title: title) }
Portico.mountChildren(children, into: w, ctx) { c in w.add(child: c) }
if let v = Portico.mountSlotChild(headerSuffix, ctx, onUpdate: { v in w.setHeaderSuffix(suffix: v) }) { w.setHeaderSuffix(suffix: v) }
}
}
}
extension PreferencesGroup: WidgetView {
public typealias Target = Adw.PreferencesGroup
@_spi(Portico) public func appending(
_ step: @escaping (Adw.PreferencesGroup, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension PreferencesGroup: 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.PreferencesGroup
/// Modifiers for `Adw.PreferencesGroup`, available on every Portico view whose
/// backing widget is `Adw.PreferencesGroup` or one of its subclasses.
extension WidgetView where Target: Adw.PreferencesGroup {
// PorticoGen: generateModifierExtension -> generateChildAdderModifiers(static) | source: Adw.PreferencesGroup.add(child:)
/// Adds a child to `self`.
///
/// Applied once at mount; use the `@ViewBuilder` overload for multiple children.
///
/// - Parameter child: A child widget to add.
/// - Returns: A copy of this view with the modifier applied.
public func add(_ child: Gtk.Widget) -> Self {
appending { w, _ in
w.add(child: child)
}
}
// PorticoGen: generateModifierExtension -> generateChildAdderModifiers(viewBuilder) | source: Adw.PreferencesGroup.add(child:)
/// Adds a child to `self`.
///
/// Every view the closure produces is added at mount, in order.
///
/// - Parameter child: A closure producing child views.
/// - Returns: A copy of this view with the modifier applied.
public func add(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
for v in childViews { w.add(child: v.makeWidget(ctx)) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.PreferencesGroup.setDescription(description:)
/// Sets the description for `self`.
///
/// 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 description: The description for this group of preferences.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func description<S: StringProtocol>(_ description: S?) -> Self {
appending { w, _ in
w.setDescription(description: description.map { String($0) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.PreferencesGroup.setDescription(description:), GObject.Object.connectNotify(detail:_:), Adw.PreferencesGroup.getDescription()
/// Sets the description for `self`.
///
/// 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 description(_ description: Portico.Binding<String?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, description, registry: ctx.registry, notifyDetail: "description",
read: { [w] in w.getDescription() },
write: { [w] v in w.setDescription(description: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.PreferencesGroup.setDescription(description:), GObject.Object.connectNotify(detail:_:), Adw.PreferencesGroup.getDescription()
/// Sets the description for `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<String>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<String?>` to be able to clear the property.
/// 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.
/// A `nil` widget value is never written back into the binding.
///
/// - Returns: A copy of this view with the modifier applied.
public func description(_ description: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, description, registry: ctx.registry, notifyDetail: "description",
read: { [w] in w.getDescription() },
write: { [w] v in w.setDescription(description: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.PreferencesGroup.setDescription(description:)
/// Sets the description for `self`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.PreferencesGroup.setDescription(description:)`.
///
/// - Parameter description: The description for this group of preferences.
/// - Returns: A copy of this view with the modifier applied.
public func description(_ description: @escaping () -> String?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setDescription(description: description()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.PreferencesGroup.setDescription(description:)
/// Sets the description for `self`.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.PreferencesGroup.setDescription(description:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter description: The description for this group of preferences.
/// - Returns: A copy of this view with the modifier applied.
public func description(_ description: Portico.InterpolatedText?) -> Self {
appending { w, ctx in
Portico.bindOptionalInterpolation(description, registry: ctx.registry) { [w] v in w.setDescription(description: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.PreferencesGroup.setHeaderSuffix(suffix:)
/// Sets the suffix for `self`'s header.
///
/// Displayed above the list, next to the title and description.
///
/// Suffixes are commonly used to show a button or a spinner for the whole group.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter headerSuffix: The header suffix widget.
/// - Returns: A copy of this view with the modifier applied.
public func headerSuffix(_ headerSuffix: Adw.Widget?) -> Self {
appending { w, _ in
w.setHeaderSuffix(suffix: headerSuffix)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Adw.PreferencesGroup.setHeaderSuffix(suffix:)
/// Sets the suffix for `self`'s header.
///
/// Displayed above the list, next to the title and description.
///
/// Suffixes are commonly used to show a button or a spinner for the whole group.
///
/// The closure is evaluated once when the modifier is applied. Its first view is mounted into the slot.
/// Additional views are ignored; an empty closure leaves the slot unset.
///
/// - Parameter headerSuffix: The header suffix widget.
/// - Returns: A copy of this view with the modifier applied.
public func headerSuffix(@ViewBuilder _ headerSuffix: () -> [AnyView]) -> Self {
let headerSuffixViews = headerSuffix()
return appending { w, ctx in
guard let v = headerSuffixViews.first else { return }
w.setHeaderSuffix(suffix: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.PreferencesGroup.setHeaderSuffix(suffix:), GObject.Object.connectNotify(detail:_:), Adw.PreferencesGroup.getHeaderSuffix()
/// Sets the suffix for `self`'s header.
///
/// Displayed above the list, next to the title and description.
///
/// Suffixes are commonly used to show a button or a spinner for the whole group.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.Widget?` 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 headerSuffix<W: Gtk.Widget>(_ headerSuffix: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, headerSuffix, registry: ctx.registry, notifyDetail: "header-suffix",
read: { [w] in w.getHeaderSuffix() as? W },
write: { [w] v in w.setHeaderSuffix(suffix: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.PreferencesGroup.setHeaderSuffix(suffix:), GObject.Object.connectNotify(detail:_:), Adw.PreferencesGroup.getHeaderSuffix()
/// Sets the suffix for `self`'s header.
///
/// Displayed above the list, next to the title and description.
///
/// Suffixes are commonly used to show a button or a spinner for the whole group.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Adw.Widget>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.Widget?>` to be able to clear the property.
/// When `Adw.Widget` 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 headerSuffix<W: Gtk.Widget>(_ headerSuffix: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, headerSuffix, registry: ctx.registry, notifyDetail: "header-suffix",
read: { [w] in w.getHeaderSuffix() as? W },
write: { [w] v in w.setHeaderSuffix(suffix: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.PreferencesGroup.setHeaderSuffix(suffix:)
/// Sets the suffix for `self`'s header.
///
/// Displayed above the list, next to the title and description.
///
/// Suffixes are commonly used to show a button or a spinner for the whole group.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.PreferencesGroup.setHeaderSuffix(suffix:)`.
///
/// - Parameter headerSuffix: The header suffix widget.
/// - Returns: A copy of this view with the modifier applied.
public func headerSuffix(_ headerSuffix: @escaping () -> Adw.Widget?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setHeaderSuffix(suffix: headerSuffix()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.PreferencesGroup.setSeparateRows(separateRows:)
/// Sets whether `self`'s rows are separated.
///
/// Equivalent to using the
/// [`.boxed-list-separate`](style-classes.html`boxed`-lists-cards) style class
/// on a [class`Gtk`.ListBox] instead of `.boxed-list`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter separateRows: Whether to separate rows.
/// - Returns: A copy of this view with the modifier applied.
public func separateRows(_ separateRows: Bool) -> Self {
appending { w, _ in
w.setSeparateRows(separateRows: separateRows)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.PreferencesGroup.setSeparateRows(separateRows:), GObject.Object.connectNotify(detail:_:), Adw.PreferencesGroup.getSeparateRows()
/// Sets whether `self`'s rows are separated.
///
/// Equivalent to using the
/// [`.boxed-list-separate`](style-classes.html`boxed`-lists-cards) style class
/// on a [class`Gtk`.ListBox] instead of `.boxed-list`.
///
/// 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 separateRows(_ separateRows: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, separateRows, registry: ctx.registry, notifyDetail: "separate-rows",
read: { [w] in w.getSeparateRows() },
write: { [w] v in w.setSeparateRows(separateRows: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.PreferencesGroup.setSeparateRows(separateRows:)
/// Sets whether `self`'s rows are separated.
///
/// Equivalent to using the
/// [`.boxed-list-separate`](style-classes.html`boxed`-lists-cards) style class
/// on a [class`Gtk`.ListBox] instead of `.boxed-list`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.PreferencesGroup.setSeparateRows(separateRows:)`.
///
/// - Parameter separateRows: Whether to separate rows.
/// - Returns: A copy of this view with the modifier applied.
public func separateRows(_ separateRows: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setSeparateRows(separateRows: separateRows()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.PreferencesGroup.setTitle(title:)
/// Sets the title for `self`.
///
/// 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 title: The title for this group of preferences.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func title<S: StringProtocol>(_ title: S) -> Self {
appending { w, _ in
w.setTitle(title: String(title))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.PreferencesGroup.setTitle(title:), GObject.Object.connectNotify(detail:_:), Adw.PreferencesGroup.getTitle()
/// Sets the title for `self`.
///
/// 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 title(_ title: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, title, registry: ctx.registry, notifyDetail: "title",
read: { [w] in w.getTitle() },
write: { [w] v in w.setTitle(title: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.PreferencesGroup.setTitle(title:)
/// Sets the title for `self`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.PreferencesGroup.setTitle(title:)`.
///
/// - Parameter title: The title for this group of preferences.
/// - Returns: A copy of this view with the modifier applied.
public func title(_ title: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setTitle(title: title()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Adw.PreferencesGroup.setTitle(title:)
/// Sets the title for `self`.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Adw.PreferencesGroup.setTitle(title:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter title: The title for this group of preferences.
/// - Returns: A copy of this view with the modifier applied.
public func title(_ title: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(title, registry: ctx.registry) { [w] v in w.setTitle(title: v) }
}
}
}