SearchBarProtocol

public protocol SearchBarProtocol : WidgetProtocol

GtkSearchBar is a container made to have a search entry.

An example GtkSearchBar

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 application’s 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 [methodGtk.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 [methodGtk.SearchBar.connect_entry].

The following example shows you how to create a more complex search entry.

A simple example

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 GTK_ACCESSIBLE_ROLE_SEARCH role.

The SearchBarProtocol protocol exposes the methods and properties of an underlying GtkSearchBar instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see SearchBar. Alternatively, use SearchBarRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkSearchBar instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • search_bar_ptr Default implementation

    Typed pointer to the underlying GtkSearchBar instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkSearchBar instance.

    Declaration

    Swift

    var search_bar_ptr: UnsafeMutablePointer<GtkSearchBar>! { get }
  • Required Initialiser for types conforming to SearchBarProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

SearchBar Class

  • Bind a SearchBarPropertyName source property to a given target object.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: SearchBarPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a SearchBar property

    Declaration

    Swift

    @inlinable
    func get(property: SearchBarPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    Set the value of a SearchBar property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

    @inlinable
    func set(property: SearchBarPropertyName, value v: GLibObject.Value)

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

SearchBar Class: SearchBarProtocol extension (methods and fields)

  • connect(entry:) Extension method

    Connects the `GtkEditable widget passed as the one to be used in this search bar.

    The entry should be a descendant of the search bar. Calling this function manually is only required if the entry isn’t the direct child of the search bar (as in our main example).

    Declaration

    Swift

    @inlinable
    func connect<EditableT>(entry: EditableT) where EditableT : EditableProtocol
  • getChild() Extension method

    Gets the child widget of bar.

    Declaration

    Swift

    @inlinable
    func getChild() -> WidgetRef!
  • getKeyCaptureWidget() Extension method

    Gets the widget that bar is capturing key events from.

    Declaration

    Swift

    @inlinable
    func getKeyCaptureWidget() -> WidgetRef!
  • getSearchMode() Extension method

    Returns whether the search mode is on or off.

    Declaration

    Swift

    @inlinable
    func getSearchMode() -> Bool
  • getShowCloseButton() Extension method

    Returns whether the close button is shown.

    Declaration

    Swift

    @inlinable
    func getShowCloseButton() -> Bool
  • set(child:) Extension method

    Sets the child widget of bar.

    Declaration

    Swift

    @inlinable
    func set(child: WidgetRef? = nil)
  • set(child:) Extension method

    Sets the child widget of bar.

    Declaration

    Swift

    @inlinable
    func set<WidgetT>(child: WidgetT?) where WidgetT : WidgetProtocol
  • setKeyCapture(widget:) Extension method

    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 [methodGtk.EventControllerKey.forward].

    Declaration

    Swift

    @inlinable
    func setKeyCapture(widget: WidgetRef? = nil)
  • setKeyCapture(widget:) Extension method

    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 [methodGtk.EventControllerKey.forward].

    Declaration

    Swift

    @inlinable
    func setKeyCapture<WidgetT>(widget: WidgetT?) where WidgetT : WidgetProtocol
  • set(searchMode:) Extension method

    Switches the search mode on or off.

    Declaration

    Swift

    @inlinable
    func set(searchMode: Bool)
  • setShowCloseButton(visible:) Extension method

    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.

    Declaration

    Swift

    @inlinable
    func setShowCloseButton(visible: Bool)
  • child Extension method

    The child widget.

    Declaration

    Swift

    @inlinable
    var child: WidgetRef! { get nonmutating set }
  • keyCaptureWidget Extension method

    Gets the widget that bar is capturing key events from.

    Declaration

    Swift

    @inlinable
    var keyCaptureWidget: WidgetRef! { get nonmutating set }
  • searchMode Extension method

    Returns whether the search mode is on or off.

    Declaration

    Swift

    @inlinable
    var searchMode: Bool { get nonmutating set }
  • showCloseButton Extension method

    Returns whether the close button is shown.

    Declaration

    Swift

    @inlinable
    var showCloseButton: Bool { get nonmutating set }