111 lines
6.1 KiB
Swift
111 lines
6.1 KiB
Swift
// Generated by PorticoGen. DO NOT EDIT. See Sources/PorticoGen to make changes.
|
|
|
|
import Adw
|
|
import Gtk
|
|
import Gio
|
|
import Gdk
|
|
@_spi(Portico) import Portico
|
|
|
|
// PorticoGen: generateStruct | source: Gtk.ShortcutLabel
|
|
/// `GtkShortcutLabel` displays a single keyboard shortcut or gesture.
|
|
///
|
|
/// The main use case for `GtkShortcutLabel` is inside a [class`Gtk`.ShortcutsWindow].
|
|
///
|
|
/// A Portico view that mounts a `Gtk.ShortcutLabel`.
|
|
@MainActor public struct ShortcutLabel: View {
|
|
private let make: (MountContext) -> Gtk.ShortcutLabel
|
|
private var configure: [(Gtk.ShortcutLabel, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Gtk.ShortcutLabel.init(accelerator:)
|
|
/// Creates a new `GtkShortcutLabel` with `accelerator` set.
|
|
///
|
|
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for values that change.
|
|
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
|
|
/// 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 accelerator: The accelerator that `self` displays.
|
|
/// - Parameter disabledText: The text that is displayed when no accelerator is set.
|
|
@_disfavoredOverload
|
|
public init<S: StringProtocol>(accelerator: S, disabledText: String? = nil) {
|
|
make = { _ in Gtk.ShortcutLabel(accelerator: String(accelerator)) }
|
|
configure.append { w, _ in
|
|
if let disabledText { w.setDisabledText(disabledText: disabledText) }
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateInits(binding) | source: Gtk.ShortcutLabel.init(accelerator:), Gtk.ShortcutLabel.setAccelerator(accelerator:)
|
|
/// Creates a new `GtkShortcutLabel` with `accelerator` set.
|
|
///
|
|
/// The initial value is the binding's current value; every later change is pushed into the widget through `Gtk.ShortcutLabel.setAccelerator(accelerator:)` without rebuilding the view.
|
|
/// 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.
|
|
/// Optional `Binding` parameters bind through `Portico.bindProperty`, so they are two-way wherever the wrapper exposes a safe getter.
|
|
///
|
|
/// - Parameter accelerator: The accelerator that `self` displays.
|
|
/// - Parameter disabledText: The text that is displayed when no accelerator is set.
|
|
public init(accelerator: Portico.Binding<String>, disabledText: Portico.Binding<String>? = nil) {
|
|
make = { _ in Gtk.ShortcutLabel(accelerator: accelerator.wrappedValue) }
|
|
configure.append { w, ctx in
|
|
ctx.registry.add(accelerator.subscribe { [w] v in w.setAccelerator(accelerator: v) })
|
|
if let disabledText {
|
|
Portico.bindProperty(w, disabledText, registry: ctx.registry, notifyDetail: "disabled-text", read: { [w] in w.getDisabledText() }, write: { [w] v in w.setDisabledText(disabledText: v) })
|
|
}
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateInits(closure) | source: Gtk.ShortcutLabel.init(accelerator:), Gtk.ShortcutLabel.setAccelerator(accelerator:)
|
|
/// Creates a new `GtkShortcutLabel` with `accelerator` set.
|
|
///
|
|
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.ShortcutLabel.setAccelerator(accelerator:)`.
|
|
/// 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 accelerator: The accelerator that `self` displays.
|
|
/// - Parameter disabledText: The text that is displayed when no accelerator is set.
|
|
public init(accelerator: @escaping () -> String, disabledText: String? = nil) {
|
|
make = { _ in Gtk.ShortcutLabel(accelerator: accelerator()) }
|
|
configure.append { w, ctx in
|
|
let t0 = DependencyTracker { [w] in w.setAccelerator(accelerator: accelerator()) }
|
|
t0.run()
|
|
ctx.registry.add(t0)
|
|
if let disabledText { w.setDisabledText(disabledText: disabledText) }
|
|
}
|
|
}
|
|
|
|
// PorticoGen: generateInits(interpolation) | source: Gtk.ShortcutLabel.init(accelerator:), Gtk.ShortcutLabel.setAccelerator(accelerator:)
|
|
/// Creates a new `GtkShortcutLabel` with `accelerator` set.
|
|
///
|
|
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.ShortcutLabel.setAccelerator(accelerator:)`. A literal with no interpolation is applied once, with no subscription.
|
|
/// 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 accelerator: The accelerator that `self` displays.
|
|
/// - Parameter disabledText: The text that is displayed when no accelerator is set.
|
|
public init(accelerator: Portico.InterpolatedText, disabledText: String? = nil) {
|
|
make = { _ in Gtk.ShortcutLabel(accelerator: accelerator.untrackedText) }
|
|
configure.append { w, ctx in
|
|
Portico.bindInterpolation(accelerator, registry: ctx.registry) { [w] v in w.setAccelerator(accelerator: v) }
|
|
if let disabledText { w.setDisabledText(disabledText: disabledText) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension ShortcutLabel: WidgetView {
|
|
public typealias Target = Gtk.ShortcutLabel
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Gtk.ShortcutLabel, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension ShortcutLabel: Mountable {
|
|
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
|
|
let w = make(ctx)
|
|
for step in configure { step(w, ctx) }
|
|
return w
|
|
}
|
|
}
|