portico/Sources/Portico/Generated/TabButton.swift

178 lines
8 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: generateInits(static) | source: Adw.TabButton.init()
/// Creates a new `AdwTabButton`.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// 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 view: The view the tab button displays.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(view: Adw.TabView? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Adw.TabButton() }
configure.append { w, ctx in
if let view { w.setView(view: view) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
}
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(twoWay) | source: Adw.TabButton.setView(view:), GObject.Object.connectNotify(detail:_:), Adw.TabButton.getView()
/// Sets the tab view to display.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Adw.TabView?` 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 view<W: Adw.TabView>(_ view: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, view, registry: ctx.registry, notifyDetail: "view",
read: { [w] in w.getView() as? W },
write: { [w] v in w.setView(view: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Adw.TabButton.setView(view:), GObject.Object.connectNotify(detail:_:), Adw.TabButton.getView()
/// 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.
/// When `Adw.TabView` 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 view<W: Adw.TabView>(_ view: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, view, registry: ctx.registry, notifyDetail: "view",
read: { [w] in w.getView() as? W },
write: { [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() })
}
}
}