portico/Sources/Portico/Generated/SpinButton.swift

807 lines
42 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: Gtk.SpinButton
/// Allows to enter or change numeric values.
///
/// <picture>
/// <source srcset="spinbutton-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkSpinButton" src="spinbutton.png">
/// </picture>
///
/// Rather than having to directly type a number into a `GtkEntry`,
/// `GtkSpinButton` allows the user to click on one of two arrows
/// to increment or decrement the displayed value. A value can still be
/// typed in, with the bonus that it can be checked to ensure it is in a
/// given range.
///
/// The main properties of a `GtkSpinButton` are through an adjustment.
/// See the [class`Gtk`.Adjustment] documentation for more details about
/// an adjustment's properties.
///
/// Note that `GtkSpinButton` will by default make its entry large enough
/// to accommodate the lower and upper bounds of the adjustment. If this
/// is not desired, the automatic sizing can be turned off by explicitly
/// setting [property`Gtk`.Editable:width-chars] to a value != -1.
///
/// ## Using a GtkSpinButton to get an integer
///
/// ```c
/// // Provides a function to retrieve an integer value from a GtkSpinButton
/// // and creates a spin button to model percentage values.
///
/// int
/// grab_int_value (GtkSpinButton *button,
/// gpointer user_data)
/// {
/// return gtk_spin_button_get_value_as_int (button);
/// }
///
/// void
/// create_integer_spin_button (void)
/// {
///
/// GtkWidget *window, *button;
/// GtkAdjustment *adjustment;
///
/// adjustment = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 0.0);
///
/// window = gtk_window_new ();
///
/// // creates the spinbutton, with no decimal places
/// button = gtk_spin_button_new (adjustment, 1.0, 0);
/// gtk_window_set_child (GTK_WINDOW (window), button);
///
/// gtk_window_present (GTK_WINDOW (window));
/// }
/// ```
///
/// ## Using a GtkSpinButton to get a floating point value
///
/// ```c
/// // Provides a function to retrieve a floating point value from a
/// // GtkSpinButton, and creates a high precision spin button.
///
/// float
/// grab_float_value (GtkSpinButton *button,
/// gpointer user_data)
/// {
/// return gtk_spin_button_get_value (button);
/// }
///
/// void
/// create_floating_spin_button (void)
/// {
/// GtkWidget *window, *button;
/// GtkAdjustment *adjustment;
///
/// adjustment = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0);
///
/// window = gtk_window_new ();
///
/// // creates the spinbutton, with three decimal places
/// button = gtk_spin_button_new (adjustment, 0.001, 3);
/// gtk_window_set_child (GTK_WINDOW (window), button);
///
/// gtk_window_present (GTK_WINDOW (window));
/// }
/// ```
///
/// # Shortcuts and Gestures
///
/// The following signals have default keybindings:
///
/// - [signal`Gtk`.SpinButton::change-value]
///
/// # CSS nodes
///
/// ```
/// spinbutton.horizontal
/// text
/// undershoot.left
/// undershoot.right
/// button.down
/// button.up
/// ```
///
/// ```
/// spinbutton.vertical
/// button.up
/// text
/// undershoot.left
/// undershoot.right
/// button.down
/// ```
///
/// `GtkSpinButton`s main CSS node has the name spinbutton. It creates subnodes
/// for the entry and the two buttons, with these names. The button nodes have
/// the style classes .up and .down. The `GtkText` subnodes (if present) are put
/// below the text node. The orientation of the spin button is reflected in
/// the .vertical or .horizontal style class on the main node.
///
/// # Accessibility
///
/// `GtkSpinButton` uses the [enum`Gtk`.AccessibleRole.spin_button] role.
///
/// A Portico view that mounts a `Gtk.SpinButton`.
@MainActor public struct SpinButton: View {
private let make: (MountContext) -> Gtk.SpinButton
private var configure: [(Gtk.SpinButton, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.SpinButton.init(adjustment:climbRate:digits:)
/// Creates a new `GtkSpinButton`.
///
/// 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 adjustment: The adjustment that holds the value of the spin button.
/// - Parameter climbRate: The acceleration rate when you hold down a button or key.
/// - Parameter digits: The number of decimal places to display.
/// - Parameter activatesDefault: Whether to activate the default widget when the spin button is activated.
/// - Parameter numeric: Whether non-numeric characters should be ignored.
/// - Parameter snapToTicks: Whether erroneous values are automatically changed to the spin buttons nearest step increment.
/// - Parameter updatePolicy: Whether the spin button should update always, or only when the value is acceptable.
/// - Parameter value: The current value.
/// - Parameter wrap: Whether a spin button should wrap upon reaching its limits.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onChangeValue: Invoked when the widget emits the `change-value` signal. The closure receives the signal's arguments in order.
/// - Parameter onInput: Invoked when the widget emits the `input` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onOutput: Invoked when the widget emits the `output` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onValueChanged: Invoked when the widget emits the `value-changed` signal.
/// - Parameter onWrapped: Invoked when the widget emits the `wrapped` signal.
public init(adjustment: Gtk.Adjustment?, climbRate: Double, digits: UInt32, activatesDefault: Bool? = nil, numeric: Bool? = nil, snapToTicks: Bool? = nil, updatePolicy: Gtk.SpinButtonUpdatePolicy? = nil, value: Double? = nil, wrap: Bool? = nil, onActivate: (() -> Void)? = nil, onChangeValue: ((Gtk.ScrollType) -> Void)? = nil, onInput: ((Double) -> Int32)? = nil, onOutput: (() -> Bool)? = nil, onValueChanged: (() -> Void)? = nil, onWrapped: (() -> Void)? = nil) {
make = { _ in Gtk.SpinButton(adjustment: adjustment, climbRate: climbRate, digits: digits) }
configure.append { w, ctx in
if let activatesDefault { w.setActivatesDefault(activatesDefault: activatesDefault) }
if let numeric { w.setNumeric(numeric: numeric) }
if let snapToTicks { w.setSnapToTicks(snapToTicks: snapToTicks) }
if let updatePolicy { w.setUpdatePolicy(policy: updatePolicy) }
if let value { w.setValue(value: value) }
if let wrap { w.setWrap(wrap: wrap) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onChangeValue { ctx.registry.add(w.connectChangeValue { _, a0 in onChangeValue(a0) }) }
if let onInput { ctx.registry.add(w.connectInput { _, a0 in onInput(a0) }) }
if let onOutput { ctx.registry.add(w.connectOutput { _ in onOutput() }) }
if let onValueChanged { ctx.registry.add(w.connectValueChanged { _ in onValueChanged() }) }
if let onWrapped { ctx.registry.add(w.connectWrapped { _ in onWrapped() }) }
}
}
// PorticoGen: generateInits(static) | source: Gtk.SpinButton.init(min:max:step:)
/// Creates a new `GtkSpinButton` with the given properties.
///
/// This is a convenience constructor that allows creation
/// of a numeric `GtkSpinButton` without manually creating
/// an adjustment. The value is initially set to the minimum
/// value and a page increment of 10 * `step` is the default.
/// The precision of the spin button is equivalent to the
/// precision of `step`.
///
/// Note that the way in which the precision is derived works
/// best if `step` is a power of ten. If the resulting precision
/// is not suitable for your needs, use
/// [method`Gtk`.SpinButton.set_digits] to correct it.
///
/// 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 min: The `min` value forwarded to `Gtk.SpinButton`.
/// - Parameter max: The `max` value forwarded to `Gtk.SpinButton`.
/// - Parameter step: The `step` value forwarded to `Gtk.SpinButton`.
/// - Parameter activatesDefault: Whether to activate the default widget when the spin button is activated.
/// - Parameter numeric: Whether non-numeric characters should be ignored.
/// - Parameter snapToTicks: Whether erroneous values are automatically changed to the spin buttons nearest step increment.
/// - Parameter updatePolicy: Whether the spin button should update always, or only when the value is acceptable.
/// - Parameter value: The current value.
/// - Parameter wrap: Whether a spin button should wrap upon reaching its limits.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onChangeValue: Invoked when the widget emits the `change-value` signal. The closure receives the signal's arguments in order.
/// - Parameter onInput: Invoked when the widget emits the `input` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onOutput: Invoked when the widget emits the `output` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onValueChanged: Invoked when the widget emits the `value-changed` signal.
/// - Parameter onWrapped: Invoked when the widget emits the `wrapped` signal.
public init(min: Double, max: Double, step: Double, activatesDefault: Bool? = nil, numeric: Bool? = nil, snapToTicks: Bool? = nil, updatePolicy: Gtk.SpinButtonUpdatePolicy? = nil, value: Double? = nil, wrap: Bool? = nil, onActivate: (() -> Void)? = nil, onChangeValue: ((Gtk.ScrollType) -> Void)? = nil, onInput: ((Double) -> Int32)? = nil, onOutput: (() -> Bool)? = nil, onValueChanged: (() -> Void)? = nil, onWrapped: (() -> Void)? = nil) {
make = { _ in Gtk.SpinButton(min: min, max: max, step: step) }
configure.append { w, ctx in
if let activatesDefault { w.setActivatesDefault(activatesDefault: activatesDefault) }
if let numeric { w.setNumeric(numeric: numeric) }
if let snapToTicks { w.setSnapToTicks(snapToTicks: snapToTicks) }
if let updatePolicy { w.setUpdatePolicy(policy: updatePolicy) }
if let value { w.setValue(value: value) }
if let wrap { w.setWrap(wrap: wrap) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onChangeValue { ctx.registry.add(w.connectChangeValue { _, a0 in onChangeValue(a0) }) }
if let onInput { ctx.registry.add(w.connectInput { _, a0 in onInput(a0) }) }
if let onOutput { ctx.registry.add(w.connectOutput { _ in onOutput() }) }
if let onValueChanged { ctx.registry.add(w.connectValueChanged { _ in onValueChanged() }) }
if let onWrapped { ctx.registry.add(w.connectWrapped { _ in onWrapped() }) }
}
}
}
extension SpinButton: WidgetView {
public typealias Target = Gtk.SpinButton
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.SpinButton, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension SpinButton: 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.SpinButton
/// Modifiers for `Gtk.SpinButton`, available on every Portico view whose
/// backing widget is `Gtk.SpinButton` or one of its subclasses.
extension WidgetView where Target: Gtk.SpinButton {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setActivatesDefault(activatesDefault:)
/// Sets whether activating the spin button will activate the default
/// widget for the window containing the spin button.
///
/// See [signal`Gtk`.SpinButton::activate] for what counts as activation.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter activatesDefault: Whether to activate the default widget when the spin button is activated.
/// - Returns: A copy of this view with the modifier applied.
public func activatesDefault(_ activatesDefault: Bool) -> Self {
appending { w, _ in
w.setActivatesDefault(activatesDefault: activatesDefault)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setActivatesDefault(activatesDefault:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getActivatesDefault()
/// Sets whether activating the spin button will activate the default
/// widget for the window containing the spin button.
///
/// See [signal`Gtk`.SpinButton::activate] for what counts as activation.
///
/// 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 activatesDefault(_ activatesDefault: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, activatesDefault, registry: ctx.registry, notifyDetail: "activates-default",
read: { [w] in w.getActivatesDefault() },
write: { [w] v in w.setActivatesDefault(activatesDefault: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setActivatesDefault(activatesDefault:)
/// Sets whether activating the spin button will activate the default
/// widget for the window containing the spin button.
///
/// See [signal`Gtk`.SpinButton::activate] for what counts as activation.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setActivatesDefault(activatesDefault:)`.
///
/// - Parameter activatesDefault: Whether to activate the default widget when the spin button is activated.
/// - Returns: A copy of this view with the modifier applied.
public func activatesDefault(_ activatesDefault: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setActivatesDefault(activatesDefault: activatesDefault()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setAdjustment(adjustment:)
/// Replaces the `GtkAdjustment` associated with `spin_button`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter adjustment: The adjustment that holds the value of the spin button.
/// - Returns: A copy of this view with the modifier applied.
public func adjustment(_ adjustment: Gtk.Adjustment) -> Self {
appending { w, _ in
w.setAdjustment(adjustment: adjustment)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setAdjustment(adjustment:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getAdjustment()
/// Replaces the `GtkAdjustment` associated with `spin_button`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.Adjustment` 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 adjustment(_ adjustment: Portico.Binding<Gtk.Adjustment>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, adjustment, registry: ctx.registry, notifyDetail: "adjustment",
read: { [w] in w.getAdjustment() },
write: { [w] v in w.setAdjustment(adjustment: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setAdjustment(adjustment:)
/// Replaces the `GtkAdjustment` associated with `spin_button`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setAdjustment(adjustment:)`.
///
/// - Parameter adjustment: The adjustment that holds the value of the spin button.
/// - Returns: A copy of this view with the modifier applied.
public func adjustment(_ adjustment: @escaping () -> Gtk.Adjustment) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setAdjustment(adjustment: adjustment()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setClimbRate(climbRate:)
/// Sets the acceleration rate for repeated changes when you
/// hold down a button or key.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter climbRate: The acceleration rate when you hold down a button or key.
/// - Returns: A copy of this view with the modifier applied.
public func climbRate(_ climbRate: Double) -> Self {
appending { w, _ in
w.setClimbRate(climbRate: climbRate)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setClimbRate(climbRate:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getClimbRate()
/// Sets the acceleration rate for repeated changes when you
/// hold down a button or key.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Double` 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 climbRate(_ climbRate: Portico.Binding<Double>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, climbRate, registry: ctx.registry, notifyDetail: "climb-rate",
read: { [w] in w.getClimbRate() },
write: { [w] v in w.setClimbRate(climbRate: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setClimbRate(climbRate:)
/// Sets the acceleration rate for repeated changes when you
/// hold down a button or key.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setClimbRate(climbRate:)`.
///
/// - Parameter climbRate: The acceleration rate when you hold down a button or key.
/// - Returns: A copy of this view with the modifier applied.
public func climbRate(_ climbRate: @escaping () -> Double) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setClimbRate(climbRate: climbRate()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setDigits(digits:)
/// Set the precision to be displayed by `spin_button`.
///
/// Up to 20 digit precision is allowed.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter digits: The number of decimal places to display.
/// - Returns: A copy of this view with the modifier applied.
public func digits(_ digits: UInt32) -> Self {
appending { w, _ in
w.setDigits(digits: digits)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setDigits(digits:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getDigits()
/// Set the precision to be displayed by `spin_button`.
///
/// Up to 20 digit precision is allowed.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `UInt32` 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 digits(_ digits: Portico.Binding<UInt32>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, digits, registry: ctx.registry, notifyDetail: "digits",
read: { [w] in w.getDigits() },
write: { [w] v in w.setDigits(digits: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setDigits(digits:)
/// Set the precision to be displayed by `spin_button`.
///
/// Up to 20 digit precision is allowed.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setDigits(digits:)`.
///
/// - Parameter digits: The number of decimal places to display.
/// - Returns: A copy of this view with the modifier applied.
public func digits(_ digits: @escaping () -> UInt32) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setDigits(digits: digits()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setNumeric(numeric:)
/// Sets the flag that determines if non-numeric text can be typed
/// into the spin button.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter numeric: Whether non-numeric characters should be ignored.
/// - Returns: A copy of this view with the modifier applied.
public func numeric(_ numeric: Bool) -> Self {
appending { w, _ in
w.setNumeric(numeric: numeric)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setNumeric(numeric:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getNumeric()
/// Sets the flag that determines if non-numeric text can be typed
/// into the spin button.
///
/// 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 numeric(_ numeric: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, numeric, registry: ctx.registry, notifyDetail: "numeric",
read: { [w] in w.getNumeric() },
write: { [w] v in w.setNumeric(numeric: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setNumeric(numeric:)
/// Sets the flag that determines if non-numeric text can be typed
/// into the spin button.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setNumeric(numeric:)`.
///
/// - Parameter numeric: Whether non-numeric characters should be ignored.
/// - Returns: A copy of this view with the modifier applied.
public func numeric(_ numeric: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setNumeric(numeric: numeric()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setSnapToTicks(snapToTicks:)
/// Sets the policy as to whether values are corrected to the
/// nearest step increment when a spin button is activated after
/// providing an invalid value.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter snapToTicks: Whether erroneous values are automatically changed to the spin buttons nearest step increment.
/// - Returns: A copy of this view with the modifier applied.
public func snapToTicks(_ snapToTicks: Bool) -> Self {
appending { w, _ in
w.setSnapToTicks(snapToTicks: snapToTicks)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setSnapToTicks(snapToTicks:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getSnapToTicks()
/// Sets the policy as to whether values are corrected to the
/// nearest step increment when a spin button is activated after
/// providing an invalid value.
///
/// 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 snapToTicks(_ snapToTicks: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, snapToTicks, registry: ctx.registry, notifyDetail: "snap-to-ticks",
read: { [w] in w.getSnapToTicks() },
write: { [w] v in w.setSnapToTicks(snapToTicks: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setSnapToTicks(snapToTicks:)
/// Sets the policy as to whether values are corrected to the
/// nearest step increment when a spin button is activated after
/// providing an invalid value.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setSnapToTicks(snapToTicks:)`.
///
/// - Parameter snapToTicks: Whether erroneous values are automatically changed to the spin buttons nearest step increment.
/// - Returns: A copy of this view with the modifier applied.
public func snapToTicks(_ snapToTicks: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setSnapToTicks(snapToTicks: snapToTicks()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setUpdatePolicy(policy:)
/// Sets the update behavior of a spin button.
///
/// This determines whether the spin button is always
/// updated or only when a valid value is set.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter updatePolicy: Whether the spin button should update always, or only when the value is acceptable.
/// - Returns: A copy of this view with the modifier applied.
public func updatePolicy(_ updatePolicy: Gtk.SpinButtonUpdatePolicy) -> Self {
appending { w, _ in
w.setUpdatePolicy(policy: updatePolicy)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setUpdatePolicy(policy:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getUpdatePolicy()
/// Sets the update behavior of a spin button.
///
/// This determines whether the spin button is always
/// updated or only when a valid value is set.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.SpinButtonUpdatePolicy` 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 updatePolicy(_ updatePolicy: Portico.Binding<Gtk.SpinButtonUpdatePolicy>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, updatePolicy, registry: ctx.registry, notifyDetail: "update-policy",
read: { [w] in w.getUpdatePolicy() },
write: { [w] v in w.setUpdatePolicy(policy: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setUpdatePolicy(policy:)
/// Sets the update behavior of a spin button.
///
/// This determines whether the spin button is always
/// updated or only when a valid value is set.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setUpdatePolicy(policy:)`.
///
/// - Parameter updatePolicy: Whether the spin button should update always, or only when the value is acceptable.
/// - Returns: A copy of this view with the modifier applied.
public func updatePolicy(_ updatePolicy: @escaping () -> Gtk.SpinButtonUpdatePolicy) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setUpdatePolicy(policy: updatePolicy()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setValue(value:)
/// Sets the value of `spin_button`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter value: The current value.
/// - Returns: A copy of this view with the modifier applied.
public func value(_ value: Double) -> Self {
appending { w, _ in
w.setValue(value: value)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setValue(value:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getValue()
/// Sets the value of `spin_button`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Double` 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 value(_ value: Portico.Binding<Double>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, value, registry: ctx.registry, notifyDetail: "value",
read: { [w] in w.getValue() },
write: { [w] v in w.setValue(value: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setValue(value:)
/// Sets the value of `spin_button`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setValue(value:)`.
///
/// - Parameter value: The current value.
/// - Returns: A copy of this view with the modifier applied.
public func value(_ value: @escaping () -> Double) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setValue(value: value()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SpinButton.setWrap(wrap:)
/// Sets the flag that determines if a spin button value wraps
/// around to the opposite limit when the upper or lower limit
/// of the range is exceeded.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter wrap: Whether a spin button should wrap upon reaching its limits.
/// - Returns: A copy of this view with the modifier applied.
public func wrap(_ wrap: Bool) -> Self {
appending { w, _ in
w.setWrap(wrap: wrap)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SpinButton.setWrap(wrap:), GObject.Object.connectNotify(detail:_:), Gtk.SpinButton.getWrap()
/// Sets the flag that determines if a spin button value wraps
/// around to the opposite limit when the upper or lower limit
/// of the range is exceeded.
///
/// 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 wrap(_ wrap: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, wrap, registry: ctx.registry, notifyDetail: "wrap",
read: { [w] in w.getWrap() },
write: { [w] v in w.setWrap(wrap: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SpinButton.setWrap(wrap:)
/// Sets the flag that determines if a spin button value wraps
/// around to the opposite limit when the upper or lower limit
/// of the range is exceeded.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SpinButton.setWrap(wrap:)`.
///
/// - Parameter wrap: Whether a spin button should wrap upon reaching its limits.
/// - Returns: A copy of this view with the modifier applied.
public func wrap(_ wrap: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setWrap(wrap: wrap()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.SpinButton.connectActivate(_:)
/// Emitted when the spin button is activated.
///
/// The keybindings for this signal are all forms of the <kbd>Enter</kbd> key.
///
/// If the <kbd>Enter</kbd> key results in the value being committed to the
/// spin button, then activation does not occur until <kbd>Enter</kbd> is
/// pressed again.
///
/// - Parameter handler: Invoked when the widget emits the `activate` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onActivate(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectActivate { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.SpinButton.connectChangeValue(_:)
/// Emitted when the user initiates a value change.
///
/// This is a [keybinding signal](class.SignalAction.html).
///
/// Applications should not connect to it, but may emit it with
/// g_signal_emit_by_name() if they need to control the cursor
/// programmatically.
///
/// The default bindings for this signal are Up/Down and PageUp/PageDown.
///
/// - Parameter handler: Invoked when the widget emits the `change-value` signal. The closure receives the signal's arguments in order.
/// - Returns: A copy of this view with the modifier applied.
public func onChangeValue(_ handler: @escaping (Gtk.ScrollType) -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectChangeValue { _, a0 in handler(a0) })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.SpinButton.connectInput(_:)
/// Emitted to convert the users input into a double value.
///
/// The signal handler is expected to use [method`Gtk`.Editable.get_text]
/// to retrieve the text of the spinbutton and set `new_value` to the
/// new value.
///
/// The default conversion uses g_strtod().
///
/// - Parameter handler: Invoked when the widget emits the `input` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
/// - Returns: A copy of this view with the modifier applied.
public func onInput(_ handler: @escaping (Double) -> Int32) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectInput { _, a0 in handler(a0) })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.SpinButton.connectOutput(_:)
/// Emitted to tweak the formatting of the value for display.
///
/// ```c
/// // show leading zeros
/// static gboolean
/// on_output (GtkSpinButton *spin,
/// gpointer data)
/// {
/// char *text;
/// int value;
///
/// value = gtk_spin_button_get_value_as_int (spin);
/// text = g_strdup_printf ("%02d", value);
/// gtk_editable_set_text (GTK_EDITABLE (spin), text):
/// g_free (text);
///
/// return TRUE;
/// }
/// ```
///
/// - Parameter handler: Invoked when the widget emits the `output` signal. Its return value is forwarded to GTK as the signal's result.
/// - Returns: A copy of this view with the modifier applied.
public func onOutput(_ handler: @escaping () -> Bool) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectOutput { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.SpinButton.connectValueChanged(_:)
/// Emitted when the value is changed.
///
/// Also see the [signal`Gtk`.SpinButton::output] signal.
///
/// - Parameter handler: Invoked when the widget emits the `value-changed` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onValueChanged(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectValueChanged { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.SpinButton.connectWrapped(_:)
/// Emitted right after the spinbutton wraps from its maximum
/// to its minimum value or vice-versa.
///
/// - Parameter handler: Invoked when the widget emits the `wrapped` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onWrapped(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectWrapped { _ in handler() })
}
}
}