portico/Sources/Portico/Generated/LinkButton.swift

405 lines
25 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.LinkButton
/// A button with a hyperlink.
///
/// <picture>
/// <source srcset="link-button-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkLinkButton" src="link-button.png">
/// </picture>
///
/// It is useful to show quick links to resources.
///
/// A link button is created by calling either [ctor`Gtk`.LinkButton.new] or
/// [ctor`Gtk`.LinkButton.new_with_label]. If using the former, the URI you
/// pass to the constructor is used as a label for the widget.
///
/// The URI bound to a `GtkLinkButton` can be set specifically using
/// [method`Gtk`.LinkButton.set_uri].
///
/// By default, `GtkLinkButton` calls [method`Gtk`.FileLauncher.launch] when the button
/// is clicked. This behaviour can be overridden by connecting to the
/// [signal`Gtk`.LinkButton::activate-link] signal and returning `true` from
/// the signal handler.
///
/// # Shortcuts and Gestures
///
/// `GtkLinkButton` supports the following keyboard shortcuts:
///
/// - <kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Menu</kbd> opens the context menu.
///
/// # Actions
///
/// `GtkLinkButton` defines a set of built-in actions:
///
/// - `clipboard.copy` copies the url to the clipboard.
/// - `menu.popup` opens the context menu.
///
/// # CSS nodes
///
/// `GtkLinkButton` has a single CSS node with name button. To differentiate
/// it from a plain `GtkButton`, it gets the .link style class.
///
/// # Accessibility
///
/// `GtkLinkButton` uses the [enum`Gtk`.AccessibleRole.link] role.
///
/// A Portico view that mounts a `Gtk.LinkButton`.
@MainActor public struct LinkButton: View {
private let make: (MountContext) -> Gtk.LinkButton
private var configure: [(Gtk.LinkButton, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.LinkButton.init(uri:)
/// Creates a new `GtkLinkButton` with the URI as its text.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for values that change.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
/// 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 uri: The URI bound to this button.
/// - Parameter visited: The 'visited' state of this button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter iconName: The name of the icon used to automatically populate the button.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivateLink: Invoked when the widget emits the `activate-link` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
@_disfavoredOverload
public init<S: StringProtocol>(uri: S, visited: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivateLink: (() -> Bool)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.LinkButton(uri: String(uri)) }
configure.append { w, ctx in
if let visited { w.setVisited(visited: visited) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivateLink { ctx.registry.add(w.connectActivateLink { _ in onActivateLink() }) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(binding) | source: Gtk.LinkButton.init(uri:), Gtk.LinkButton.setUri(uri:)
/// Creates a new `GtkLinkButton` with the URI as its text.
///
/// The initial value is the binding's current value; every later change is pushed into the widget through `Gtk.LinkButton.setUri(uri:)` without rebuilding the view.
/// 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.
/// Optional `Binding` parameters bind through `Portico.bindProperty`, so they are two-way wherever the wrapper exposes a safe getter.
///
/// - Parameter uri: The URI bound to this button.
/// - Parameter visited: The 'visited' state of this button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter iconName: The name of the icon used to automatically populate the button.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivateLink: Invoked when the widget emits the `activate-link` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(uri: Portico.Binding<String>, visited: Portico.Binding<Bool>? = nil, canShrink: Portico.Binding<Bool>? = nil, hasFrame: Portico.Binding<Bool>? = nil, iconName: Portico.Binding<String>? = nil, useUnderline: Portico.Binding<Bool>? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivateLink: (() -> Bool)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.LinkButton(uri: uri.wrappedValue) }
configure.append { w, ctx in
ctx.registry.add(uri.subscribe { [w] v in w.setUri(uri: v) })
if let visited {
Portico.bindProperty(w, visited, registry: ctx.registry, notifyDetail: "visited", read: { [w] in w.getVisited() }, write: { [w] v in w.setVisited(visited: v) })
}
if let canShrink {
Portico.bindProperty(w, canShrink, registry: ctx.registry, notifyDetail: "can-shrink", read: { [w] in w.getCanShrink() }, write: { [w] v in w.setCanShrink(canShrink: v) })
}
if let hasFrame {
Portico.bindProperty(w, hasFrame, registry: ctx.registry, notifyDetail: "has-frame", read: { [w] in w.getHasFrame() }, write: { [w] v in w.setHasFrame(hasFrame: v) })
}
if let iconName {
Portico.bindProperty(w, iconName, registry: ctx.registry, notifyDetail: "icon-name", read: { [w] in w.getIconName() }, write: { [w] v in w.setIconName(iconName: v) })
}
if let useUnderline {
Portico.bindProperty(w, useUnderline, registry: ctx.registry, notifyDetail: "use-underline", read: { [w] in w.getUseUnderline() }, write: { [w] v in w.setUseUnderline(useUnderline: v) })
}
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivateLink { ctx.registry.add(w.connectActivateLink { _ in onActivateLink() }) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(closure) | source: Gtk.LinkButton.init(uri:), Gtk.LinkButton.setUri(uri:)
/// Creates a new `GtkLinkButton` with the URI as its text.
///
/// Each closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LinkButton.setUri(uri:)`.
/// 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 uri: The URI bound to this button.
/// - Parameter visited: The 'visited' state of this button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter iconName: The name of the icon used to automatically populate the button.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivateLink: Invoked when the widget emits the `activate-link` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(uri: @escaping () -> String, visited: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivateLink: (() -> Bool)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.LinkButton(uri: uri()) }
configure.append { w, ctx in
let t0 = DependencyTracker { [w] in w.setUri(uri: uri()) }
t0.run()
ctx.registry.add(t0)
if let visited { w.setVisited(visited: visited) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivateLink { ctx.registry.add(w.connectActivateLink { _ in onActivateLink() }) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(interpolation) | source: Gtk.LinkButton.init(uri:), Gtk.LinkButton.setUri(uri:)
/// Creates a new `GtkLinkButton` with the URI as its text.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.LinkButton.setUri(uri:)`. A literal with no interpolation is applied once, with no subscription.
/// 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 uri: The URI bound to this button.
/// - Parameter visited: The 'visited' state of this button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter iconName: The name of the icon used to automatically populate the button.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivateLink: Invoked when the widget emits the `activate-link` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(uri: Portico.InterpolatedText, visited: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivateLink: (() -> Bool)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.LinkButton(uri: uri.untrackedText) }
configure.append { w, ctx in
Portico.bindInterpolation(uri, registry: ctx.registry) { [w] v in w.setUri(uri: v) }
if let visited { w.setVisited(visited: visited) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivateLink { ctx.registry.add(w.connectActivateLink { _ in onActivateLink() }) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
// PorticoGen: generateInits(static) | source: Gtk.LinkButton.init(uri:label:)
/// Creates a new `GtkLinkButton` containing a label.
///
/// 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 uri: The URI bound to this button.
/// - Parameter label: The `label` value forwarded to `Gtk.LinkButton`.
/// - Parameter visited: The 'visited' state of this button.
/// - Parameter canShrink: Whether the size of the button can be made smaller than the natural size of its contents.
/// - Parameter hasFrame: Whether the button has a frame.
/// - Parameter iconName: The name of the icon used to automatically populate the button.
/// - Parameter useUnderline: If set, an underline in the text indicates that the following character is to be used as mnemonic.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter onActivateLink: Invoked when the widget emits the `activate-link` signal. Its return value is forwarded to GTK as the signal's result.
/// - Parameter onActivate: Invoked when the widget emits the `activate` signal.
/// - Parameter onClicked: Invoked when the widget emits the `clicked` signal.
public init(uri: String, label: String?, visited: Bool? = nil, canShrink: Bool? = nil, hasFrame: Bool? = nil, iconName: String? = nil, useUnderline: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, onActivateLink: (() -> Bool)? = nil, onActivate: (() -> Void)? = nil, onClicked: (() -> Void)? = nil) {
make = { _ in Gtk.LinkButton(uri: uri, label: label) }
configure.append { w, ctx in
if let visited { w.setVisited(visited: visited) }
if let canShrink { w.setCanShrink(canShrink: canShrink) }
if let hasFrame { w.setHasFrame(hasFrame: hasFrame) }
if let iconName { w.setIconName(iconName: iconName) }
if let useUnderline { w.setUseUnderline(useUnderline: useUnderline) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let onActivateLink { ctx.registry.add(w.connectActivateLink { _ in onActivateLink() }) }
if let onActivate { ctx.registry.add(w.connectActivate { _ in onActivate() }) }
if let onClicked { ctx.registry.add(w.connectClicked { _ in onClicked() }) }
}
}
}
extension LinkButton: WidgetView {
public typealias Target = Gtk.LinkButton
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.LinkButton, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension LinkButton: 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.LinkButton
/// Modifiers for `Gtk.LinkButton`, available on every Portico view whose
/// backing widget is `Gtk.LinkButton` or one of its subclasses.
extension WidgetView where Target: Gtk.LinkButton {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.LinkButton.setUri(uri:)
/// Sets `uri` as the URI where the `GtkLinkButton` points.
///
/// As a side-effect this unsets the visited state of the button.
///
/// Applied once at mount; use the `Binding`, closure, or `InterpolatedText` overload for a value that changes.
/// A string literal containing interpolation selects the `InterpolatedText` overload instead, which updates live.
///
/// - Parameter uri: The URI bound to this button.
/// - Returns: A copy of this view with the modifier applied.
@_disfavoredOverload
public func uri<S: StringProtocol>(_ uri: S) -> Self {
appending { w, _ in
w.setUri(uri: String(uri))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.LinkButton.setUri(uri:), GObject.Object.connectNotify(detail:_:), Gtk.LinkButton.getUri()
/// Sets `uri` as the URI where the `GtkLinkButton` points.
///
/// As a side-effect this unsets the visited state of the button.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `String` 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 uri(_ uri: Portico.Binding<String>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, uri, registry: ctx.registry, notifyDetail: "uri",
read: { [w] in w.getUri() },
write: { [w] v in w.setUri(uri: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.LinkButton.setUri(uri:)
/// Sets `uri` as the URI where the `GtkLinkButton` points.
///
/// As a side-effect this unsets the visited state of the button.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LinkButton.setUri(uri:)`.
///
/// - Parameter uri: The URI bound to this button.
/// - Returns: A copy of this view with the modifier applied.
public func uri(_ uri: @escaping () -> String) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setUri(uri: uri()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(interpolation) | source: Gtk.LinkButton.setUri(uri:)
/// Sets `uri` as the URI where the `GtkLinkButton` points.
///
/// As a side-effect this unsets the visited state of the button.
///
/// Interpolated segments are captured unevaluated and re-read inside a `DependencyTracker`, so any `@State` they read pushes a new value through `Gtk.LinkButton.setUri(uri:)`. A literal with no interpolation is applied once, with no subscription.
///
/// - Parameter uri: The URI bound to this button.
/// - Returns: A copy of this view with the modifier applied.
public func uri(_ uri: Portico.InterpolatedText) -> Self {
appending { w, ctx in
Portico.bindInterpolation(uri, registry: ctx.registry) { [w] v in w.setUri(uri: v) }
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.LinkButton.setVisited(visited:)
/// Sets the visited state of the `GtkLinkButton`.
///
/// See [method`Gtk`.LinkButton.get_visited] for more details.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter visited: The 'visited' state of this button.
/// - Returns: A copy of this view with the modifier applied.
public func visited(_ visited: Bool) -> Self {
appending { w, _ in
w.setVisited(visited: visited)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.LinkButton.setVisited(visited:), GObject.Object.connectNotify(detail:_:), Gtk.LinkButton.getVisited()
/// Sets the visited state of the `GtkLinkButton`.
///
/// See [method`Gtk`.LinkButton.get_visited] for more details.
///
/// 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 visited(_ visited: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, visited, registry: ctx.registry, notifyDetail: "visited",
read: { [w] in w.getVisited() },
write: { [w] v in w.setVisited(visited: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.LinkButton.setVisited(visited:)
/// Sets the visited state of the `GtkLinkButton`.
///
/// See [method`Gtk`.LinkButton.get_visited] for more details.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.LinkButton.setVisited(visited:)`.
///
/// - Parameter visited: The 'visited' state of this button.
/// - Returns: A copy of this view with the modifier applied.
public func visited(_ visited: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setVisited(visited: visited()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generateSignalModifier | source: Gtk.LinkButton.connectActivateLink(_:)
/// Emitted each time the `GtkLinkButton` is clicked.
///
/// The default handler will call [method`Gtk`.FileLauncher.launch] with the URI
/// stored inside the [property`Gtk`.LinkButton:uri] property.
///
/// To override the default behavior, you can connect to the
/// ::activate-link signal and stop the propagation of the signal
/// by returning `true` from your handler.
///
/// - Parameter handler: Invoked when the widget emits the `activate-link` signal. Its return value is forwarded to GTK as the signal's result.
/// - Returns: A copy of this view with the modifier applied.
public func onActivateLink(_ handler: @escaping () -> Bool) -> Self {
appending { w, ctx in
ctx.registry.add(w.connectActivateLink { _ in handler() })
}
}
}