portico/Sources/Portico/Generated/PopoverMenuBar.swift

157 lines
7.1 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.PopoverMenuBar
/// Presents a horizontal bar of items that pop up menus when clicked.
///
/// <picture>
/// <source srcset="menubar-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkPopoverMenuBar" src="menubar.png">
/// </picture>
///
/// The only way to create instances of `GtkPopoverMenuBar` is
/// from a `GMenuModel`.
///
/// # CSS nodes
///
/// ```
/// menubar
/// item[.active]
/// popover
/// item
/// popover
/// ```
///
/// `GtkPopoverMenuBar` has a single CSS node with name menubar, below which
/// each item has its CSS node, and below that the corresponding popover.
///
/// The item whose popover is currently open gets the .active
/// style class.
///
/// # Accessibility
///
/// `GtkPopoverMenuBar` uses the [enum`Gtk`.AccessibleRole.menu_bar] role,
/// the menu items use the [enum`Gtk`.AccessibleRole.menu_item] role and
/// the menus use the [enum`Gtk`.AccessibleRole.menu] role.
///
/// A Portico view that mounts a `Gtk.PopoverMenuBar`.
@MainActor public struct PopoverMenuBar: View {
private let make: (MountContext) -> Gtk.PopoverMenuBar
private var configure: [(Gtk.PopoverMenuBar, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.PopoverMenuBar.init(model:)
/// Creates a `GtkPopoverMenuBar` from a `GMenuModel`.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// 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.PopoverMenuBar`.
/// - Parameter menuModel: The `GMenuModel` from which the menu bar is created.
public init(model: Gtk.MenuModel?, menuModel: Gtk.MenuModel? = nil) {
make = { _ in Gtk.PopoverMenuBar(model: model) }
configure.append { w, _ in
if let menuModel { w.setMenuModel(model: menuModel) }
}
}
}
extension PopoverMenuBar: WidgetView {
public typealias Target = Gtk.PopoverMenuBar
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.PopoverMenuBar, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension PopoverMenuBar: 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.PopoverMenuBar
/// Modifiers for `Gtk.PopoverMenuBar`, available on every Portico view whose
/// backing widget is `Gtk.PopoverMenuBar` or one of its subclasses.
extension WidgetView where Target: Gtk.PopoverMenuBar {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.PopoverMenuBar.setMenuModel(model:)
/// Sets a menu model from which `bar` should take
/// its contents.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter menuModel: The `GMenuModel` from which the menu bar is created.
/// - 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.PopoverMenuBar.setMenuModel(model:), GObject.Object.connectNotify(detail:_:), Gtk.PopoverMenuBar.getMenuModel()
/// Sets a menu model from which `bar` should take
/// its contents.
///
/// 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.PopoverMenuBar.setMenuModel(model:), GObject.Object.connectNotify(detail:_:), Gtk.PopoverMenuBar.getMenuModel()
/// Sets a menu model from which `bar` should take
/// its contents.
///
/// 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.PopoverMenuBar.setMenuModel(model:)
/// Sets a menu model from which `bar` should take
/// its contents.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.PopoverMenuBar.setMenuModel(model:)`.
///
/// - Parameter menuModel: The `GMenuModel` from which the menu bar is created.
/// - 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)
}
}
}