portico/Sources/Portico/Generated/AlertDialog.swift

678 lines
30 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: Adw.AlertDialog
/// A dialog presenting a message or a question.
///
/// <picture>
/// <source srcset="alert-dialog-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="alert-dialog.png" alt="alert-dialog">
/// </picture>
///
/// Alert dialogs have a heading, a body, an optional child widget, and one or
/// multiple responses, each presented as a button.
///
/// Each response has a unique string ID, and a button label. Additionally, each
/// response can be enabled or disabled, and can have a suggested or destructive
/// appearance.
///
/// When one of the responses is activated, or the dialog is closed, the
/// [signal`AlertDialog`::response] signal will be emitted. This signal is
/// detailed, and the detail, as well as the `response` parameter will be set to
/// the ID of the activated response, or to the value of the
/// [property`AlertDialog`:close-response] property if the dialog had been closed
/// without activating any of the responses.
///
/// Response buttons can be presented horizontally or vertically depending on
/// available space.
///
/// When a response is activated, `AdwAlertDialog` is closed automatically.
///
/// An example of using an alert dialog:
///
/// ```c
/// AdwDialog *dialog;
///
/// dialog = adw_alert_dialog_new (_("Replace File?"), NULL);
///
/// adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
/// _("A file named `s` already exists. Do you want to replace it?"),
/// filename);
///
/// adw_alert_dialog_add_responses (ADW_ALERT_DIALOG (dialog),
/// "cancel", _("_Cancel"),
/// "replace", _("_Replace"),
/// NULL);
///
/// adw_alert_dialog_set_response_appearance (ADW_ALERT_DIALOG (dialog),
/// "replace",
/// ADW_RESPONSE_DESTRUCTIVE);
///
/// adw_alert_dialog_set_default_response (ADW_ALERT_DIALOG (dialog), "cancel");
/// adw_alert_dialog_set_close_response (ADW_ALERT_DIALOG (dialog), "cancel");
///
/// g_signal_connect (dialog, "response", G_CALLBACK (response_cb), self);
///
/// adw_dialog_present (dialog, parent);
/// ```
///
/// ## Async API
///
/// `AdwAlertDialog` can also be used via the [method`AlertDialog`.choose] method.
/// This API follows the GIO async pattern, for example:
///
/// ```c
/// static void
/// dialog_cb (AdwAlertDialog *dialog,
/// GAsyncResult *result,
/// MyWindow *self)
/// {
/// const char *response = adw_alert_dialog_choose_finish (dialog, result);
///
/// // ...
/// }
///
/// static void
/// show_dialog (MyWindow *self)
/// {
/// AdwDialog *dialog;
///
/// dialog = adw_alert_dialog_new (_("Replace File?"), NULL);
///
/// adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
/// _("A file named `s` already exists. Do you want to replace it?"),
/// filename);
///
/// adw_alert_dialog_add_responses (ADW_ALERT_DIALOG (dialog),
/// "cancel", _("_Cancel"),
/// "replace", _("_Replace"),
/// NULL);
///
/// adw_alert_dialog_set_response_appearance (ADW_ALERT_DIALOG (dialog),
/// "replace",
/// ADW_RESPONSE_DESTRUCTIVE);
///
/// adw_alert_dialog_set_default_response (ADW_ALERT_DIALOG (dialog), "cancel");
/// adw_alert_dialog_set_close_response (ADW_ALERT_DIALOG (dialog), "cancel");
///
/// adw_alert_dialog_choose (ADW_ALERT_DIALOG (dialog), GTK_WIDGET (self),
/// NULL, (GAsyncReadyCallback) dialog_cb, self);
/// }
/// ```
///
/// ## AdwAlertDialog as GtkBuildable
///
/// `AdwAlertDialog` supports adding responses in UI definitions by via the
/// `<responses>` element that may contain multiple `<response>` elements, each
/// representing a response.
///
/// Each of the `<response>` elements must have the `id` attribute specifying the
/// response ID. The contents of the element are used as the response label.
///
/// Response labels can be translated with the usual `translatable`, `context`
/// and `comments` attributes.
///
/// The `<response>` elements can also have `enabled` and/or `appearance`
/// attributes. See [method`AlertDialog`.set_response_enabled] and
/// [method`AlertDialog`.set_response_appearance] for details.
///
/// Example of an `AdwAlertDialog` UI definition:
///
/// ```xml
/// <object class="AdwAlertDialog" id="dialog">
/// <property name="heading" translatable="yes">Save Changes?</property>
/// <property name="body" translatable="yes">Open documents contain unsaved changes. Changes which are not saved will be permanently lost.</property>
/// <property name="default-response">save</property>
/// <property name="close-response">cancel</property>
/// <signal name="response" handler="response_cb"/>
/// <responses>
/// <response id="cancel" translatable="yes">_Cancel</response>
/// <response id="discard" translatable="yes" appearance="destructive">_Discard</response>
/// <response id="save" translatable="yes" appearance="suggested" enabled="false">_Save</response>
/// </responses>
/// </object>
/// ```
///
/// A Portico view that mounts a `Adw.AlertDialog`.
@MainActor public struct AlertDialog: View {
private let make: (MountContext) -> Adw.AlertDialog
private var configure: [(Adw.AlertDialog, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.AlertDialog.init(heading:body:)
/// Creates a new `AdwAlertDialog`.
///
/// `heading` and `body` can be set to `NULL`. This can be useful if they need to
/// be formatted or use markup. In that case, set them to `NULL` and call
/// [method`AlertDialog`.format_body] or similar methods afterwards:
///
/// ```c
/// AdwDialog *dialog;
///
/// dialog = adw_alert_dialog_new (_("Replace File?"), NULL);
/// adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
/// _("A file named `s` already exists. Do you want to replace it?"),
/// filename);
/// ```
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
///
/// - Parameter heading: The heading of the dialog.
/// - Parameter body: The body text of the dialog.
public init(heading: String?, body: String?) {
make = { _ in Adw.AlertDialog(heading: heading, body: body) }
}
// PorticoGen: generateContentInit | source: Adw.AlertDialog.setExtraChild(child:)
/// Creates a AlertDialog with child widgets supplied by `ViewBuilder` closures.
///
/// Each closure is evaluated once; its first view is mounted into the matching slot.
/// Additional views are ignored; an empty closure leaves that slot unset.
///
/// - Parameter heading: The heading of the dialog.
/// - Parameter body: The body text of the dialog.
/// - Parameter extraChild: A `ViewBuilder` closure whose first view is mounted into the `extraChild` slot.
public init(heading: String?, body: String?, @ViewBuilder extraChild: () -> [AnyView]) {
let extraChildViews = extraChild()
make = { _ in Adw.AlertDialog(heading: heading, body: body) }
configure.append { w, ctx in
if let v = extraChildViews.first { w.setExtraChild(child: v.makeWidget(ctx)) }
}
}
}
extension AlertDialog: WidgetView {
public typealias Target = Adw.AlertDialog
@_spi(Portico) public func appending(
_ step: @escaping (Adw.AlertDialog, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension AlertDialog: 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: Adw.AlertDialog
/// Modifiers for `Adw.AlertDialog`, available on every Portico view whose
/// backing widget is `Adw.AlertDialog` or one of its subclasses.
extension WidgetView where Target: Adw.AlertDialog {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.AlertDialog.setBody(body:)
/// Sets the body text of `self`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter body: The body text of the dialog.
/// - Returns: A copy of this view with the modifier applied.
public func body(_ body: String) -> Self {
appending { w, _ in
w.setBody(body: body)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Adw.AlertDialog.setBody(body:)
/// Sets the body text of `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter body: The body text of the dialog.
/// - Returns: A copy of this view with the modifier applied.
public func body(_ body: Portico.Binding<String>) -> Self {
appending { w, ctx in
w.setBody(body: body.wrappedValue)
ctx.registry.add(body.subscribe { [w] v in w.setBody(body: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.AlertDialog.setBody(body:)
/// Sets the body text of `self`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.AlertDialog.setBody(body:)`.
///
/// - Parameter body: The body text of the dialog.
/// - Returns: A copy of this view with the modifier applied.
public func body(_ body: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setBody(body: body()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.AlertDialog.setBodyUseMarkup(useMarkup:)
/// Sets whether the body text of `self` includes Pango markup.
///
/// See [func`Pango`.parse_markup].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter bodyUseMarkup: Whether the body text includes Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func bodyUseMarkup(_ bodyUseMarkup: Bool) -> Self {
appending { w, _ in
w.setBodyUseMarkup(useMarkup: bodyUseMarkup)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Adw.AlertDialog.setBodyUseMarkup(useMarkup:)
/// Sets whether the body text of `self` includes Pango markup.
///
/// See [func`Pango`.parse_markup].
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter bodyUseMarkup: Whether the body text includes Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func bodyUseMarkup(_ bodyUseMarkup: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
w.setBodyUseMarkup(useMarkup: bodyUseMarkup.wrappedValue)
ctx.registry.add(bodyUseMarkup.subscribe { [w] v in w.setBodyUseMarkup(useMarkup: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.AlertDialog.setBodyUseMarkup(useMarkup:)
/// Sets whether the body text of `self` includes Pango markup.
///
/// See [func`Pango`.parse_markup].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.AlertDialog.setBodyUseMarkup(useMarkup:)`.
///
/// - Parameter bodyUseMarkup: Whether the body text includes Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func bodyUseMarkup(_ bodyUseMarkup: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setBodyUseMarkup(useMarkup: bodyUseMarkup()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.AlertDialog.setCloseResponse(response:)
/// Sets the ID of the close response of `self`.
///
/// It will be passed to [signal`AlertDialog`::response] if the dialog is closed
/// by pressing <kbd>Escape</kbd> or with a system action.
///
/// It doesn't have to correspond to any of the responses in the dialog.
///
/// The default close response is `close`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter closeResponse: The ID of the close response.
/// - Returns: A copy of this view with the modifier applied.
public func closeResponse(_ closeResponse: String) -> Self {
appending { w, _ in
w.setCloseResponse(response: closeResponse)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Adw.AlertDialog.setCloseResponse(response:)
/// Sets the ID of the close response of `self`.
///
/// It will be passed to [signal`AlertDialog`::response] if the dialog is closed
/// by pressing <kbd>Escape</kbd> or with a system action.
///
/// It doesn't have to correspond to any of the responses in the dialog.
///
/// The default close response is `close`.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter closeResponse: The ID of the close response.
/// - Returns: A copy of this view with the modifier applied.
public func closeResponse(_ closeResponse: Portico.Binding<String>) -> Self {
appending { w, ctx in
w.setCloseResponse(response: closeResponse.wrappedValue)
ctx.registry.add(closeResponse.subscribe { [w] v in w.setCloseResponse(response: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.AlertDialog.setCloseResponse(response:)
/// Sets the ID of the close response of `self`.
///
/// It will be passed to [signal`AlertDialog`::response] if the dialog is closed
/// by pressing <kbd>Escape</kbd> or with a system action.
///
/// It doesn't have to correspond to any of the responses in the dialog.
///
/// The default close response is `close`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.AlertDialog.setCloseResponse(response:)`.
///
/// - Parameter closeResponse: The ID of the close response.
/// - Returns: A copy of this view with the modifier applied.
public func closeResponse(_ closeResponse: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setCloseResponse(response: closeResponse()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.AlertDialog.setDefaultResponse(response:)
/// Sets the ID of the default response of `self`.
///
/// The button corresponding to this response will be set as the default widget
/// of `self`.
///
/// If not set, the default widget will not be set, and the last added response
/// will be focused by default.
///
/// See [property`Dialog`:default-widget].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter defaultResponse: The response ID of the default response.
/// - Returns: A copy of this view with the modifier applied.
public func defaultResponse(_ defaultResponse: String?) -> Self {
appending { w, _ in
w.setDefaultResponse(response: defaultResponse)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Adw.AlertDialog.setDefaultResponse(response:)
/// Sets the ID of the default response of `self`.
///
/// The button corresponding to this response will be set as the default widget
/// of `self`.
///
/// If not set, the default widget will not be set, and the last added response
/// will be focused by default.
///
/// See [property`Dialog`:default-widget].
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter defaultResponse: The response ID of the default response.
/// - Returns: A copy of this view with the modifier applied.
public func defaultResponse(_ defaultResponse: Portico.Binding<String?>) -> Self {
appending { w, ctx in
w.setDefaultResponse(response: defaultResponse.wrappedValue)
ctx.registry.add(defaultResponse.subscribe { [w] v in w.setDefaultResponse(response: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted) | source: Adw.AlertDialog.setDefaultResponse(response:)
/// Sets the ID of the default response of `self`.
///
/// The button corresponding to this response will be set as the default widget
/// of `self`.
///
/// If not set, the default widget will not be set, and the last added response
/// will be focused by default.
///
/// See [property`Dialog`:default-widget].
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<String>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<String?>` to be able to clear the property.
///
/// - Parameter defaultResponse: The response ID of the default response.
/// - Returns: A copy of this view with the modifier applied.
public func defaultResponse(_ defaultResponse: Portico.Binding<String>) -> Self {
appending { w, ctx in
w.setDefaultResponse(response: defaultResponse.wrappedValue)
ctx.registry.add(defaultResponse.subscribe { [w] v in w.setDefaultResponse(response: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.AlertDialog.setDefaultResponse(response:)
/// Sets the ID of the default response of `self`.
///
/// The button corresponding to this response will be set as the default widget
/// of `self`.
///
/// If not set, the default widget will not be set, and the last added response
/// will be focused by default.
///
/// See [property`Dialog`:default-widget].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.AlertDialog.setDefaultResponse(response:)`.
///
/// - Parameter defaultResponse: The response ID of the default response.
/// - Returns: A copy of this view with the modifier applied.
public func defaultResponse(_ defaultResponse: @escaping () -> String?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setDefaultResponse(response: defaultResponse()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.AlertDialog.setExtraChild(child:)
/// Sets the child widget of `self`.
///
/// The child widget is displayed below the heading and body.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter extraChild: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func extraChild(_ extraChild: Adw.Widget?) -> Self {
appending { w, _ in
w.setExtraChild(child: extraChild)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Adw.AlertDialog.setExtraChild(child:)
/// Sets the child widget of `self`.
///
/// The child widget is displayed below the heading and body.
///
/// 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 extraChild: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func extraChild(@ViewBuilder _ extraChild: () -> [AnyView]) -> Self {
let extraChildViews = extraChild()
return appending { w, ctx in
guard let v = extraChildViews.first else { return }
w.setExtraChild(child: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.AlertDialog.setHeading(heading:)
/// Sets the heading of `self`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter heading: The heading of the dialog.
/// - Returns: A copy of this view with the modifier applied.
public func heading(_ heading: String?) -> Self {
appending { w, _ in
w.setHeading(heading: heading)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Adw.AlertDialog.setHeading(heading:)
/// Sets the heading of `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter heading: The heading of the dialog.
/// - Returns: A copy of this view with the modifier applied.
public func heading(_ heading: Portico.Binding<String?>) -> Self {
appending { w, ctx in
w.setHeading(heading: heading.wrappedValue)
ctx.registry.add(heading.subscribe { [w] v in w.setHeading(heading: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted) | source: Adw.AlertDialog.setHeading(heading:)
/// Sets the heading of `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<String>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<String?>` to be able to clear the property.
///
/// - Parameter heading: The heading of the dialog.
/// - Returns: A copy of this view with the modifier applied.
public func heading(_ heading: Portico.Binding<String>) -> Self {
appending { w, ctx in
w.setHeading(heading: heading.wrappedValue)
ctx.registry.add(heading.subscribe { [w] v in w.setHeading(heading: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.AlertDialog.setHeading(heading:)
/// Sets the heading of `self`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.AlertDialog.setHeading(heading:)`.
///
/// - Parameter heading: The heading of the dialog.
/// - Returns: A copy of this view with the modifier applied.
public func heading(_ heading: @escaping () -> String?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setHeading(heading: heading()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.AlertDialog.setHeadingUseMarkup(useMarkup:)
/// Sets whether the heading of `self` includes Pango markup.
///
/// See [func`Pango`.parse_markup].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter headingUseMarkup: Whether the heading includes Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func headingUseMarkup(_ headingUseMarkup: Bool) -> Self {
appending { w, _ in
w.setHeadingUseMarkup(useMarkup: headingUseMarkup)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Adw.AlertDialog.setHeadingUseMarkup(useMarkup:)
/// Sets whether the heading of `self` includes Pango markup.
///
/// See [func`Pango`.parse_markup].
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter headingUseMarkup: Whether the heading includes Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func headingUseMarkup(_ headingUseMarkup: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
w.setHeadingUseMarkup(useMarkup: headingUseMarkup.wrappedValue)
ctx.registry.add(headingUseMarkup.subscribe { [w] v in w.setHeadingUseMarkup(useMarkup: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.AlertDialog.setHeadingUseMarkup(useMarkup:)
/// Sets whether the heading of `self` includes Pango markup.
///
/// See [func`Pango`.parse_markup].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.AlertDialog.setHeadingUseMarkup(useMarkup:)`.
///
/// - Parameter headingUseMarkup: Whether the heading includes Pango markup.
/// - Returns: A copy of this view with the modifier applied.
public func headingUseMarkup(_ headingUseMarkup: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setHeadingUseMarkup(useMarkup: headingUseMarkup()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.AlertDialog.setPreferWideLayout(preferWideLayout:)
/// Whether to prefer horizontal button layout.
///
/// `AdwAlertDialog` can present buttons horizontally or vertically depending
/// on available space, how many buttons there are and how wide they are.
///
/// By default it will prefer to stack buttons vertically at medium sizes.
///
/// Set to `TRUE` to prefer horizontal layout in these cases instead. This will
/// make the dialog slightly wider as well.
///
/// Vertical layout may still be used if the dialog would get too wide
/// otherwise.
///
/// Does nothing with just one button, or when the buttons are already
/// horizontal.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter preferWideLayout: Whether to prefer horizontal button layout.
/// - Returns: A copy of this view with the modifier applied.
public func preferWideLayout(_ preferWideLayout: Bool) -> Self {
appending { w, _ in
w.setPreferWideLayout(preferWideLayout: preferWideLayout)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Adw.AlertDialog.setPreferWideLayout(preferWideLayout:)
/// Whether to prefer horizontal button layout.
///
/// `AdwAlertDialog` can present buttons horizontally or vertically depending
/// on available space, how many buttons there are and how wide they are.
///
/// By default it will prefer to stack buttons vertically at medium sizes.
///
/// Set to `TRUE` to prefer horizontal layout in these cases instead. This will
/// make the dialog slightly wider as well.
///
/// Vertical layout may still be used if the dialog would get too wide
/// otherwise.
///
/// Does nothing with just one button, or when the buttons are already
/// horizontal.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter preferWideLayout: Whether to prefer horizontal button layout.
/// - Returns: A copy of this view with the modifier applied.
public func preferWideLayout(_ preferWideLayout: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
w.setPreferWideLayout(preferWideLayout: preferWideLayout.wrappedValue)
ctx.registry.add(preferWideLayout.subscribe { [w] v in w.setPreferWideLayout(preferWideLayout: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.AlertDialog.setPreferWideLayout(preferWideLayout:)
/// Whether to prefer horizontal button layout.
///
/// `AdwAlertDialog` can present buttons horizontally or vertically depending
/// on available space, how many buttons there are and how wide they are.
///
/// By default it will prefer to stack buttons vertically at medium sizes.
///
/// Set to `TRUE` to prefer horizontal layout in these cases instead. This will
/// make the dialog slightly wider as well.
///
/// Vertical layout may still be used if the dialog would get too wide
/// otherwise.
///
/// Does nothing with just one button, or when the buttons are already
/// horizontal.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.AlertDialog.setPreferWideLayout(preferWideLayout:)`.
///
/// - Parameter preferWideLayout: Whether to prefer horizontal button layout.
/// - Returns: A copy of this view with the modifier applied.
public func preferWideLayout(_ preferWideLayout: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setPreferWideLayout(preferWideLayout: preferWideLayout()) }
tracker.run()
ctx.registry.add(tracker)
}
}
}