133 lines
5.3 KiB
Swift
133 lines
5.3 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.Spinner
|
||
/// A widget showing a loading spinner.
|
||
///
|
||
/// <picture>
|
||
/// <source srcset="spinner-dark.png" media="(prefers-color-scheme: dark)">
|
||
/// <img src="spinner.png" alt="spinner">
|
||
/// </picture>
|
||
///
|
||
/// The size of the spinner depends on the available size, never smaller than
|
||
/// 16×16 pixels and never larger than 64×64 pixels.
|
||
///
|
||
/// Use the [property`Gtk`.Widget:halign] and [property`Gtk`.Widget:valign]
|
||
/// properties in combination with [property`Gtk`.Widget:width-request] and
|
||
/// [property`Gtk`.Widget:height-request] for fine sizing control.
|
||
///
|
||
/// For example, the following snippet shows the spinner at 48×48 pixels:
|
||
///
|
||
/// ```xml
|
||
/// <object class="AdwSpinner">
|
||
/// <property name="halign">center</property>
|
||
/// <property name="valign">center</property>
|
||
/// <property name="width-request">48</property>
|
||
/// <property name="height-request">48</property>
|
||
/// </object>
|
||
/// ```
|
||
///
|
||
/// See [class`SpinnerPaintable`] for cases where using a widget is impractical or
|
||
/// impossible, such as [property`StatusPage`:paintable].
|
||
///
|
||
/// ## CSS nodes
|
||
///
|
||
/// `AdwSpinner` has a single node with the name `image` and the style class
|
||
/// `.spinner`.
|
||
///
|
||
/// ## Accessibility
|
||
///
|
||
/// `AdwSpinner` uses the [enum`Gtk`.AccessibleRole.progress-bar] role.
|
||
///
|
||
/// A Portico view that mounts a `Adw.Spinner`.
|
||
@MainActor public struct Spinner: View {
|
||
private let make: (MountContext) -> Adw.Spinner
|
||
private var configure: [(Adw.Spinner, MountContext) -> Void] = []
|
||
|
||
public var body: Never { fatalError() }
|
||
|
||
// PorticoGen: generateInits(static) | source: Adw.Spinner.init()
|
||
/// Creates a new `AdwSpinner`.
|
||
///
|
||
/// 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.
|
||
public init() {
|
||
make = { _ in Adw.Spinner() }
|
||
}
|
||
|
||
}
|
||
|
||
extension Spinner: WidgetView {
|
||
public typealias Target = Adw.Spinner
|
||
|
||
@_spi(Portico) public func appending(
|
||
_ step: @escaping (Adw.Spinner, MountContext) -> Void
|
||
) -> Self {
|
||
var c = self
|
||
c.configure.append(step)
|
||
return c
|
||
}
|
||
}
|
||
|
||
@_spi(Portico) extension Spinner: 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: Gtk.Spinner
|
||
/// Modifiers for `Gtk.Spinner`, available on every Portico view whose
|
||
/// backing widget is `Gtk.Spinner` or one of its subclasses.
|
||
extension WidgetView where Target: Gtk.Spinner {
|
||
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Spinner.setSpinning(spinning:)
|
||
/// Sets the activity of the spinner.
|
||
///
|
||
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
||
///
|
||
/// - Parameter spinning: Whether the spinner is spinning
|
||
/// - Returns: A copy of this view with the modifier applied.
|
||
public func spinning(_ spinning: Bool) -> Self {
|
||
appending { w, _ in
|
||
w.setSpinning(spinning: spinning)
|
||
}
|
||
}
|
||
|
||
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Spinner.setSpinning(spinning:), GObject.Object.connectNotify(detail:_:), Gtk.Spinner.getSpinning()
|
||
/// Sets the activity of the spinner.
|
||
///
|
||
/// 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 spinning(_ spinning: Portico.Binding<Bool>) -> Self {
|
||
appending { w, ctx in
|
||
Portico.bindProperty(
|
||
w, spinning, registry: ctx.registry, notifyDetail: "spinning",
|
||
read: { [w] in w.getSpinning() },
|
||
write: { [w] v in w.setSpinning(spinning: v) }
|
||
)
|
||
}
|
||
}
|
||
|
||
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Spinner.setSpinning(spinning:)
|
||
/// Sets the activity of the spinner.
|
||
///
|
||
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Spinner.setSpinning(spinning:)`.
|
||
///
|
||
/// - Parameter spinning: Whether the spinner is spinning
|
||
/// - Returns: A copy of this view with the modifier applied.
|
||
public func spinning(_ spinning: @escaping () -> Bool) -> Self {
|
||
appending { w, ctx in
|
||
let tracker = DependencyTracker { [w] in w.setSpinning(spinning: spinning()) }
|
||
tracker.run()
|
||
ctx.registry.add(tracker)
|
||
}
|
||
}
|
||
|
||
}
|