portico/Sources/Portico/Generated/InfoBar.swift

371 lines
18 KiB
Swift

// Generated by PorticoGen. DO NOT EDIT. See Sources/PorticoGen to make changes.
import Adw
import Gtk
import Gio
import Gdk
// PorticoGen: generateStruct | source: Gtk.InfoBar
/// `GtkInfoBar` can be used to show messages to the user without a dialog.
///
/// <picture>
/// <source srcset="info-bar-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkInfoBar" src="info-bar.png">
/// </picture>
///
/// It is often temporarily shown at the top or bottom of a document.
/// In contrast to [class`Gtk`.Dialog], which has an action area at the
/// bottom, `GtkInfoBar` has an action area at the side.
///
/// The API of `GtkInfoBar` is very similar to `GtkDialog`, allowing you
/// to add buttons to the action area with [method`Gtk`.InfoBar.add_button]
/// or [ctor`Gtk`.InfoBar.new_with_buttons]. The sensitivity of action widgets
/// can be controlled with [method`Gtk`.InfoBar.set_response_sensitive].
///
/// To add widgets to the main content area of a `GtkInfoBar`, use
/// [method`Gtk`.InfoBar.add_child].
///
/// Similar to [class`Gtk`.MessageDialog], the contents of a `GtkInfoBar`
/// can by classified as error message, warning, informational message, etc,
/// by using [method`Gtk`.InfoBar.set_message_type]. GTK may use the message
/// type to determine how the message is displayed.
///
/// A simple example for using a `GtkInfoBar`:
/// ```c
/// GtkWidget *message_label;
/// GtkWidget *widget;
/// GtkWidget *grid;
/// GtkInfoBar *bar;
///
/// // set up info bar
/// widget = gtk_info_bar_new ();
/// bar = GTK_INFO_BAR (widget);
/// grid = gtk_grid_new ();
///
/// message_label = gtk_label_new ("");
/// gtk_info_bar_add_child (bar, message_label);
/// gtk_info_bar_add_button (bar,
/// _("_OK"),
/// GTK_RESPONSE_OK);
/// g_signal_connect (bar,
/// "response",
/// G_CALLBACK (gtk_widget_hide),
/// NULL);
/// gtk_grid_attach (GTK_GRID (grid),
/// widget,
/// 0, 2, 1, 1);
///
/// // ...
///
/// // show an error message
/// gtk_label_set_text (GTK_LABEL (message_label), "An error occurred!");
/// gtk_info_bar_set_message_type (bar, GTK_MESSAGE_ERROR);
/// gtk_widget_show (bar);
/// ```
///
/// # GtkInfoBar as GtkBuildable
///
/// `GtkInfoBar` supports a custom `<action-widgets>` element, which can contain
/// multiple `<action-widget>` elements. The response attribute specifies a
/// numeric response, and the content of the element is the id of widget
/// (which should be a child of the dialogs `action_area`).
///
/// `GtkInfoBar` supports adding action widgets by specifying action as
/// the type attribute of a `<child>` element. The widget will be added
/// either to the action area. The response id has to be associated
/// with the action widget using the `<action-widgets>` element.
///
/// # CSS nodes
///
/// `GtkInfoBar` has a single CSS node with name infobar. The node may get
/// one of the style classes .info, .warning, .error or .question, depending
/// on the message type.
/// If the info bar shows a close button, that button will have the .close
/// style class applied.
///
/// A Portico view that mounts a `Gtk.InfoBar`.
@MainActor public struct InfoBar: View {
private let make: (MountContext) -> Gtk.InfoBar
private var configure: [(Gtk.InfoBar, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.InfoBar.init()
/// Creates a new `GtkInfoBar` object.
///
/// 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.
/// A `ForEach` in the `children:` closure spreads its rows directly into this widget, with no wrapper, when the widget supports ordered insertion.
/// 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 messageType: The type of the message.
/// - Parameter revealed: Whether the info bar shows its contents.
/// - Parameter showCloseButton: Whether to include a standard close button.
/// - Parameter children: A `ViewBuilder` closure whose views are added in order.
/// - Parameter onClose: Invoked when the widget emits the `close` signal.
/// - Parameter onResponse: Invoked when the widget emits the `response` signal. The closure receives the signal's arguments in order.
public init(messageType: Gtk.MessageType? = nil, revealed: Bool? = nil, showCloseButton: Bool? = nil, @ViewBuilder children: @escaping () -> [AnyView] = { [] }, onClose: (() -> Void)? = nil, onResponse: ((Int32) -> Void)? = nil) {
make = { _ in Gtk.InfoBar() }
configure.append { w, ctx in
if let messageType { w.setMessageType(messageType: messageType) }
if let revealed { w.setRevealed(revealed: revealed) }
if let showCloseButton { w.setShowCloseButton(setting: showCloseButton) }
Portico.mountChildren(children, into: w, ctx) { c in w.addChild(widget: c) }
if let onClose { ctx.registry.add(w.connectClose { _ in onClose() }) }
if let onResponse { ctx.registry.add(w.connectResponse { _, a0 in onResponse(a0) }) }
}
}
}
extension InfoBar: WidgetView {
public typealias Target = Gtk.InfoBar
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.InfoBar, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension InfoBar: 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.InfoBar
/// Modifiers for `Gtk.InfoBar`, available on every Portico view whose
/// backing widget is `Gtk.InfoBar` or one of its subclasses.
extension WidgetView where Target: Gtk.InfoBar {
// PorticoGen: generateModifierExtension -> generateChildAdderModifiers(static) | source: Gtk.InfoBar.addChild(widget:)
/// Adds a widget to the content area of the info bar.
///
/// Applied once at mount; use the `@ViewBuilder` overload for multiple children.
///
/// - Parameter child: A child widget to add.
/// - Returns: A copy of this view with the modifier applied.
public func addChild(_ child: Gtk.Widget) -> Self {
appending { w, _ in
w.addChild(widget: child)
}
}
// PorticoGen: generateModifierExtension -> generateChildAdderModifiers(viewBuilder) | source: Gtk.InfoBar.addChild(widget:)
/// Adds a widget to the content area of the info bar.
///
/// Every view the closure produces is added at mount, in order.
///
/// - Parameter child: A closure producing child views.
/// - Returns: A copy of this view with the modifier applied.
public func addChild(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
for v in childViews { w.addChild(widget: v.makeWidget(ctx)) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.InfoBar.setMessageType(messageType:)
/// Sets the message type of the message area.
///
/// GTK uses this type to determine how the message is displayed.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter messageType: The type of the message.
/// - Returns: A copy of this view with the modifier applied.
public func messageType(_ messageType: Gtk.MessageType) -> Self {
appending { w, _ in
w.setMessageType(messageType: messageType)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.InfoBar.setMessageType(messageType:), GObject.Object.connectNotify(detail:_:), Gtk.InfoBar.getMessageType()
/// Sets the message type of the message area.
///
/// GTK uses this type to determine how the message is displayed.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.MessageType` 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 messageType(_ messageType: Portico.Binding<Gtk.MessageType>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, messageType, registry: ctx.registry, notifyDetail: "message-type",
read: { [w] in w.getMessageType() },
write: { [w] v in w.setMessageType(messageType: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.InfoBar.setMessageType(messageType:)
/// Sets the message type of the message area.
///
/// GTK uses this type to determine how the message is displayed.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.InfoBar.setMessageType(messageType:)`.
///
/// - Parameter messageType: The type of the message.
/// - Returns: A copy of this view with the modifier applied.
public func messageType(_ messageType: @escaping () -> Gtk.MessageType) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setMessageType(messageType: messageType()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.InfoBar.setRevealed(revealed:)
/// Sets whether the `GtkInfoBar` is revealed.
///
/// Changing this will make `info_bar` reveal or conceal
/// itself via a sliding transition.
///
/// Note: this does not show or hide `info_bar` in the
/// [property`Gtk`.Widget:visible] sense, so revealing has no effect
/// if [property`Gtk`.Widget:visible] is `false`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter revealed: Whether the info bar shows its contents.
/// - Returns: A copy of this view with the modifier applied.
public func revealed(_ revealed: Bool) -> Self {
appending { w, _ in
w.setRevealed(revealed: revealed)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.InfoBar.setRevealed(revealed:), GObject.Object.connectNotify(detail:_:), Gtk.InfoBar.getRevealed()
/// Sets whether the `GtkInfoBar` is revealed.
///
/// Changing this will make `info_bar` reveal or conceal
/// itself via a sliding transition.
///
/// Note: this does not show or hide `info_bar` in the
/// [property`Gtk`.Widget:visible] sense, so revealing has no effect
/// if [property`Gtk`.Widget:visible] is `false`.
///
/// 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 revealed(_ revealed: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, revealed, registry: ctx.registry, notifyDetail: "revealed",
read: { [w] in w.getRevealed() },
write: { [w] v in w.setRevealed(revealed: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.InfoBar.setRevealed(revealed:)
/// Sets whether the `GtkInfoBar` is revealed.
///
/// Changing this will make `info_bar` reveal or conceal
/// itself via a sliding transition.
///
/// Note: this does not show or hide `info_bar` in the
/// [property`Gtk`.Widget:visible] sense, so revealing has no effect
/// if [property`Gtk`.Widget:visible] is `false`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.InfoBar.setRevealed(revealed:)`.
///
/// - Parameter revealed: Whether the info bar shows its contents.
/// - Returns: A copy of this view with the modifier applied.
public func revealed(_ revealed: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setRevealed(revealed: revealed()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.InfoBar.setShowCloseButton(setting:)
/// If true, a standard close button is shown.
///
/// When clicked it emits the response `GTK_RESPONSE_CLOSE`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showCloseButton: Whether to include a standard close button.
/// - Returns: A copy of this view with the modifier applied.
public func showCloseButton(_ showCloseButton: Bool) -> Self {
appending { w, _ in
w.setShowCloseButton(setting: showCloseButton)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.InfoBar.setShowCloseButton(setting:), GObject.Object.connectNotify(detail:_:), Gtk.InfoBar.getShowCloseButton()
/// If true, a standard close button is shown.
///
/// When clicked it emits the response `GTK_RESPONSE_CLOSE`.
///
/// 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 showCloseButton(_ showCloseButton: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showCloseButton, registry: ctx.registry, notifyDetail: "show-close-button",
read: { [w] in w.getShowCloseButton() },
write: { [w] v in w.setShowCloseButton(setting: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.InfoBar.setShowCloseButton(setting:)
/// If true, a standard close button is shown.
///
/// When clicked it emits the response `GTK_RESPONSE_CLOSE`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.InfoBar.setShowCloseButton(setting:)`.
///
/// - Parameter showCloseButton: Whether to include a standard close button.
/// - Returns: A copy of this view with the modifier applied.
public func showCloseButton(_ showCloseButton: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowCloseButton(setting: showCloseButton()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.InfoBar.connectClose(_:)
/// Gets emitted when the user uses a keybinding to dismiss the info bar.
///
/// The ::close signal is a [keybinding signal](class.SignalAction.html).
///
/// The default binding for this signal is the Escape key.
///
/// - Parameter handler: Invoked when the widget emits the `close` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onClose(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectClose { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.InfoBar.connectResponse(_:)
/// Emitted when an action widget is clicked.
///
/// The signal is also emitted when the application programmer
/// calls [method`Gtk`.InfoBar.response]. The `response_id` depends
/// on which action widget was clicked.
///
/// - Parameter handler: Invoked when the widget emits the `response` signal. The closure receives the signal's arguments in order.
/// - Returns: A copy of this view with the modifier applied.
public func onResponse(_ handler: @escaping (Int32) -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectResponse { _, a0 in handler(a0) })
}
}
}