105 lines
3.3 KiB
Swift

//
// Spinner.swift
// Adwaita
//
// Created by auto-generation on 03.08.24.
//
import CAdw
import LevenshteinTransformations
/// A `GtkSpinner` widget displays an icon-size spinning animation.
///
/// It is often used as an alternative to a [class@Gtk.ProgressBar]
/// for displaying indefinite activity, instead of actual progress.
///
/// ![An example GtkSpinner](spinner.png)
///
/// To start the animation, use [method@Gtk.Spinner.start], to stop it
/// use [method@Gtk.Spinner.stop].
///
/// # CSS nodes
///
/// `GtkSpinner` has a single CSS node with the name spinner.
/// When the animation is active, the :checked pseudoclass is
/// added to this node.
public struct Spinner: AdwaitaWidget {
/// Additional update functions for type extensions.
var updateFunctions: [(ViewStorage, [(AnyView) -> AnyView], Bool) -> Void] = []
/// Additional appear functions for type extensions.
var appearFunctions: [(ViewStorage, [(AnyView) -> AnyView]) -> Void] = []
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
var accessibleRole: String?
/// Whether the spinner is spinning
var spinning: Bool?
/// The application.
var app: AdwaitaApp?
/// The window.
var window: AdwaitaWindow?
/// Initialize `Spinner`.
public init() {
}
/// The view storage.
/// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The type of the app storage.
/// - Returns: The view storage.
public func container<Data>(modifiers: [(AnyView) -> AnyView], type: Data.Type) -> ViewStorage where Data: ViewRenderData {
let storage = ViewStorage(gtk_spinner_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true, type: type)
return storage
}
/// Update the stored content.
/// - Parameters:
/// - storage: The storage to update.
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The type of the app storage.
public func update<Data>(_ storage: ViewStorage, modifiers: [(AnyView) -> AnyView], updateProperties: Bool, type: Data.Type) where Data: ViewRenderData {
storage.modify { widget in
if let spinning, updateProperties, (storage.previousState as? Self)?.spinning != spinning {
gtk_spinner_set_spinning(widget, spinning.cBool)
}
}
for function in updateFunctions {
function(storage, modifiers, updateProperties)
}
if updateProperties {
storage.previousState = self
}
}
/// The accessible role of the given `GtkAccessible` implementation.
///
/// The accessible role cannot be changed once set.
public func accessibleRole(_ accessibleRole: String?) -> Self {
var newSelf = self
newSelf.accessibleRole = accessibleRole
return newSelf
}
/// Whether the spinner is spinning
public func spinning(_ spinning: Bool? = true) -> Self {
var newSelf = self
newSelf.spinning = spinning
return newSelf
}
}