portico/Sources/Portico/Generated/Overlay.swift

239 lines
12 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.Overlay
/// Places overlay widgets on top of a single main child.
///
/// <picture>
/// <source srcset="overlay-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkOverlay" src="overlay.png">
/// </picture>
///
/// The position of each overlay widget is determined by its
/// [property`Gtk`.Widget:halign] and [property`Gtk`.Widget:valign]
/// properties. E.g. a widget with both alignments set to `GTK_ALIGN_START`
/// will be placed at the top left corner of the `GtkOverlay` container,
/// whereas an overlay with halign set to `GTK_ALIGN_CENTER` and valign set
/// to `GTK_ALIGN_END` will be placed a the bottom edge of the `GtkOverlay`,
/// horizontally centered. The position can be adjusted by setting the margin
/// properties of the child to non-zero values.
///
/// More complicated placement of overlays is possible by connecting
/// to the [signal`Gtk`.Overlay::get-child-position] signal.
///
/// An overlays minimum and natural sizes are those of its main child.
/// The sizes of overlay children are not considered when measuring these
/// preferred sizes.
///
/// # GtkOverlay as GtkBuildable
///
/// The `GtkOverlay` implementation of the `GtkBuildable` interface
/// supports placing a child as an overlay by specifying overlay as
/// the type attribute of a `<child>` element.
///
/// # CSS nodes
///
/// `GtkOverlay` has a single CSS node with the name overlay. Overlay children
/// whose alignments cause them to be positioned at an edge get the style classes
/// .left, .right, .top, and/or .bottom according to their position.
///
/// A Portico view that mounts a `Gtk.Overlay`.
@MainActor public struct Overlay: View {
private let make: (MountContext) -> Gtk.Overlay
private var configure: [(Gtk.Overlay, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.Overlay.init()
/// Creates a new `GtkOverlay`.
///
/// 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 child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onGetChildPosition: Invoked when the widget emits the `get-child-position` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
public init(@ViewBuilder child: @escaping () -> [AnyView] = { [] }, onGetChildPosition: ((Gtk.Widget, Gdk.Rectangle) -> Bool)? = nil) {
make = { _ in Gtk.Overlay() }
configure.append { w, ctx in
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onGetChildPosition { ctx.registry.add(w.connectGetChildPosition { _, a0, a1 in onGetChildPosition(a0, a1) }) }
}
}
}
extension Overlay: WidgetView {
public typealias Target = Gtk.Overlay
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.Overlay, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension Overlay: 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.Overlay
/// Modifiers for `Gtk.Overlay`, available on every Portico view whose
/// backing widget is `Gtk.Overlay` or one of its subclasses.
extension WidgetView where Target: Gtk.Overlay {
// PorticoGen: generateModifierExtension -> generateChildAdderModifiers(static) | source: Gtk.Overlay.addOverlay(widget:)
/// Adds `widget` to `overlay`.
///
/// The widget will be stacked on top of the main widget
/// added with [method`Gtk`.Overlay.set_child].
///
/// The position at which `widget` is placed is determined
/// from its [property`Gtk`.Widget:halign] and
/// [property`Gtk`.Widget:valign] properties.
///
/// 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 addOverlay(_ child: Gtk.Widget) -> Self {
appending { w, _ in
w.addOverlay(widget: child)
}
}
// PorticoGen: generateModifierExtension -> generateChildAdderModifiers(viewBuilder) | source: Gtk.Overlay.addOverlay(widget:)
/// Adds `widget` to `overlay`.
///
/// The widget will be stacked on top of the main widget
/// added with [method`Gtk`.Overlay.set_child].
///
/// The position at which `widget` is placed is determined
/// from its [property`Gtk`.Widget:halign] and
/// [property`Gtk`.Widget:valign] properties.
///
/// 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 addOverlay(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
for v in childViews { w.addOverlay(widget: v.makeWidget(ctx)) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Overlay.setChild(child:)
/// Sets the child widget of `overlay`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter child: The main child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: Gtk.Widget?) -> Self {
appending { w, _ in
w.setChild(child: child)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Gtk.Overlay.setChild(child:)
/// Sets the child widget of `overlay`.
///
/// 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 child: The main child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
guard let v = childViews.first else { return }
w.setChild(child: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Overlay.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.Overlay.getChild()
/// Sets the child widget of `overlay`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.Widget?` 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 child<W: Gtk.Widget>(_ child: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.Overlay.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.Overlay.getChild()
/// Sets the child widget of `overlay`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Gtk.Widget>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.Widget?>` to be able to clear the property.
/// When `Gtk.Widget` 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 child<W: Gtk.Widget>(_ child: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Overlay.setChild(child:)
/// Sets the child widget of `overlay`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Overlay.setChild(child:)`.
///
/// - Parameter child: The main child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: @escaping () -> Gtk.Widget?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setChild(child: child()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.Overlay.connectGetChildPosition(_:)
/// Emitted to determine the position and size of any overlay
/// child widgets.
///
/// A handler for this signal should fill `allocation` with
/// the desired position and size for `widget`, relative to
/// the 'main' child of `overlay`.
///
/// The default handler for this signal uses the `widget`'s
/// halign and valign properties to determine the position
/// and gives the widget its natural size (except that an
/// alignment of `GTK_ALIGN_FILL` will cause the overlay to
/// be full-width/height). If the main child is a
/// `GtkScrolledWindow`, the overlays are placed relative
/// to its contents.
///
/// - Parameter handler: Invoked when the widget emits the `get-child-position` signal. The closure receives the signal's arguments in order. Its return value is forwarded to GTK as the signal's result.
/// - Returns: A copy of this view with the modifier applied.
public func onGetChildPosition(_ handler: @escaping (Gtk.Widget, Gdk.Rectangle) -> Bool) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectGetChildPosition { _, a0, a1 in handler(a0, a1) })
}
}
}