portico/Sources/Portico/Generated/ToggleButton.swift

413 lines
26 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.ToggleButton
/// Shows a button which remains pressed-in when clicked.
///
/// <picture>
/// <source srcset="toggle-button-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="Example GtkToggleButtons" src="toggle-button.png">
/// </picture>
///
/// Clicking again will cause the toggle button to return to its normal state.
///
/// A toggle button is created by calling either [ctor`Gtk`.ToggleButton.new] or
/// [ctor`Gtk`.ToggleButton.new_with_label]. If using the former, it is advisable
/// to pack a widget, (such as a `GtkLabel` and/or a `GtkImage`), into the toggle
/// buttons container. (See [class`Gtk`.Button] for more information).
///
/// The state of a `GtkToggleButton` can be set specifically using
/// [method`Gtk`.ToggleButton.set_active], and retrieved using
/// [method`Gtk`.ToggleButton.get_active].
///
/// ## Grouping
///
/// Toggle buttons can be grouped together, to form mutually exclusive
/// groups - only one of the buttons can be toggled at a time, and toggling
/// another one will switch the currently toggled one off.
///
/// To add a `GtkToggleButton` to a group, use [method`Gtk`.ToggleButton.set_group].
///
/// ## CSS nodes
///
/// `GtkToggleButton` has a single CSS node with name button. To differentiate
/// it from a plain `GtkButton`, it gets the `.toggle` style class.
///
/// ## Accessibility
///
/// `GtkToggleButton` uses the [enum`Gtk`.AccessibleRole.toggle_button] role.
///
/// ## Creating two `GtkToggleButton` widgets.
///
/// ```c
/// static void
/// output_state (GtkToggleButton *source,
/// gpointer user_data)
/// {
/// g_print ("Toggle button "`s`" is active: `s`",
/// gtk_button_get_label (GTK_BUTTON (source)),
/// gtk_toggle_button_get_active (source) ? "Yes" : "No");
/// }
///
/// static void
/// make_toggles (void)
/// {
/// GtkWidget *window, *toggle1, *toggle2;
/// GtkWidget *box;
/// const char *text;
///
/// window = gtk_window_new ();
/// box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
///
/// text = "Hi, Im toggle button one";
/// toggle1 = gtk_toggle_button_new_with_label (text);
///
/// g_signal_connect (toggle1, "toggled",
/// G_CALLBACK (output_state),
/// NULL);
/// gtk_box_append (GTK_BOX (box), toggle1);
///
/// text = "Hi, Im toggle button two";
/// toggle2 = gtk_toggle_button_new_with_label (text);
/// g_signal_connect (toggle2, "toggled",
/// G_CALLBACK (output_state),
/// NULL);
/// gtk_box_append (GTK_BOX (box), toggle2);
///
/// gtk_window_set_child (GTK_WINDOW (window), box);
/// gtk_window_present (GTK_WINDOW (window));
/// }
/// ```
///
/// A Portico view that mounts a `Gtk.ToggleButton`.
@MainActor public struct ToggleButton: View {
private let make: (MountContext) -> Gtk.ToggleButton
private var configure: [(Gtk.ToggleButton, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.ToggleButton.init()
/// Creates a new toggle button.
///
/// A widget should be packed into the button, as in [ctor`Gtk`.Button.new].
///
/// 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 active: If the toggle button should be pressed in.
/// - 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 iconName: The name of the icon used to automatically populate the button.
/// - 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 onToggled: Invoked when the widget emits the `toggled` signal.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(active: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onToggled: (() -> Void)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.ToggleButton() }
configure.append { w, ctx in
if let active { w.setActive(isActive: active) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
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 onToggled { ctx.registry.add(w.connectToggled { _ in onToggled() }) }
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.ToggleButton.init(label:)
/// Creates a new toggle button with a text label.
///
/// 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: The `label` value forwarded to `Gtk.ToggleButton`.
/// - Parameter active: If the toggle button should be pressed in.
/// - 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 iconName: The name of the icon used to automatically populate the button.
/// - 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 onToggled: Invoked when the widget emits the `toggled` signal.
/// - 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, active: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onToggled: (() -> Void)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.ToggleButton(label: String(label)) }
configure.append { w, ctx in
if let active { w.setActive(isActive: active) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
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 onToggled { ctx.registry.add(w.connectToggled { _ in onToggled() }) }
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.ToggleButton.init(label:), Gtk.ToggleButton.setLabel(label:)
/// Creates a new toggle button with a text label.
///
/// The initial value is the binding's current value; every later change is pushed into the widget through `Gtk.ToggleButton.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: The `label` value forwarded to `Gtk.ToggleButton`.
/// - Parameter active: If the toggle button should be pressed in.
/// - 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 iconName: The name of the icon used to automatically populate the button.
/// - 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 onToggled: Invoked when the widget emits the `toggled` signal.
/// - 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>, active: Portico.Binding<Bool>? = nil, canShrink: Portico.Binding<Bool>? = nil, hasFrame: Portico.Binding<Bool>? = nil, iconName: Portico.Binding<String>? = nil, useUnderline: Portico.Binding<Bool>? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onToggled: (() -> Void)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.ToggleButton(label: label.wrappedValue) }
configure.append { w, ctx in
ctx.registry.add(label.subscribe { [w] v in w.setLabel(label: v) })
if let active {
Portico.bindProperty(w, active, registry: ctx.registry, notifyDetail: "active", read: { [w] in w.getActive() }, write: { [w] v in w.setActive(isActive: 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 iconName {
Portico.bindProperty(w, iconName, registry: ctx.registry, notifyDetail: "icon-name", read: { [w] in w.getIconName() }, write: { [w] v in w.setIconName(iconName: 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 onToggled { ctx.registry.add(w.connectToggled { _ in onToggled() }) }
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.ToggleButton.init(label:), Gtk.ToggleButton.setLabel(label:)
/// Creates a new toggle button with a text label.
///
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.ToggleButton.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: The `label` value forwarded to `Gtk.ToggleButton`.
/// - Parameter active: If the toggle button should be pressed in.
/// - 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 iconName: The name of the icon used to automatically populate the button.
/// - 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 onToggled: Invoked when the widget emits the `toggled` signal.
/// - 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, active: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onToggled: (() -> Void)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.ToggleButton(label: label()) }
configure.append { w, ctx in
let t0 = DependencyTracker { [w] in w.setLabel(label: label()) }
t0.run()
ctx.registry.add(t0)
if let active { w.setActive(isActive: active) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
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 onToggled { ctx.registry.add(w.connectToggled { _ in onToggled() }) }
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.ToggleButton.init(label:), Gtk.ToggleButton.setLabel(label:)
/// Creates a new toggle button with a text label.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.ToggleButton.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: The `label` value forwarded to `Gtk.ToggleButton`.
/// - Parameter active: If the toggle button should be pressed in.
/// - 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 iconName: The name of the icon used to automatically populate the button.
/// - 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 onToggled: Invoked when the widget emits the `toggled` signal.
/// - 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, active: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onToggled: (() -> Void)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.ToggleButton(label: label.untrackedText) }
configure.append { w, ctx in
Portico.bindInterpolation(label, registry: ctx.registry) { [w] v in w.setLabel(label: v) }
if let active { w.setActive(isActive: active) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
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 onToggled { ctx.registry.add(w.connectToggled { _ in onToggled() }) }
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.ToggleButton.init(withMnemonicLabel:)
/// Creates a new `GtkToggleButton` containing a label.
///
/// The label will be created using [ctor`Gtk`.Label.new_with_mnemonic],
/// so underscores in `label` indicate the mnemonic for 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.ToggleButton`.
/// - Parameter active: If the toggle button should be pressed in.
/// - 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 iconName: The name of the icon used to automatically populate the button.
/// - 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 onToggled: Invoked when the widget emits the `toggled` signal.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(withMnemonicLabel: String, active: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onToggled: (() -> Void)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.ToggleButton(withMnemonicLabel: withMnemonicLabel) }
configure.append { w, ctx in
if let active { w.setActive(isActive: active) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
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 onToggled { ctx.registry.add(w.connectToggled { _ in onToggled() }) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
}
extension ToggleButton: WidgetView {
public typealias Target = Gtk.ToggleButton
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.ToggleButton, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension ToggleButton: 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.ToggleButton
/// Modifiers for `Gtk.ToggleButton`, available on every Portico view whose
/// backing widget is `Gtk.ToggleButton` or one of its subclasses.
extension WidgetView where Target: Gtk.ToggleButton {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.ToggleButton.setActive(isActive:)
/// Sets the status of the toggle button.
///
/// Set to `true` if you want the `GtkToggleButton` to be pressed in,
/// and `false` to raise it.
///
/// If the status of the button changes, this action causes the
/// [signal`Gtk`.ToggleButton::toggled] signal to be emitted.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter active: If the toggle button should be pressed in.
/// - Returns: A copy of this view with the modifier applied.
public func active(_ active: Bool) -> Self {
appending { w, _ in
w.setActive(isActive: active)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.ToggleButton.setActive(isActive:), GObject.Object.connectNotify(detail:_:), Gtk.ToggleButton.getActive()
/// Sets the status of the toggle button.
///
/// Set to `true` if you want the `GtkToggleButton` to be pressed in,
/// and `false` to raise it.
///
/// If the status of the button changes, this action causes the
/// [signal`Gtk`.ToggleButton::toggled] signal to be emitted.
///
/// 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 active(_ active: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, active, registry: ctx.registry, notifyDetail: "active",
read: { [w] in w.getActive() },
write: { [w] v in w.setActive(isActive: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.ToggleButton.setActive(isActive:)
/// Sets the status of the toggle button.
///
/// Set to `true` if you want the `GtkToggleButton` to be pressed in,
/// and `false` to raise it.
///
/// If the status of the button changes, this action causes the
/// [signal`Gtk`.ToggleButton::toggled] signal to be emitted.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.ToggleButton.setActive(isActive:)`.
///
/// - Parameter active: If the toggle button should be pressed in.
/// - Returns: A copy of this view with the modifier applied.
public func active(_ active: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setActive(isActive: active()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.ToggleButton.connectToggled(_:)
/// Emitted whenever the `GtkToggleButton`'s state is changed.
///
/// - Parameter handler: Invoked when the widget emits the `toggled` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onToggled(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectToggled { _ in handler() })
}
}
}