portico/Sources/Portico/Generated/Viewport.swift

211 lines
11 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.Viewport
/// Implements scrollability for widgets that don't support scrolling
/// on their own.
///
/// Use `GtkViewport` to scroll child widgets such as `GtkGrid`,
/// `GtkBox`, and so on.
///
/// The `GtkViewport` will start scrolling content only if allocated
/// less than the child widgets minimum size in a given orientation.
///
/// # CSS nodes
///
/// `GtkViewport` has a single CSS node with name `viewport`.
///
/// # Accessibility
///
/// Until GTK 4.10, `GtkViewport` used the [enum`Gtk`.AccessibleRole.group] role.
///
/// Starting from GTK 4.12, `GtkViewport` uses the [enum`Gtk`.AccessibleRole.generic] role.
///
/// A Portico view that mounts a `Gtk.Viewport`.
@MainActor public struct Viewport: View {
private let make: (MountContext) -> Gtk.Viewport
private var configure: [(Gtk.Viewport, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.Viewport.init(hadjustment:vadjustment:)
/// Creates a new `GtkViewport`.
///
/// The new viewport uses the given adjustments, or default
/// adjustments if none are given.
///
/// 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 hadjustment: The `hadjustment` value forwarded to `Gtk.Viewport`.
/// - Parameter vadjustment: The `vadjustment` value forwarded to `Gtk.Viewport`.
/// - Parameter scrollToFocus: Whether to scroll when the focus changes.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
public init(hadjustment: Gtk.Adjustment?, vadjustment: Gtk.Adjustment?, scrollToFocus: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }) {
make = { _ in Gtk.Viewport(hadjustment: hadjustment, vadjustment: vadjustment) }
configure.append { w, ctx in
if let scrollToFocus { w.setScrollToFocus(scrollToFocus: scrollToFocus) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
}
}
}
extension Viewport: WidgetView {
public typealias Target = Gtk.Viewport
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.Viewport, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension Viewport: 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.Viewport
/// Modifiers for `Gtk.Viewport`, available on every Portico view whose
/// backing widget is `Gtk.Viewport` or one of its subclasses.
extension WidgetView where Target: Gtk.Viewport {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.Viewport.setChild(child:)
/// Sets the child widget of `viewport`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter child: The 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.Viewport.setChild(child:)
/// Sets the child widget of `viewport`.
///
/// 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 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.Viewport.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.Viewport.getChild()
/// Sets the child widget of `viewport`.
///
/// 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.Viewport.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.Viewport.getChild()
/// Sets the child widget of `viewport`.
///
/// 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.Viewport.setChild(child:)
/// Sets the child widget of `viewport`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Viewport.setChild(child:)`.
///
/// - Parameter child: The 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 -> generatePropertyModifiers(static) | source: Gtk.Viewport.setScrollToFocus(scrollToFocus:)
/// Sets whether the viewport should automatically scroll
/// to keep the focused child in view.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter scrollToFocus: Whether to scroll when the focus changes.
/// - Returns: A copy of this view with the modifier applied.
public func scrollToFocus(_ scrollToFocus: Bool) -> Self {
appending { w, _ in
w.setScrollToFocus(scrollToFocus: scrollToFocus)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.Viewport.setScrollToFocus(scrollToFocus:), GObject.Object.connectNotify(detail:_:), Gtk.Viewport.getScrollToFocus()
/// Sets whether the viewport should automatically scroll
/// to keep the focused child in view.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` 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 scrollToFocus(_ scrollToFocus: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, scrollToFocus, registry: ctx.registry, notifyDetail: "scroll-to-focus",
read: { [w] in w.getScrollToFocus() },
write: { [w] v in w.setScrollToFocus(scrollToFocus: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.Viewport.setScrollToFocus(scrollToFocus:)
/// Sets whether the viewport should automatically scroll
/// to keep the focused child in view.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.Viewport.setScrollToFocus(scrollToFocus:)`.
///
/// - Parameter scrollToFocus: Whether to scroll when the focus changes.
/// - Returns: A copy of this view with the modifier applied.
public func scrollToFocus(_ scrollToFocus: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setScrollToFocus(scrollToFocus: scrollToFocus()) }
tracker.run()
ctx.registry.add(tracker)
}
}
}