portico/Sources/Portico/Generated/PopoverMenu.swift

381 lines
21 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.PopoverMenu
/// A subclass of `GtkPopover` that implements menu behavior.
///
/// <picture>
/// <source srcset="menu-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkPopoverMenu" src="menu.png">
/// </picture>
///
/// `GtkPopoverMenu` treats its children like menus and allows switching
/// between them. It can open submenus as traditional, nested submenus,
/// or in a more touch-friendly sliding fashion.
/// The property [property`Gtk`.PopoverMenu:flags] controls this appearance.
///
/// `GtkPopoverMenu` is meant to be used primarily with menu models,
/// using [ctor`Gtk`.PopoverMenu.new_from_model]. If you need to put
/// other widgets such as a `GtkSpinButton` or a `GtkSwitch` into a popover,
/// you can use [method`Gtk`.PopoverMenu.add_child].
///
/// For more dialog-like behavior, use a plain `GtkPopover`.
///
/// ## Menu models
///
/// The XML format understood by `GtkBuilder` for `GMenuModel` consists
/// of a toplevel `<menu>` element, which contains one or more `<item>`
/// elements. Each `<item>` element contains `<attribute>` and `<link>`
/// elements with a mandatory name attribute. `<link>` elements have the
/// same content model as `<menu>`. Instead of `<link name="submenu">`
/// or `<link name="section">`, you can use `<submenu>` or `<section>`
/// elements.
///
/// ```xml
/// <menu id='app-menu'>
/// <section>
/// <item>
/// <attribute name='label' translatable='yes'>_New Window</attribute>
/// <attribute name='action'>app.new</attribute>
/// </item>
/// <item>
/// <attribute name='label' translatable='yes'>_About Sunny</attribute>
/// <attribute name='action'>app.about</attribute>
/// </item>
/// <item>
/// <attribute name='label' translatable='yes'>_Quit</attribute>
/// <attribute name='action'>app.quit</attribute>
/// </item>
/// </section>
/// </menu>
/// ```
///
/// Attribute values can be translated using gettext, like other `GtkBuilder`
/// content. `<attribute>` elements can be marked for translation with a
/// `translatable="yes"` attribute. It is also possible to specify message
/// context and translator comments, using the context and comments attributes.
/// To make use of this, the `GtkBuilder` must have been given the gettext
/// domain to use.
///
/// The following attributes are used when constructing menu items:
///
/// - "label": a user-visible string to display
/// - "use-markup": whether the text in the menu item includes [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)
/// - "action": the prefixed name of the action to trigger
/// - "target": the parameter to use when activating the action
/// - "icon" and "verb-icon": names of icons that may be displayed
/// - "submenu-action": name of an action that may be used to track
/// whether a submenu is open
/// - "hidden-when": a string used to determine when the item will be hidden.
/// Possible values include "action-disabled", "action-missing", "macos-menubar".
/// This is mainly useful for exported menus, see [method`Gtk`.Application.set_menubar].
/// - "custom": a string used to match against the ID of a custom child added with
/// [method`Gtk`.PopoverMenu.add_child], [method`Gtk`.PopoverMenuBar.add_child],
/// or in the ui file with `<child type="ID">`.
///
/// The following attributes are used when constructing sections:
///
/// - "label": a user-visible string to use as section heading
/// - "display-hint": a string used to determine special formatting for the section.
/// Possible values include "horizontal-buttons", "circular-buttons" and
/// "inline-buttons". They all indicate that section should be
/// displayed as a horizontal row of buttons.
/// - "text-direction": a string used to determine the `GtkTextDirection` to use
/// when "display-hint" is set to "horizontal-buttons". Possible values
/// include "rtl", "ltr", and "none".
///
/// The following attributes are used when constructing submenus:
///
/// - "label": a user-visible string to display
/// - "icon": icon name to display
/// - "gtk-macos-special": (macOS only, ignored by others) Add special meaning to a menu
/// in the macOS menu bar. See [Using GTK on Apple macOS](osx.html).
///
/// Menu items will also show accelerators, which are usually associated
/// with actions via [method`Gtk`.Application.set_accels_for_action],
/// [method`WidgetClass`.add_binding_action] or
/// [method`Gtk`.ShortcutController.add_shortcut].
///
/// # Shortcuts and Gestures
///
/// `GtkPopoverMenu` supports the following keyboard shortcuts:
///
/// - <kbd>Space</kbd> activates the default widget.
///
/// # CSS Nodes
///
/// `GtkPopoverMenu` is just a subclass of `GtkPopover` that adds custom content
/// to it, therefore it has the same CSS nodes. It is one of the cases that add
/// a `.menu` style class to the main `popover` node.
///
/// Menu items have nodes with name `button` and class `.model`. If a section
/// display-hint is set, the section gets a node `box` with class `horizontal`
/// plus a class with the same text as the display hint. Note that said box may
/// not be the direct ancestor of the item `button`s. Thus, for example, to style
/// items in an `inline-buttons` section, select `.inline-buttons button.model`.
/// Other things that may be of interest to style in menus include `label` nodes.
///
/// # Accessibility
///
/// `GtkPopoverMenu` uses the [enum`Gtk`.AccessibleRole.menu] role, and its
/// items use the [enum`Gtk`.AccessibleRole.menu_item],
/// [enum`Gtk`.AccessibleRole.checkbox] or [enum`Gtk`.AccessibleRole.menu_item_radio]
/// roles, depending on the action they are connected to.
///
/// A Portico view that mounts a `Gtk.PopoverMenu`.
@MainActor public struct PopoverMenu: View {
private let make: (MountContext) -> Gtk.PopoverMenu
private var configure: [(Gtk.PopoverMenu, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.PopoverMenu.init(model:)
/// Creates a `GtkPopoverMenu` and populates it according to `model`.
///
/// The created buttons are connected to actions found in the
/// `GtkApplicationWindow` to which the popover belongs - typically
/// by means of being attached to a widget that is contained within
/// the `GtkApplicationWindow`s widget hierarchy.
///
/// Actions can also be added using [method`Gtk`.Widget.insert_action_group]
/// on the menus attach widget or on any of its parent widgets.
///
/// This function creates menus with sliding submenus.
/// See [ctor`Gtk`.PopoverMenu.new_from_model_full] for a way
/// to control this.
///
/// 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 model: The `model` value forwarded to `Gtk.PopoverMenu`.
/// - Parameter menuModel: The model from which the menu is made.
/// - Parameter autohide: Whether to dismiss the popover on outside clicks.
/// - Parameter cascadePopdown: Whether the popover pops down after a child popover.
/// - Parameter hasArrow: Whether to draw an arrow.
/// - Parameter mnemonicsVisible: Whether mnemonics are currently visible in this popover.
/// - Parameter position: How to place the popover, relative to its parent.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivateDefault: Invoked when the widget emits the `activate-default` signal.
/// - Parameter onClosed: Invoked when the widget emits the `closed` signal.
public init(model: Gtk.MenuModel?, menuModel: Gtk.MenuModel? = nil, autohide: Bool? = nil, cascadePopdown: Bool? = nil, hasArrow: Bool? = nil, mnemonicsVisible: Bool? = nil, position: Gtk.PositionType? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivateDefault: (() -> Void)? = nil, onClosed: (() -> Void)? = nil) {
make = { _ in Gtk.PopoverMenu(model: model) }
configure.append { w, ctx in
if let menuModel { w.setMenuModel(model: menuModel) }
if let autohide { w.setAutohide(autohide: autohide) }
if let cascadePopdown { w.setCascadePopdown(cascadePopdown: cascadePopdown) }
if let hasArrow { w.setHasArrow(hasArrow: hasArrow) }
if let mnemonicsVisible { w.setMnemonicsVisible(mnemonicsVisible: mnemonicsVisible) }
if let position { w.setPosition(position: position) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivateDefault { ctx.registry.add(w.connectActivateDefault { _ in onActivateDefault() }) }
if let onClosed { ctx.registry.add(w.connectClosed { _ in onClosed() }) }
}
}
// PorticoGen: generateInits(static) | source: Gtk.PopoverMenu.init(model:flags:)
/// Creates a `GtkPopoverMenu` and populates it according to `model`.
///
/// The created buttons are connected to actions found in the
/// action groups that are accessible from the parent widget.
/// This includes the `GtkApplicationWindow` to which the popover
/// belongs. Actions can also be added using [method`Gtk`.Widget.insert_action_group]
/// on the parent widget or on any of its parent widgets.
///
/// 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 model: The `model` value forwarded to `Gtk.PopoverMenu`.
/// - Parameter flags: The flags that `popover` uses to create/display a menu from its model.
/// - Parameter menuModel: The model from which the menu is made.
/// - Parameter autohide: Whether to dismiss the popover on outside clicks.
/// - Parameter cascadePopdown: Whether the popover pops down after a child popover.
/// - Parameter hasArrow: Whether to draw an arrow.
/// - Parameter mnemonicsVisible: Whether mnemonics are currently visible in this popover.
/// - Parameter position: How to place the popover, relative to its parent.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivateDefault: Invoked when the widget emits the `activate-default` signal.
/// - Parameter onClosed: Invoked when the widget emits the `closed` signal.
public init(model: Gtk.MenuModel, flags: Gtk.PopoverMenuFlags, menuModel: Gtk.MenuModel? = nil, autohide: Bool? = nil, cascadePopdown: Bool? = nil, hasArrow: Bool? = nil, mnemonicsVisible: Bool? = nil, position: Gtk.PositionType? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivateDefault: (() -> Void)? = nil, onClosed: (() -> Void)? = nil) {
make = { _ in Gtk.PopoverMenu(model: model, flags: flags) }
configure.append { w, ctx in
if let menuModel { w.setMenuModel(model: menuModel) }
if let autohide { w.setAutohide(autohide: autohide) }
if let cascadePopdown { w.setCascadePopdown(cascadePopdown: cascadePopdown) }
if let hasArrow { w.setHasArrow(hasArrow: hasArrow) }
if let mnemonicsVisible { w.setMnemonicsVisible(mnemonicsVisible: mnemonicsVisible) }
if let position { w.setPosition(position: position) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivateDefault { ctx.registry.add(w.connectActivateDefault { _ in onActivateDefault() }) }
if let onClosed { ctx.registry.add(w.connectClosed { _ in onClosed() }) }
}
}
}
extension PopoverMenu: WidgetView {
public typealias Target = Gtk.PopoverMenu
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.PopoverMenu, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension PopoverMenu: 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.PopoverMenu
/// Modifiers for `Gtk.PopoverMenu`, available on every Portico view whose
/// backing widget is `Gtk.PopoverMenu` or one of its subclasses.
extension WidgetView where Target: Gtk.PopoverMenu {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.PopoverMenu.setFlags(flags:)
/// Sets the flags that `popover` uses to create/display a menu from its model.
///
/// If a model is set and the flags change, contents are rebuilt, so if setting
/// properties individually, set flags before model to avoid a redundant rebuild.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter flags: The flags that `popover` uses to create/display a menu from its model.
/// - Returns: A copy of this view with the modifier applied.
public func flags(_ flags: Gtk.PopoverMenuFlags) -> Self {
appending { w, _ in
w.setFlags(flags: flags)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.PopoverMenu.setFlags(flags:), GObject.Object.connectNotify(detail:_:), Gtk.PopoverMenu.getFlags()
/// Sets the flags that `popover` uses to create/display a menu from its model.
///
/// If a model is set and the flags change, contents are rebuilt, so if setting
/// properties individually, set flags before model to avoid a redundant rebuild.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.PopoverMenuFlags` 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 flags(_ flags: Portico.Binding<Gtk.PopoverMenuFlags>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, flags, registry: ctx.registry, notifyDetail: "flags",
read: { [w] in w.getFlags() },
write: { [w] v in w.setFlags(flags: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.PopoverMenu.setFlags(flags:)
/// Sets the flags that `popover` uses to create/display a menu from its model.
///
/// If a model is set and the flags change, contents are rebuilt, so if setting
/// properties individually, set flags before model to avoid a redundant rebuild.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.PopoverMenu.setFlags(flags:)`.
///
/// - Parameter flags: The flags that `popover` uses to create/display a menu from its model.
/// - Returns: A copy of this view with the modifier applied.
public func flags(_ flags: @escaping () -> Gtk.PopoverMenuFlags) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setFlags(flags: flags()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.PopoverMenu.setMenuModel(model:)
/// Sets a new menu model on `popover`.
///
/// The existing contents of `popover` are removed, and
/// the `popover` is populated with new contents according
/// to `model`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter menuModel: The model from which the menu is made.
/// - Returns: A copy of this view with the modifier applied.
public func menuModel(_ menuModel: Gtk.MenuModel?) -> Self {
appending { w, _ in
w.setMenuModel(model: menuModel)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.PopoverMenu.setMenuModel(model:), GObject.Object.connectNotify(detail:_:), Gtk.PopoverMenu.getMenuModel()
/// Sets a new menu model on `popover`.
///
/// The existing contents of `popover` are removed, and
/// the `popover` is populated with new contents according
/// to `model`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.MenuModel?` 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 menuModel(_ menuModel: Portico.Binding<Gtk.MenuModel?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, menuModel, registry: ctx.registry, notifyDetail: "menu-model",
read: { [w] in w.getMenuModel() },
write: { [w] v in w.setMenuModel(model: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.PopoverMenu.setMenuModel(model:), GObject.Object.connectNotify(detail:_:), Gtk.PopoverMenu.getMenuModel()
/// Sets a new menu model on `popover`.
///
/// The existing contents of `popover` are removed, and
/// the `popover` is populated with new contents according
/// to `model`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Gtk.MenuModel>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.MenuModel?>` to be able to clear the property.
/// When `Gtk.MenuModel` 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 menuModel(_ menuModel: Portico.Binding<Gtk.MenuModel>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, menuModel, registry: ctx.registry, notifyDetail: "menu-model",
read: { [w] in w.getMenuModel() },
write: { [w] v in w.setMenuModel(model: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.PopoverMenu.setMenuModel(model:)
/// Sets a new menu model on `popover`.
///
/// The existing contents of `popover` are removed, and
/// the `popover` is populated with new contents according
/// to `model`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.PopoverMenu.setMenuModel(model:)`.
///
/// - Parameter menuModel: The model from which the menu is made.
/// - Returns: A copy of this view with the modifier applied.
public func menuModel(_ menuModel: @escaping () -> Gtk.MenuModel?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setMenuModel(model: menuModel()) }
tracker.run()
ctx.registry.add(tracker)
}
}
}