153 lines
7.4 KiB
Swift
153 lines
7.4 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.DragIcon
|
|
/// A `GtkRoot` implementation for drag icons.
|
|
///
|
|
/// A drag icon moves with the pointer during a Drag-and-Drop operation
|
|
/// and is destroyed when the drag ends.
|
|
///
|
|
/// To set up a drag icon and associate it with an ongoing drag operation,
|
|
/// use [ctor`Gtk`.DragIcon.get_for_drag] to get the icon for a drag. You can
|
|
/// then use it like any other widget and use [method`Gtk`.DragIcon.set_child]
|
|
/// to set whatever widget should be used for the drag icon.
|
|
///
|
|
/// Keep in mind that drag icons do not allow user input.
|
|
///
|
|
/// A Portico view that mounts a `Gtk.DragIcon`.
|
|
@MainActor public struct DragIcon: View {
|
|
private let make: (MountContext) -> Gtk.DragIcon
|
|
private var configure: [(Gtk.DragIcon, MountContext) -> Void] = []
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
// PorticoGen: generateInits(static) | source: Gtk.DragIcon.init(drag:)
|
|
/// Gets the `GtkDragIcon` in use with `drag`.
|
|
///
|
|
/// If no drag icon exists yet, a new one will be created
|
|
/// and shown.
|
|
///
|
|
/// 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 drag: The `drag` value forwarded to `Gtk.DragIcon`.
|
|
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
|
|
public init(drag: Gtk.Drag, @ViewBuilder child: @escaping () -> [AnyView] = { [] }) {
|
|
make = { _ in Gtk.DragIcon(drag: drag) }
|
|
configure.append { w, ctx in
|
|
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension DragIcon: WidgetView {
|
|
public typealias Target = Gtk.DragIcon
|
|
|
|
@_spi(Portico) public func appending(
|
|
_ step: @escaping (Gtk.DragIcon, MountContext) -> Void
|
|
) -> Self {
|
|
var c = self
|
|
c.configure.append(step)
|
|
return c
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension DragIcon: 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.DragIcon
|
|
/// Modifiers for `Gtk.DragIcon`, available on every Portico view whose
|
|
/// backing widget is `Gtk.DragIcon` or one of its subclasses.
|
|
extension WidgetView where Target: Gtk.DragIcon {
|
|
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.DragIcon.setChild(child:)
|
|
/// Sets the widget to display as the drag icon.
|
|
///
|
|
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
|
|
///
|
|
/// - Parameter child: The widget to display as drag icon.
|
|
/// - 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.DragIcon.setChild(child:)
|
|
/// Sets the widget to display as the drag icon.
|
|
///
|
|
/// 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 widget to display as drag icon.
|
|
/// - 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.DragIcon.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.DragIcon.getChild()
|
|
/// Sets the widget to display as the drag icon.
|
|
///
|
|
/// 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.DragIcon.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.DragIcon.getChild()
|
|
/// Sets the widget to display as the drag icon.
|
|
///
|
|
/// 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.DragIcon.setChild(child:)
|
|
/// Sets the widget to display as the drag icon.
|
|
///
|
|
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.DragIcon.setChild(child:)`.
|
|
///
|
|
/// - Parameter child: The widget to display as drag icon.
|
|
/// - 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)
|
|
}
|
|
}
|
|
|
|
}
|