portico/Sources/Portico/Generated/SearchBar.swift

436 lines
23 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.SearchBar
/// Reveals a search entry when search is started.
///
/// <picture>
/// <source srcset="search-bar-dark.png" media="(prefers-color-scheme: dark)">
/// <img alt="An example GtkSearchBar" src="search-bar.png">
/// </picture>
///
/// It can also contain additional widgets, such as drop-down menus,
/// or buttons. The search bar would appear when a search is started
/// through typing on the keyboard, or the applications search mode
/// is toggled on.
///
/// For keyboard presses to start a search, the search bar must be told
/// of a widget to capture key events from through
/// [method`Gtk`.SearchBar.set_key_capture_widget]. This widget will
/// typically be the top-level window, or a parent container of the
/// search bar. Common shortcuts such as Ctrl+F should be handled as an
/// application action, or through the menu items.
///
/// You will also need to tell the search bar about which entry you
/// are using as your search entry using [method`Gtk`.SearchBar.connect_entry].
///
/// ## Creating a search bar
///
/// The following example shows you how to create a more complex search
/// entry.
///
/// [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/main/examples/search-bar.c)
///
/// # Shortcuts and Gestures
///
/// `GtkSearchBar` supports the following keyboard shortcuts:
///
/// - <kbd>Escape</kbd> hides the search bar.
///
/// # CSS nodes
///
/// ```
/// searchbar
/// revealer
/// box
/// [child]
/// [button.close]
/// ```
///
/// `GtkSearchBar` has a main CSS node with name searchbar. It has a child
/// node with name revealer that contains a node with name box. The box node
/// contains both the CSS node of the child widget as well as an optional button
/// node which gets the .close style class applied.
///
/// # Accessibility
///
/// `GtkSearchBar` uses the [enum`Gtk`.AccessibleRole.search] role.
///
/// A Portico view that mounts a `Gtk.SearchBar`.
@MainActor public struct SearchBar: View {
private let make: (MountContext) -> Gtk.SearchBar
private var configure: [(Gtk.SearchBar, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.SearchBar.init()
/// Creates a `GtkSearchBar`.
///
/// You will need to tell it about which widget is going to be your text
/// entry using [method`Gtk`.SearchBar.connect_entry].
///
/// 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 searchModeEnabled: Whether the search mode is on and the search bar shown.
/// - Parameter showCloseButton: Whether to show the close button in the search bar.
/// - Parameter child: A `ViewBuilder` closure whose first view is mounted into the `child` slot.
/// - Parameter keyCaptureWidget: A `ViewBuilder` closure whose first view is mounted into the `keyCaptureWidget` slot.
public init(searchModeEnabled: Bool? = nil, showCloseButton: Bool? = nil, @ViewBuilder child: @escaping () -> [AnyView] = { [] }, @ViewBuilder keyCaptureWidget: @escaping () -> [AnyView] = { [] }) {
make = { _ in Gtk.SearchBar() }
configure.append { w, ctx in
if let searchModeEnabled { w.setSearchMode(searchMode: searchModeEnabled) }
if let showCloseButton { w.setShowCloseButton(visible: showCloseButton) }
if let v = Portico.mountSlotChild(child, ctx, onUpdate: { v in w.setChild(child: v) }) { w.setChild(child: v) }
if let v = Portico.mountSlotChild(keyCaptureWidget, ctx, onUpdate: { v in w.setKeyCaptureWidget(widget: v) }) { w.setKeyCaptureWidget(widget: v) }
}
}
}
extension SearchBar: WidgetView {
public typealias Target = Gtk.SearchBar
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.SearchBar, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension SearchBar: 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.SearchBar
/// Modifiers for `Gtk.SearchBar`, available on every Portico view whose
/// backing widget is `Gtk.SearchBar` or one of its subclasses.
extension WidgetView where Target: Gtk.SearchBar {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SearchBar.setChild(child:)
/// Sets the child widget of `bar`.
///
/// 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.SearchBar.setChild(child:)
/// Sets the child widget of `bar`.
///
/// 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.SearchBar.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.SearchBar.getChild()
/// Sets the child widget of `bar`.
///
/// 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.SearchBar.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.SearchBar.getChild()
/// Sets the child widget of `bar`.
///
/// 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.SearchBar.setChild(child:)
/// Sets the child widget of `bar`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SearchBar.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.SearchBar.setKeyCaptureWidget(widget:)
/// Sets `widget` as the widget that `bar` will capture key events
/// from.
///
/// If key events are handled by the search bar, the bar will
/// be shown, and the entry populated with the entered text.
///
/// Note that despite the name of this function, the events
/// are only 'captured' in the bubble phase, which means that
/// editable child widgets of `widget` will receive text input
/// before it gets captured. If that is not desired, you can
/// capture and forward the events yourself with
/// [method`Gtk`.EventControllerKey.forward].
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter keyCaptureWidget: The key capture widget.
/// - Returns: A copy of this view with the modifier applied.
public func keyCaptureWidget(_ keyCaptureWidget: Gtk.Widget?) -> Self {
appending { w, _ in
w.setKeyCaptureWidget(widget: keyCaptureWidget)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Gtk.SearchBar.setKeyCaptureWidget(widget:)
/// Sets `widget` as the widget that `bar` will capture key events
/// from.
///
/// If key events are handled by the search bar, the bar will
/// be shown, and the entry populated with the entered text.
///
/// Note that despite the name of this function, the events
/// are only 'captured' in the bubble phase, which means that
/// editable child widgets of `widget` will receive text input
/// before it gets captured. If that is not desired, you can
/// capture and forward the events yourself with
/// [method`Gtk`.EventControllerKey.forward].
///
/// 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 keyCaptureWidget: The key capture widget.
/// - Returns: A copy of this view with the modifier applied.
public func keyCaptureWidget(@ViewBuilder _ keyCaptureWidget: () -> [AnyView]) -> Self {
let keyCaptureWidgetViews = keyCaptureWidget()
return appending { w, ctx in
guard let v = keyCaptureWidgetViews.first else { return }
w.setKeyCaptureWidget(widget: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SearchBar.setKeyCaptureWidget(widget:), GObject.Object.connectNotify(detail:_:), Gtk.SearchBar.getKeyCaptureWidget()
/// Sets `widget` as the widget that `bar` will capture key events
/// from.
///
/// If key events are handled by the search bar, the bar will
/// be shown, and the entry populated with the entered text.
///
/// Note that despite the name of this function, the events
/// are only 'captured' in the bubble phase, which means that
/// editable child widgets of `widget` will receive text input
/// before it gets captured. If that is not desired, you can
/// capture and forward the events yourself with
/// [method`Gtk`.EventControllerKey.forward].
///
/// 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 keyCaptureWidget<W: Gtk.Widget>(_ keyCaptureWidget: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, keyCaptureWidget, registry: ctx.registry, notifyDetail: "key-capture-widget",
read: { [w] in w.getKeyCaptureWidget() as? W },
write: { [w] v in w.setKeyCaptureWidget(widget: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.SearchBar.setKeyCaptureWidget(widget:), GObject.Object.connectNotify(detail:_:), Gtk.SearchBar.getKeyCaptureWidget()
/// Sets `widget` as the widget that `bar` will capture key events
/// from.
///
/// If key events are handled by the search bar, the bar will
/// be shown, and the entry populated with the entered text.
///
/// Note that despite the name of this function, the events
/// are only 'captured' in the bubble phase, which means that
/// editable child widgets of `widget` will receive text input
/// before it gets captured. If that is not desired, you can
/// capture and forward the events yourself with
/// [method`Gtk`.EventControllerKey.forward].
///
/// 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 keyCaptureWidget<W: Gtk.Widget>(_ keyCaptureWidget: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, keyCaptureWidget, registry: ctx.registry, notifyDetail: "key-capture-widget",
read: { [w] in w.getKeyCaptureWidget() as? W },
write: { [w] v in w.setKeyCaptureWidget(widget: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SearchBar.setKeyCaptureWidget(widget:)
/// Sets `widget` as the widget that `bar` will capture key events
/// from.
///
/// If key events are handled by the search bar, the bar will
/// be shown, and the entry populated with the entered text.
///
/// Note that despite the name of this function, the events
/// are only 'captured' in the bubble phase, which means that
/// editable child widgets of `widget` will receive text input
/// before it gets captured. If that is not desired, you can
/// capture and forward the events yourself with
/// [method`Gtk`.EventControllerKey.forward].
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SearchBar.setKeyCaptureWidget(widget:)`.
///
/// - Parameter keyCaptureWidget: The key capture widget.
/// - Returns: A copy of this view with the modifier applied.
public func keyCaptureWidget(_ keyCaptureWidget: @escaping () -> Gtk.Widget?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setKeyCaptureWidget(widget: keyCaptureWidget()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SearchBar.setSearchMode(searchMode:)
/// Switches the search mode on or off.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter searchModeEnabled: Whether the search mode is on and the search bar shown.
/// - Returns: A copy of this view with the modifier applied.
public func searchModeEnabled(_ searchModeEnabled: Bool) -> Self {
appending { w, _ in
w.setSearchMode(searchMode: searchModeEnabled)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SearchBar.setSearchMode(searchMode:), GObject.Object.connectNotify(detail:_:)
/// Switches the search mode on or off.
///
/// 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 searchModeEnabled(_ searchModeEnabled: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, searchModeEnabled, registry: ctx.registry, notifyDetail: "search-mode-enabled",
read: { [w] in w.searchModeEnabled },
write: { [w] v in w.setSearchMode(searchMode: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SearchBar.setSearchMode(searchMode:)
/// Switches the search mode on or off.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SearchBar.setSearchMode(searchMode:)`.
///
/// - Parameter searchModeEnabled: Whether the search mode is on and the search bar shown.
/// - Returns: A copy of this view with the modifier applied.
public func searchModeEnabled(_ searchModeEnabled: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setSearchMode(searchMode: searchModeEnabled()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.SearchBar.setShowCloseButton(visible:)
/// Shows or hides the close button.
///
/// Applications that already have a search toggle button should not
/// show a close button in their search bar, as it duplicates the role
/// of the toggle button.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter showCloseButton: Whether to show the close button in the search bar.
/// - Returns: A copy of this view with the modifier applied.
public func showCloseButton(_ showCloseButton: Bool) -> Self {
appending { w, _ in
w.setShowCloseButton(visible: showCloseButton)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.SearchBar.setShowCloseButton(visible:), GObject.Object.connectNotify(detail:_:), Gtk.SearchBar.getShowCloseButton()
/// Shows or hides the close button.
///
/// Applications that already have a search toggle button should not
/// show a close button in their search bar, as it duplicates the role
/// of the toggle button.
///
/// 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 showCloseButton(_ showCloseButton: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, showCloseButton, registry: ctx.registry, notifyDetail: "show-close-button",
read: { [w] in w.getShowCloseButton() },
write: { [w] v in w.setShowCloseButton(visible: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.SearchBar.setShowCloseButton(visible:)
/// Shows or hides the close button.
///
/// Applications that already have a search toggle button should not
/// show a close button in their search bar, as it duplicates the role
/// of the toggle button.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.SearchBar.setShowCloseButton(visible:)`.
///
/// - Parameter showCloseButton: Whether to show the close button in the search bar.
/// - Returns: A copy of this view with the modifier applied.
public func showCloseButton(_ showCloseButton: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setShowCloseButton(visible: showCloseButton()) }
tracker.run()
ctx.registry.add(tracker)
}
}
}