portico/Sources/Portico/Generated/Button.swift

842 lines
52 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.Button
/// Calls a callback function when the button is clicked.
///
/// <picture>
/// <source srcset="button-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkButton" src="button.png">
/// </picture>
///
/// The `GtkButton` widget can hold any valid child widget. That is, it can hold
/// almost any other standard `GtkWidget`. The most commonly used child is the
/// `GtkLabel`.
///
/// # Shortcuts and Gestures
///
/// The following signals have default keybindings:
///
/// - [signal`Gtk`.Button::activate]
///
/// # CSS nodes
///
/// `GtkButton` has a single CSS node with name button. The node will get the
/// style classes .image-button or .text-button, if the content is just an
/// image or label, respectively. It may also receive the .flat style class.
/// When activating a button via the keyboard, the button will temporarily
/// gain the .keyboard-activating style class.
///
/// Other style classes that are commonly used with `GtkButton` include
/// .suggested-action and .destructive-action. In special cases, buttons
/// can be made round by adding the .circular style class.
///
/// Button-like widgets like [class`Gtk`.ToggleButton], [class`Gtk`.MenuButton],
/// [class`Gtk`.VolumeButton], [class`Gtk`.LockButton], [class`Gtk`.ColorButton]
/// or [class`Gtk`.FontButton] use style classes such as .toggle, .popup, .scale,
/// .lock, .color on the button node to differentiate themselves from a plain
/// `GtkButton`.
///
/// # Accessibility
///
/// `GtkButton` uses the [enum`Gtk`.AccessibleRole.button] role.
///
/// A Portico view that mounts a `Gtk.Button`.
@MainActor public struct Button: View {
private let make: (MountContext) -> Gtk.Button
private var configure: [(Gtk.Button, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.Button.init()
/// Creates a new `GtkButton` widget.
///
/// To add a child widget to the button, use [method`Gtk`.Button.set_child].
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(canShrink: Bool? = nil, hasFrame: Bool? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button() }
configure.append { w, ctx in
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(static) | source: Gtk.Button.init(iconName:)
/// Creates a new button containing an icon from the current icon theme.
///
/// If the icon name isnt known, a broken image icon will be
/// displayed instead. If the current icon theme is changed, the icon
/// will be updated appropriately.
///
/// 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.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 iconName: The name of the icon used to automatically populate the button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
@_disfavoredOverload
public init<S: StringProtocol>(iconName: S, canShrink: Bool? = nil, hasFrame: Bool? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(iconName: String(iconName)) }
configure.append { w, ctx in
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(binding) | source: Gtk.Button.init(iconName:), Gtk.Button.setIconName(iconName:)
/// Creates a new button containing an icon from the current icon theme.
///
/// If the icon name isnt known, a broken image icon will be
/// displayed instead. If the current icon theme is changed, the icon
/// will be updated appropriately.
///
/// The initial value is the binding's current value; every later change is pushed into the widget through `Gtk.Button.setIconName(iconName:)` without rebuilding the view.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 iconName: The name of the icon used to automatically populate the button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(iconName: Portico.Binding<String>, canShrink: Portico.Binding<Bool>? = nil, hasFrame: Portico.Binding<Bool>? = nil, useUnderline: Portico.Binding<Bool>? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(iconName: iconName.wrappedValue) }
configure.append { w, ctx in
ctx.registry.add(iconName.subscribe { [w] v in w.setIconName(iconName: v) })
if let canShrink {
Portico.bindProperty(w, canShrink, registry: ctx.registry, notifyDetail: "can-shrink", read: { [w] in w.getCanShrink() }, write: { [w] v in w.setCanShrink(canShrink: v) })
}
if let hasFrame {
Portico.bindProperty(w, hasFrame, registry: ctx.registry, notifyDetail: "has-frame", read: { [w] in w.getHasFrame() }, write: { [w] v in w.setHasFrame(hasFrame: v) })
}
if let useUnderline {
Portico.bindProperty(w, useUnderline, registry: ctx.registry, notifyDetail: "use-underline", read: { [w] in w.getUseUnderline() }, write: { [w] v in w.setUseUnderline(useUnderline: v) })
}
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(closure) | source: Gtk.Button.init(iconName:), Gtk.Button.setIconName(iconName:)
/// Creates a new button containing an icon from the current icon theme.
///
/// If the icon name isnt known, a broken image icon will be
/// displayed instead. If the current icon theme is changed, the icon
/// will be updated appropriately.
///
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Button.setIconName(iconName:)`.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 iconName: The name of the icon used to automatically populate the button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(iconName: @escaping () -> String, canShrink: Bool? = nil, hasFrame: Bool? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(iconName: iconName()) }
configure.append { w, ctx in
let t0 = DependencyTracker { [w] in w.setIconName(iconName: iconName()) }
t0.run()
ctx.registry.add(t0)
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(interpolation) | source: Gtk.Button.init(iconName:), Gtk.Button.setIconName(iconName:)
/// Creates a new button containing an icon from the current icon theme.
///
/// If the icon name isnt known, a broken image icon will be
/// displayed instead. If the current icon theme is changed, the icon
/// will be updated appropriately.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.Button.setIconName(iconName:)`. A literal with no interpolation is applied once, with no subscription.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 iconName: The name of the icon used to automatically populate the button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(iconName: Portico.InterpolatedText, canShrink: Bool? = nil, hasFrame: Bool? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(iconName: iconName.untrackedText) }
configure.append { w, ctx in
Portico.bindInterpolation(iconName, registry: ctx.registry) { [w] v in w.setIconName(iconName: v) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(static) | source: Gtk.Button.init(label:)
/// Creates a `GtkButton` widget with a `GtkLabel` child.
///
/// 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.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 label: Text of the label inside the button, if the button contains a label widget.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
@_disfavoredOverload
public init<S: StringProtocol>(label: S, canShrink: Bool? = nil, hasFrame: Bool? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(label: String(label)) }
configure.append { w, ctx in
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(binding) | source: Gtk.Button.init(label:), Gtk.Button.setLabel(label:)
/// Creates a `GtkButton` widget with a `GtkLabel` child.
///
/// The initial value is the binding's current value; every later change is pushed into the widget through `Gtk.Button.setLabel(label:)` without rebuilding the view.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 label: Text of the label inside the button, if the button contains a label widget.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(label: Portico.Binding<String>, canShrink: Portico.Binding<Bool>? = nil, hasFrame: Portico.Binding<Bool>? = nil, useUnderline: Portico.Binding<Bool>? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(label: label.wrappedValue) }
configure.append { w, ctx in
ctx.registry.add(label.subscribe { [w] v in w.setLabel(label: v) })
if let canShrink {
Portico.bindProperty(w, canShrink, registry: ctx.registry, notifyDetail: "can-shrink", read: { [w] in w.getCanShrink() }, write: { [w] v in w.setCanShrink(canShrink: v) })
}
if let hasFrame {
Portico.bindProperty(w, hasFrame, registry: ctx.registry, notifyDetail: "has-frame", read: { [w] in w.getHasFrame() }, write: { [w] v in w.setHasFrame(hasFrame: v) })
}
if let useUnderline {
Portico.bindProperty(w, useUnderline, registry: ctx.registry, notifyDetail: "use-underline", read: { [w] in w.getUseUnderline() }, write: { [w] v in w.setUseUnderline(useUnderline: v) })
}
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(closure) | source: Gtk.Button.init(label:), Gtk.Button.setLabel(label:)
/// Creates a `GtkButton` widget with a `GtkLabel` child.
///
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Button.setLabel(label:)`.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 label: Text of the label inside the button, if the button contains a label widget.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(label: @escaping () -> String, canShrink: Bool? = nil, hasFrame: Bool? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(label: label()) }
configure.append { w, ctx in
let t0 = DependencyTracker { [w] in w.setLabel(label: label()) }
t0.run()
ctx.registry.add(t0)
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(interpolation) | source: Gtk.Button.init(label:), Gtk.Button.setLabel(label:)
/// Creates a `GtkButton` widget with a `GtkLabel` child.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.Button.setLabel(label:)`. A literal with no interpolation is applied once, with no subscription.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 label: Text of the label inside the button, if the button contains a label widget.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(label: Portico.InterpolatedText, canShrink: Bool? = nil, hasFrame: Bool? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(label: label.untrackedText) }
configure.append { w, ctx in
Portico.bindInterpolation(label, registry: ctx.registry) { [w] v in w.setLabel(label: v) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(static) | source: Gtk.Button.init(withMnemonicLabel:)
/// Creates a new `GtkButton` containing a label.
///
/// If characters in `label` are preceded by an underscore, they are underlined.
/// If you need a literal underscore character in a label, use __ (two
/// underscores). The first underlined character represents a keyboard
/// accelerator called a mnemonic. Pressing <kbd>Alt</kbd> and that key
/// activates the button.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// 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 withMnemonicLabel: The `withMnemonicLabel` value forwarded to `Gtk.Button`.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(withMnemonicLabel: String, canShrink: Bool? = nil, hasFrame: Bool? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.Button(withMnemonicLabel: withMnemonicLabel) }
configure.append { w, ctx in
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
}
extension Button: WidgetView {
public typealias Target = Gtk.Button
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.Button, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension Button: 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.Button
/// Modifiers for `Gtk.Button`, available on every Portico view whose
/// backing widget is `Gtk.Button` or one of its subclasses.
extension WidgetView where Target: Gtk.Button {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Button.setCanShrink(canShrink:)
/// Sets whether the button size can be smaller than the natural size of
/// its contents.
///
/// For text buttons, setting `can_shrink` to true will ellipsize the label.
///
/// For icons and custom children, this function has no effect.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Returns: A copy of this view with the modifier applied.
public func canShrink(_ canShrink: Bool) -> Self {
appending { w, _ in
w.setCanShrink(canShrink: canShrink)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Button.setCanShrink(canShrink:), GObject.Object.connectNotify(detail:_:), Gtk.Button.getCanShrink()
/// Sets whether the button size can be smaller than the natural size of
/// its contents.
///
/// For text buttons, setting `can_shrink` to true will ellipsize the label.
///
/// For icons and custom children, this function has no effect.
///
/// 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 canShrink(_ canShrink: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, canShrink, registry: ctx.registry, notifyDetail: "can-shrink",
read: { [w] in w.getCanShrink() },
write: { [w] v in w.setCanShrink(canShrink: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Button.setCanShrink(canShrink:)
/// Sets whether the button size can be smaller than the natural size of
/// its contents.
///
/// For text buttons, setting `can_shrink` to true will ellipsize the label.
///
/// For icons and custom children, this function has no effect.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Button.setCanShrink(canShrink:)`.
///
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Returns: A copy of this view with the modifier applied.
public func canShrink(_ canShrink: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setCanShrink(canShrink: canShrink()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Button.setChild(child:)
/// Sets the child widget of `button`.
///
/// Note that by using this API, you take full responsibility for setting
/// up the proper accessibility label and description information for `button`.
/// Most likely, you'll either set the accessibility label or description
/// for `button` explicitly, or you'll set a labelled-by or described-by
/// relations from `child` to `button`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: Gtk.Widget?) -> Self {
appending { w, _ in
w.setChild(child: child)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Gtk.Button.setChild(child:)
/// Sets the child widget of `button`.
///
/// Note that by using this API, you take full responsibility for setting
/// up the proper accessibility label and description information for `button`.
/// Most likely, you'll either set the accessibility label or description
/// for `button` explicitly, or you'll set a labelled-by or described-by
/// relations from `child` to `button`.
///
/// The closure is evaluated once when the modifier is applied. Its first view is mounted into the slot.
/// Additional views are ignored; an empty closure leaves the slot unset.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
guard let v = childViews.first else { return }
w.setChild(child: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Button.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.Button.getChild()
/// Sets the child widget of `button`.
///
/// Note that by using this API, you take full responsibility for setting
/// up the proper accessibility label and description information for `button`.
/// Most likely, you'll either set the accessibility label or description
/// for `button` explicitly, or you'll set a labelled-by or described-by
/// relations from `child` to `button`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.Widget?` 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 child<W: Gtk.Widget>(_ child: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.Button.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.Button.getChild()
/// Sets the child widget of `button`.
///
/// Note that by using this API, you take full responsibility for setting
/// up the proper accessibility label and description information for `button`.
/// Most likely, you'll either set the accessibility label or description
/// for `button` explicitly, or you'll set a labelled-by or described-by
/// relations from `child` to `button`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Gtk.Widget>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.Widget?>` to be able to clear the property.
/// When `Gtk.Widget` 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.
/// A `nil` widget value is never written back into the binding.
///
/// - Returns: A copy of this view with the modifier applied.
public func child<W: Gtk.Widget>(_ child: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Button.setChild(child:)
/// Sets the child widget of `button`.
///
/// Note that by using this API, you take full responsibility for setting
/// up the proper accessibility label and description information for `button`.
/// Most likely, you'll either set the accessibility label or description
/// for `button` explicitly, or you'll set a labelled-by or described-by
/// relations from `child` to `button`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Button.setChild(child:)`.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: @escaping () -> Gtk.Widget?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setChild(child: child()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Button.setHasFrame(hasFrame:)
/// Sets the style of the button.
///
/// Buttons can have a flat appearance or have a frame drawn around them.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter hasFrame: Whether the 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.Button.setHasFrame(hasFrame:), GObject.Object.connectNotify(detail:_:), Gtk.Button.getHasFrame()
/// Sets the style of the button.
///
/// Buttons can have a flat appearance or have a frame drawn around them.
///
/// 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.Button.setHasFrame(hasFrame:)
/// Sets the style of the button.
///
/// Buttons can have a flat appearance or have a frame drawn around them.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Button.setHasFrame(hasFrame:)`.
///
/// - Parameter hasFrame: Whether the 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.Button.setIconName(iconName:)
/// Adds a `GtkImage` with the given icon name as a child.
///
/// If `button` already contains a child widget, that child widget will
/// be removed and replaced with the image.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter iconName: The name of the icon used to automatically populate the button.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func iconName<S: StringProtocol>(_ iconName: S) -> Self {
appending { w, _ in
w.setIconName(iconName: String(iconName))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Button.setIconName(iconName:), GObject.Object.connectNotify(detail:_:), Gtk.Button.getIconName()
/// Adds a `GtkImage` with the given icon name as a child.
///
/// If `button` already contains a child widget, that child widget will
/// be removed and replaced with the image.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String` 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 iconName(_ iconName: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, iconName, registry: ctx.registry, notifyDetail: "icon-name",
read: { [w] in w.getIconName() },
write: { [w] v in w.setIconName(iconName: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Button.setIconName(iconName:)
/// Adds a `GtkImage` with the given icon name as a child.
///
/// If `button` already contains a child widget, that child widget will
/// be removed and replaced with the image.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Button.setIconName(iconName:)`.
///
/// - Parameter iconName: The name of the icon used to automatically populate the button.
/// - Returns: A copy of this view with the modifier applied.
public func iconName(_ iconName: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setIconName(iconName: iconName()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Gtk.Button.setIconName(iconName:)
/// Adds a `GtkImage` with the given icon name as a child.
///
/// If `button` already contains a child widget, that child widget will
/// be removed and replaced with the image.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.Button.setIconName(iconName:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter iconName: The name of the icon used to automatically populate the button.
/// - Returns: A copy of this view with the modifier applied.
public func iconName(_ iconName: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(iconName, registry: ctx.registry) { [w] v in w.setIconName(iconName: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Button.setLabel(label:)
/// Sets the text of the label of the button to `label`.
///
/// This will also clear any previously set labels.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter label: Text of the label inside the button, if the button contains a label widget.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func label<S: StringProtocol>(_ label: S) -> Self {
appending { w, _ in
w.setLabel(label: String(label))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Button.setLabel(label:), GObject.Object.connectNotify(detail:_:), Gtk.Button.getLabel()
/// Sets the text of the label of the button to `label`.
///
/// This will also clear any previously set labels.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String` 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 label(_ label: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, label, registry: ctx.registry, notifyDetail: "label",
read: { [w] in w.getLabel() },
write: { [w] v in w.setLabel(label: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Button.setLabel(label:)
/// Sets the text of the label of the button to `label`.
///
/// This will also clear any previously set labels.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Button.setLabel(label:)`.
///
/// - Parameter label: Text of the label inside the button, if the button contains a label widget.
/// - Returns: A copy of this view with the modifier applied.
public func label(_ label: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setLabel(label: label()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Gtk.Button.setLabel(label:)
/// Sets the text of the label of the button to `label`.
///
/// This will also clear any previously set labels.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.Button.setLabel(label:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter label: Text of the label inside the button, if the button contains a label widget.
/// - Returns: A copy of this view with the modifier applied.
public func label(_ label: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(label, registry: ctx.registry) { [w] v in w.setLabel(label: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Button.setUseUnderline(useUnderline:)
/// Sets whether to use underlines as mnemonics.
///
/// If true, an underline in the text of the button label indicates
/// the next character should be used for the mnemonic accelerator key.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Returns: A copy of this view with the modifier applied.
public func useUnderline(_ useUnderline: Bool) -> Self {
appending { w, _ in
w.setUseUnderline(useUnderline: useUnderline)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Button.setUseUnderline(useUnderline:), GObject.Object.connectNotify(detail:_:), Gtk.Button.getUseUnderline()
/// Sets whether to use underlines as mnemonics.
///
/// If true, an underline in the text of the button label indicates
/// the next character should be used for the mnemonic accelerator key.
///
/// 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 useUnderline(_ useUnderline: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, useUnderline, registry: ctx.registry, notifyDetail: "use-underline",
read: { [w] in w.getUseUnderline() },
write: { [w] v in w.setUseUnderline(useUnderline: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Button.setUseUnderline(useUnderline:)
/// Sets whether to use underlines as mnemonics.
///
/// If true, an underline in the text of the button label indicates
/// the next character should be used for the mnemonic accelerator key.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Button.setUseUnderline(useUnderline:)`.
///
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Returns: A copy of this view with the modifier applied.
public func useUnderline(_ useUnderline: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setUseUnderline(useUnderline: useUnderline()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.Button.connectActivate(_:)
/// Emitted to animate press then release.
///
/// This is an action signal. Applications should never connect
/// to this signal, but use the [signal`Gtk`.Button::clicked] signal.
///
/// The default bindings for this signal are all forms of the
/// <kbd></kbd> and <kbd>Enter</kbd> keys.
///
/// - 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.Button.connectClicked(_:)
/// Emitted when the button has been activated (pressed and released).
///
/// - Parameter handler: Invoked when the widget emits the `clicked` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onClicked(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectClicked { _ in handler() })
}
}
}