portico/Sources/Portico/Generated/Carousel.swift

505 lines
26 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: Adw.Carousel
/// A paginated scrolling widget.
///
/// <picture>
/// <source srcset="carousel-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="carousel.png" alt="carousel">
/// </picture>
///
/// The `AdwCarousel` widget can be used to display a set of pages with
/// swipe-based navigation between them.
///
/// [class`CarouselIndicatorDots`] and [class`CarouselIndicatorLines`] can be used
/// to provide page indicators for `AdwCarousel`.
///
/// ## CSS nodes
///
/// `AdwCarousel` has a single CSS node with name `carousel`.
///
/// A Portico view that mounts a `Adw.Carousel`.
@MainActor public struct Carousel: View {
private let make: (MountContext) -> Adw.Carousel
private var configure: [(Adw.Carousel, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Adw.Carousel.init()
/// Creates a new `AdwCarousel`.
///
/// 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.
/// A `ForEach` in the `children:` closure spreads its rows directly into this widget, with no wrapper, when the widget supports ordered insertion.
/// 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 allowLongSwipes: Whether to allow swiping for more than one page at a time.
/// - Parameter allowMouseDrag: Sets whether the `AdwCarousel` can be dragged with mouse pointer.
/// - Parameter allowScrollWheel: Whether the widget will respond to scroll wheel events.
/// - Parameter interactive: Whether the carousel can be navigated.
/// - Parameter revealDuration: Page reveal duration, in milliseconds.
/// - Parameter scrollParams: Scroll animation spring parameters.
/// - Parameter spacing: Spacing between pages in pixels.
/// - Parameter children: A `ViewBuilder` closure whose views are added in order.
/// - Parameter onPageChanged: Invoked when the widget emits the `page-changed` signal. The closure receives the signal's arguments in order.
public init(allowLongSwipes: Bool? = nil, allowMouseDrag: Bool? = nil, allowScrollWheel: Bool? = nil, interactive: Bool? = nil, revealDuration: UInt32? = nil, scrollParams: Adw.SpringParams? = nil, spacing: UInt32? = nil, @ViewBuilder children: @escaping () -> [AnyView] = { [] }, onPageChanged: ((UInt32) -> Void)? = nil) {
make = { _ in Adw.Carousel() }
configure.append { w, ctx in
if let allowLongSwipes { w.setAllowLongSwipes(allowLongSwipes: allowLongSwipes) }
if let allowMouseDrag { w.setAllowMouseDrag(allowMouseDrag: allowMouseDrag) }
if let allowScrollWheel { w.setAllowScrollWheel(allowScrollWheel: allowScrollWheel) }
if let interactive { w.setInteractive(interactive: interactive) }
if let revealDuration { w.setRevealDuration(revealDuration: revealDuration) }
if let scrollParams { w.setScrollParams(params: scrollParams) }
if let spacing { w.setSpacing(spacing: spacing) }
Portico.mountChildren(children, into: w, ctx) { c in w.append(child: c) }
if let onPageChanged { ctx.registry.add(w.connectPageChanged { _, a0 in onPageChanged(a0) }) }
}
}
}
extension Carousel: WidgetView {
public typealias Target = Adw.Carousel
@_spi(Portico) public func appending(
_ step: @escaping (Adw.Carousel, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension Carousel: 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: Adw.Carousel
/// Modifiers for `Adw.Carousel`, available on every Portico view whose
/// backing widget is `Adw.Carousel` or one of its subclasses.
extension WidgetView where Target: Adw.Carousel {
// PorticoGen: generateModifierExtension -> generateChildAdderModifiers(static) | source: Adw.Carousel.append(child:)
/// Appends `child` to `self`.
///
/// 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 append(_ child: Gtk.Widget) -> Self {
appending { w, _ in
w.append(child: child)
}
}
// PorticoGen: generateModifierExtension -> generateChildAdderModifiers(viewBuilder) | source: Adw.Carousel.append(child:)
/// Appends `child` to `self`.
///
/// 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 append(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
for v in childViews { w.append(child: v.makeWidget(ctx)) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Carousel.setAllowLongSwipes(allowLongSwipes:)
/// Sets whether to allow swiping for more than one page at a time.
///
/// If `allow_long_swipes` is `FALSE`, each swipe can only move to the adjacent
/// pages.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter allowLongSwipes: Whether to allow swiping for more than one page at a time.
/// - Returns: A copy of this view with the modifier applied.
public func allowLongSwipes(_ allowLongSwipes: Bool) -> Self {
appending { w, _ in
w.setAllowLongSwipes(allowLongSwipes: allowLongSwipes)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Carousel.setAllowLongSwipes(allowLongSwipes:), GObject.Object.connectNotify(detail:_:), Adw.Carousel.getAllowLongSwipes()
/// Sets whether to allow swiping for more than one page at a time.
///
/// If `allow_long_swipes` is `FALSE`, each swipe can only move to the adjacent
/// pages.
///
/// 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 allowLongSwipes(_ allowLongSwipes: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, allowLongSwipes, registry: ctx.registry, notifyDetail: "allow-long-swipes",
read: { [w] in w.getAllowLongSwipes() },
write: { [w] v in w.setAllowLongSwipes(allowLongSwipes: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Carousel.setAllowLongSwipes(allowLongSwipes:)
/// Sets whether to allow swiping for more than one page at a time.
///
/// If `allow_long_swipes` is `FALSE`, each swipe can only move to the adjacent
/// pages.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Carousel.setAllowLongSwipes(allowLongSwipes:)`.
///
/// - Parameter allowLongSwipes: Whether to allow swiping for more than one page at a time.
/// - Returns: A copy of this view with the modifier applied.
public func allowLongSwipes(_ allowLongSwipes: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setAllowLongSwipes(allowLongSwipes: allowLongSwipes()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Carousel.setAllowMouseDrag(allowMouseDrag:)
/// Sets whether `self` can be dragged with mouse pointer.
///
/// If `allow_mouse_drag` is `FALSE`, dragging is only available on touch.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter allowMouseDrag: Sets whether the `AdwCarousel` can be dragged with mouse pointer.
/// - Returns: A copy of this view with the modifier applied.
public func allowMouseDrag(_ allowMouseDrag: Bool) -> Self {
appending { w, _ in
w.setAllowMouseDrag(allowMouseDrag: allowMouseDrag)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Carousel.setAllowMouseDrag(allowMouseDrag:), GObject.Object.connectNotify(detail:_:), Adw.Carousel.getAllowMouseDrag()
/// Sets whether `self` can be dragged with mouse pointer.
///
/// If `allow_mouse_drag` is `FALSE`, dragging is only available on touch.
///
/// 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 allowMouseDrag(_ allowMouseDrag: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, allowMouseDrag, registry: ctx.registry, notifyDetail: "allow-mouse-drag",
read: { [w] in w.getAllowMouseDrag() },
write: { [w] v in w.setAllowMouseDrag(allowMouseDrag: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Carousel.setAllowMouseDrag(allowMouseDrag:)
/// Sets whether `self` can be dragged with mouse pointer.
///
/// If `allow_mouse_drag` is `FALSE`, dragging is only available on touch.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Carousel.setAllowMouseDrag(allowMouseDrag:)`.
///
/// - Parameter allowMouseDrag: Sets whether the `AdwCarousel` can be dragged with mouse pointer.
/// - Returns: A copy of this view with the modifier applied.
public func allowMouseDrag(_ allowMouseDrag: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setAllowMouseDrag(allowMouseDrag: allowMouseDrag()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Carousel.setAllowScrollWheel(allowScrollWheel:)
/// Sets whether `self` will respond to scroll wheel events.
///
/// If `allow_scroll_wheel` is `FALSE`, wheel events will be ignored.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter allowScrollWheel: Whether the widget will respond to scroll wheel events.
/// - Returns: A copy of this view with the modifier applied.
public func allowScrollWheel(_ allowScrollWheel: Bool) -> Self {
appending { w, _ in
w.setAllowScrollWheel(allowScrollWheel: allowScrollWheel)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Carousel.setAllowScrollWheel(allowScrollWheel:), GObject.Object.connectNotify(detail:_:), Adw.Carousel.getAllowScrollWheel()
/// Sets whether `self` will respond to scroll wheel events.
///
/// If `allow_scroll_wheel` is `FALSE`, wheel events will be ignored.
///
/// 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 allowScrollWheel(_ allowScrollWheel: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, allowScrollWheel, registry: ctx.registry, notifyDetail: "allow-scroll-wheel",
read: { [w] in w.getAllowScrollWheel() },
write: { [w] v in w.setAllowScrollWheel(allowScrollWheel: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Carousel.setAllowScrollWheel(allowScrollWheel:)
/// Sets whether `self` will respond to scroll wheel events.
///
/// If `allow_scroll_wheel` is `FALSE`, wheel events will be ignored.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Carousel.setAllowScrollWheel(allowScrollWheel:)`.
///
/// - Parameter allowScrollWheel: Whether the widget will respond to scroll wheel events.
/// - Returns: A copy of this view with the modifier applied.
public func allowScrollWheel(_ allowScrollWheel: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setAllowScrollWheel(allowScrollWheel: allowScrollWheel()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Carousel.setInteractive(interactive:)
/// Sets whether `self` can be navigated.
///
/// This can be used to temporarily disable the carousel to only allow navigating
/// it in a certain state.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter interactive: Whether the carousel can be navigated.
/// - Returns: A copy of this view with the modifier applied.
public func interactive(_ interactive: Bool) -> Self {
appending { w, _ in
w.setInteractive(interactive: interactive)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Carousel.setInteractive(interactive:), GObject.Object.connectNotify(detail:_:), Adw.Carousel.getInteractive()
/// Sets whether `self` can be navigated.
///
/// This can be used to temporarily disable the carousel to only allow navigating
/// it in a certain state.
///
/// 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 interactive(_ interactive: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, interactive, registry: ctx.registry, notifyDetail: "interactive",
read: { [w] in w.getInteractive() },
write: { [w] v in w.setInteractive(interactive: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Carousel.setInteractive(interactive:)
/// Sets whether `self` can be navigated.
///
/// This can be used to temporarily disable the carousel to only allow navigating
/// it in a certain state.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Carousel.setInteractive(interactive:)`.
///
/// - Parameter interactive: Whether the carousel can be navigated.
/// - Returns: A copy of this view with the modifier applied.
public func interactive(_ interactive: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setInteractive(interactive: interactive()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Carousel.setRevealDuration(revealDuration:)
/// Sets the page reveal duration, in milliseconds.
///
/// Reveal duration is used when animating adding or removing pages.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter revealDuration: Page reveal duration, in milliseconds.
/// - Returns: A copy of this view with the modifier applied.
public func revealDuration(_ revealDuration: UInt32) -> Self {
appending { w, _ in
w.setRevealDuration(revealDuration: revealDuration)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Carousel.setRevealDuration(revealDuration:), GObject.Object.connectNotify(detail:_:), Adw.Carousel.getRevealDuration()
/// Sets the page reveal duration, in milliseconds.
///
/// Reveal duration is used when animating adding or removing pages.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `UInt32` 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 revealDuration(_ revealDuration: Portico.Binding<UInt32>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, revealDuration, registry: ctx.registry, notifyDetail: "reveal-duration",
read: { [w] in w.getRevealDuration() },
write: { [w] v in w.setRevealDuration(revealDuration: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Carousel.setRevealDuration(revealDuration:)
/// Sets the page reveal duration, in milliseconds.
///
/// Reveal duration is used when animating adding or removing pages.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Carousel.setRevealDuration(revealDuration:)`.
///
/// - Parameter revealDuration: Page reveal duration, in milliseconds.
/// - Returns: A copy of this view with the modifier applied.
public func revealDuration(_ revealDuration: @escaping () -> UInt32) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setRevealDuration(revealDuration: revealDuration()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Carousel.setScrollParams(params:)
/// Sets the scroll animation spring parameters for `self`.
///
/// The default value is equivalent to:
///
/// ```c
/// adw_spring_params_new (1, 0.5, 500)
/// ```
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter scrollParams: Scroll animation spring parameters.
/// - Returns: A copy of this view with the modifier applied.
public func scrollParams(_ scrollParams: Adw.SpringParams) -> Self {
appending { w, _ in
w.setScrollParams(params: scrollParams)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Carousel.setScrollParams(params:), GObject.Object.connectNotify(detail:_:), Adw.Carousel.getScrollParams()
/// Sets the scroll animation spring parameters for `self`.
///
/// The default value is equivalent to:
///
/// ```c
/// adw_spring_params_new (1, 0.5, 500)
/// ```
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.SpringParams` 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 scrollParams(_ scrollParams: Portico.Binding<Adw.SpringParams>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, scrollParams, registry: ctx.registry, notifyDetail: "scroll-params",
read: { [w] in w.getScrollParams() },
write: { [w] v in w.setScrollParams(params: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Carousel.setScrollParams(params:)
/// Sets the scroll animation spring parameters for `self`.
///
/// The default value is equivalent to:
///
/// ```c
/// adw_spring_params_new (1, 0.5, 500)
/// ```
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Carousel.setScrollParams(params:)`.
///
/// - Parameter scrollParams: Scroll animation spring parameters.
/// - Returns: A copy of this view with the modifier applied.
public func scrollParams(_ scrollParams: @escaping () -> Adw.SpringParams) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setScrollParams(params: scrollParams()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.Carousel.setSpacing(spacing:)
/// Sets spacing between pages in pixels.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter spacing: Spacing between pages in pixels.
/// - Returns: A copy of this view with the modifier applied.
public func spacing(_ spacing: UInt32) -> Self {
appending { w, _ in
w.setSpacing(spacing: spacing)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Adw.Carousel.setSpacing(spacing:), GObject.Object.connectNotify(detail:_:), Adw.Carousel.getSpacing()
/// Sets spacing between pages in pixels.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `UInt32` 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 spacing(_ spacing: Portico.Binding<UInt32>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, spacing, registry: ctx.registry, notifyDetail: "spacing",
read: { [w] in w.getSpacing() },
write: { [w] v in w.setSpacing(spacing: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.Carousel.setSpacing(spacing:)
/// Sets spacing between pages in pixels.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.Carousel.setSpacing(spacing:)`.
///
/// - Parameter spacing: Spacing between pages in pixels.
/// - Returns: A copy of this view with the modifier applied.
public func spacing(_ spacing: @escaping () -> UInt32) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setSpacing(spacing: spacing()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.Carousel.connectPageChanged(_:)
/// This signal is emitted after a page has been changed.
///
/// It can be used to implement "infinite scrolling" by amending the pages
/// after every scroll.
///
/// ::: note
/// An empty carousel is indicated by `(int)index == -1`.
///
/// - Parameter handler: Invoked when the widget emits the `page-changed` signal. The closure receives the signal's arguments in order.
/// - Returns: A copy of this view with the modifier applied.
public func onPageChanged(_ handler: @escaping (UInt32) -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectPageChanged { _, a0 in handler(a0) })
}
}
}