portico/Sources/Portico/Generated/ScaleButton.swift

300 lines
14 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Generated by PorticoGen. DO NOT EDIT. See Sources/PorticoGen to make changes.
import Adw
import Gtk
import Gio
import Gdk
// PorticoGen: generateStruct | source: Gtk.ScaleButton
/// Provides a button which pops up a scale widget.
///
/// This kind of widget is commonly used for volume controls in multimedia
/// applications, and GTK provides a [class`Gtk`.VolumeButton] subclass that
/// is tailored for this use case.
///
/// # Shortcuts and Gestures
///
/// The following signals have default keybindings:
///
/// - [signal`Gtk`.ScaleButton::popup]
///
/// # CSS nodes
///
/// ```
/// scalebutton.scale
/// button.toggle
/// <icon>
/// ```
///
/// `GtkScaleButton` has a single CSS node with name scalebutton and `.scale`
/// style class, and contains a `button` node with a `.toggle` style class.
///
/// A Portico view that mounts a `Gtk.ScaleButton`.
@MainActor public struct ScaleButton: View {
private let make: (MountContext) -> Gtk.ScaleButton
private var configure: [(Gtk.ScaleButton, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.ScaleButton.init(min:max:step:icons:)
/// Creates a `GtkScaleButton`.
///
/// The new scale button has a range between `min` and `max`,
/// with a stepping of `step`.
///
/// 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.ScaleButton`.
/// - Parameter max: The `max` value forwarded to `Gtk.ScaleButton`.
/// - Parameter step: The `step` value forwarded to `Gtk.ScaleButton`.
/// - Parameter icons: Sets the icons to be used by the scale button.
/// - Parameter adjustment: The `GtkAdjustment` that is used as the model.
/// - Parameter hasFrame: If the scale button has a frame.
/// - Parameter value: The value of the scale.
/// - Parameter onPopdown: Invoked when the widget emits the `popdown` signal.
/// - Parameter onPopup: Invoked when the widget emits the `popup` signal.
/// - Parameter onValueChanged: Invoked when the widget emits the `value-changed` signal. The closure receives the signal's arguments in order.
public init(min: Double, max: Double, step: Double, icons: [String], adjustment: Gtk.Adjustment? = nil, hasFrame: Bool? = nil, value: Double? = nil, onPopdown: (() -> Void)? = nil, onPopup: (() -> Void)? = nil, onValueChanged: ((Double) -> Void)? = nil) {
make = { _ in Gtk.ScaleButton(min: min, max: max, step: step, icons: icons) }
configure.append { w, ctx in
if let adjustment { w.setAdjustment(adjustment: adjustment) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let value { w.setValue(value: value) }
if let onPopdown { ctx.registry.add(w.connectPopdown { _ in onPopdown() }) }
if let onPopup { ctx.registry.add(w.connectPopup { _ in onPopup() }) }
if let onValueChanged { ctx.registry.add(w.connectValueChanged { _, a0 in onValueChanged(a0) }) }
}
}
}
extension ScaleButton: WidgetView {
public typealias Target = Gtk.ScaleButton
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.ScaleButton, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension ScaleButton: 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.ScaleButton
/// Modifiers for `Gtk.ScaleButton`, available on every Portico view whose
/// backing widget is `Gtk.ScaleButton` or one of its subclasses.
extension WidgetView where Target: Gtk.ScaleButton {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.ScaleButton.setAdjustment(adjustment:)
/// Sets the `GtkAdjustment` to be used as a model
/// for the `GtkScaleButton`s scale.
///
/// See [method`Gtk`.Range.set_adjustment] for details.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter adjustment: The `GtkAdjustment` that is used as the model.
/// - 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.ScaleButton.setAdjustment(adjustment:), GObject.Object.connectNotify(detail:_:), Gtk.ScaleButton.getAdjustment()
/// Sets the `GtkAdjustment` to be used as a model
/// for the `GtkScaleButton`s scale.
///
/// See [method`Gtk`.Range.set_adjustment] for details.
///
/// 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.ScaleButton.setAdjustment(adjustment:)
/// Sets the `GtkAdjustment` to be used as a model
/// for the `GtkScaleButton`s scale.
///
/// See [method`Gtk`.Range.set_adjustment] for details.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.ScaleButton.setAdjustment(adjustment:)`.
///
/// - Parameter adjustment: The `GtkAdjustment` that is used as the model.
/// - 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.ScaleButton.setHasFrame(hasFrame:)
/// Sets the style of the button.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter hasFrame: If the scale button has a frame.
/// - Returns: A copy of this view with the modifier applied.
public func hasFrame(_ hasFrame: Bool) -> Self {
appending { w, _ in
w.setHasFrame(hasFrame: hasFrame)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.ScaleButton.setHasFrame(hasFrame:), GObject.Object.connectNotify(detail:_:), Gtk.ScaleButton.getHasFrame()
/// Sets the style of the 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 hasFrame(_ hasFrame: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, hasFrame, registry: ctx.registry, notifyDetail: "has-frame",
read: { [w] in w.getHasFrame() },
write: { [w] v in w.setHasFrame(hasFrame: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.ScaleButton.setHasFrame(hasFrame:)
/// Sets the style of the button.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.ScaleButton.setHasFrame(hasFrame:)`.
///
/// - Parameter hasFrame: If the scale button has a frame.
/// - Returns: A copy of this view with the modifier applied.
public func hasFrame(_ hasFrame: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setHasFrame(hasFrame: hasFrame()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.ScaleButton.setValue(value:)
/// Sets the current value of the scale.
///
/// If the value is outside the minimum or maximum range values,
/// it will be clamped to fit inside them.
///
/// The scale button emits the [signal`Gtk`.ScaleButton::value-changed]
/// signal if the value changes.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter value: The value of the scale.
/// - 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.ScaleButton.setValue(value:), GObject.Object.connectNotify(detail:_:), Gtk.ScaleButton.getValue()
/// Sets the current value of the scale.
///
/// If the value is outside the minimum or maximum range values,
/// it will be clamped to fit inside them.
///
/// The scale button emits the [signal`Gtk`.ScaleButton::value-changed]
/// signal if the value changes.
///
/// 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.ScaleButton.setValue(value:)
/// Sets the current value of the scale.
///
/// If the value is outside the minimum or maximum range values,
/// it will be clamped to fit inside them.
///
/// The scale button emits the [signal`Gtk`.ScaleButton::value-changed]
/// signal if the value changes.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.ScaleButton.setValue(value:)`.
///
/// - Parameter value: The value of the scale.
/// - 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 -> generateSignalModifier | source: Gtk.ScaleButton.connectPopdown(_:)
/// Emitted to dismiss the popup.
///
/// This is a [keybinding signal](class.SignalAction.html).
///
/// The default binding for this signal is <kbd>Escape</kbd>.
///
/// - Parameter handler: Invoked when the widget emits the `popdown` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onPopdown(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectPopdown { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.ScaleButton.connectPopup(_:)
/// Emitted to popup the scale widget.
///
/// This is a [keybinding signal](class.SignalAction.html).
///
/// The default bindings for this signal are <kbd>Space</kbd>,
/// <kbd>Enter</kbd> and <kbd>Return</kbd>.
///
/// - Parameter handler: Invoked when the widget emits the `popup` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onPopup(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectPopup { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.ScaleButton.connectValueChanged(_:)
/// Emitted when the value field has changed.
///
/// - Parameter handler: Invoked when the widget emits the `value-changed` signal. The closure receives the signal's arguments in order.
/// - Returns: A copy of this view with the modifier applied.
public func onValueChanged(_ handler: @escaping (Double) -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectValueChanged { _, a0 in handler(a0) })
}
}
}