portico/Sources/Portico/Generated/TabButton.swift

159 lines
6.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: Adw.TabButton
/// A button that displays the number of [class`TabView`] pages.
///
/// <picture>
/// <source srcset="tab-button-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="tab-button.png" alt="tab-button">
/// </picture>
///
/// `AdwTabButton` is a button that displays the number of pages in a given
/// `AdwTabView`, as well as whether one of the inactive pages needs attention.
///
/// It's intended to be used as a visible indicator when there's no visible tab
/// bar, typically opening an [class`TabOverview`] on click, e.g. via the
/// `overview.open` action name:
///
/// ```xml
/// <object class="AdwTabButton">
/// <property name="view">view</property>
/// <property name="action-name">overview.open</property>
/// </object>
/// ```
///
/// ## CSS nodes
///
/// `AdwTabButton` has a main CSS node with name `tabbutton`.
///
/// # Accessibility
///
/// `AdwTabButton` uses the [enum`Gtk`.AccessibleRole.button] role.
///
/// A Portico view that mounts a `Adw.TabButton`.
@MainActor public struct TabButton: View {
private let make: (MountContext) -> Adw.TabButton
private var configure: [(Adw.TabButton, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateStruct -> generateInits(noArg) | source: Adw.TabButton.init()
/// Creates a new `AdwTabButton`.
public init() {
make = { _ in Adw.TabButton() }
}
}
extension TabButton: WidgetView {
public typealias Target = Adw.TabButton
@_spi(Portico) public func appending(
_ step: @escaping (Adw.TabButton, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension TabButton: 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.TabButton
/// Modifiers for `Adw.TabButton`, available on every Portico view whose
/// backing widget is `Adw.TabButton` or one of its subclasses.
extension WidgetView where Target: Adw.TabButton {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Adw.TabButton.setView(view:)
/// Sets the tab view to display.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter view: The view the tab button displays.
/// - Returns: A copy of this view with the modifier applied.
public func view(_ view: Adw.TabView?) -> Self {
appending { w, _ in
w.setView(view: view)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(oneWay) | source: Adw.TabButton.setView(view:)
/// Sets the tab view to display.
///
/// Applied at mount and re-applied on every change the binding publishes.
///
/// - Parameter view: The view the tab button displays.
/// - Returns: A copy of this view with the modifier applied.
public func view(_ view: Portico.Binding<Adw.TabView?>) -> Self {
appending { w, ctx in
w.setView(view: view.wrappedValue)
ctx.registry.add(view.subscribe { [w] v in w.setView(view: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted) | source: Adw.TabButton.setView(view:)
/// Sets the tab view to display.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Adw.TabView>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Adw.TabView?>` to be able to clear the property.
///
/// - Parameter view: The view the tab button displays.
/// - Returns: A copy of this view with the modifier applied.
public func view(_ view: Portico.Binding<Adw.TabView>) -> Self {
appending { w, ctx in
w.setView(view: view.wrappedValue)
ctx.registry.add(view.subscribe { [w] v in w.setView(view: v) })
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Adw.TabButton.setView(view:)
/// Sets the tab view to display.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Adw.TabButton.setView(view:)`.
///
/// - Parameter view: The view the tab button displays.
/// - Returns: A copy of this view with the modifier applied.
public func view(_ view: @escaping () -> Adw.TabView?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setView(view: view()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.TabButton.connectActivate(_:)
/// Emitted to animate press then release.
///
/// This is an action signal. Applications should never connect to this signal,
/// but use the [signal`TabButton`::clicked] signal.
///
/// - Parameter handler: Invoked when the widget emits the `activate` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onActivate(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectActivate { _ in handler() })
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Adw.TabButton.connectClicked(_:)
/// Emitted when the button has been activated (pressed and released).
///
/// - Parameter handler: Invoked when the widget emits the `clicked` signal.
/// - Returns: A copy of this view with the modifier applied.
public func onClicked(_ handler: @escaping () -> Void) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectClicked { _ in handler() })
}
}
}