SearchBarProtocol
public protocol SearchBarProtocol : WidgetProtocol
GtkSearchBar is a container made to have a search entry.

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].
Creating a search bar
The following example shows you how to create a more complex search entry.
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.
-
Untyped pointer to the underlying
GtkSearchBarinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
search_bar_ptrDefault implementationTyped pointer to the underlying
GtkSearchBarinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkSearchBarinstance.Declaration
Swift
var search_bar_ptr: UnsafeMutablePointer<GtkSearchBar>! { get } -
Required Initialiser for types conforming to
SearchBarProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
SearchBarPropertyNamesource 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 : ObjectProtocolParameters
source_propertythe source property to bind
targetthe target object to bind to
target_propertythe target property to bind to
flagsthe flags to pass to the
Bindingtransform_fromValueTransformerto use for forward transformationtransform_toValueTransformerto use for backwards transformationReturn Value
binding reference or
nilin case of an error -
get(property:Extension method) Get the value of a SearchBar property
Declaration
Swift
@inlinable func get(property: SearchBarPropertyName) -> GLibObject.ValueParameters
propertythe property to get the value for
Return Value
the value of the named property
-
set(property:Extension methodvalue: ) 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
propertythe property to get the value for
Return Value
the value of the named property
-
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 methodGets the child widget of
bar.Declaration
Swift
@inlinable func getChild() -> WidgetRef! -
getKeyCaptureWidget()Extension methodGets the widget that
baris capturing key events from.Declaration
Swift
@inlinable func getKeyCaptureWidget() -> WidgetRef! -
getSearchMode()Extension methodReturns whether the search mode is on or off.
Declaration
Swift
@inlinable func getSearchMode() -> Bool -
getShowCloseButton()Extension methodReturns 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
widgetas the widget thatbarwill 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
widgetwill 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
widgetas the widget thatbarwill 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
widgetwill 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) -
childExtension methodThe child widget.
Declaration
Swift
@inlinable var child: WidgetRef! { get nonmutating set } -
keyCaptureWidgetExtension methodGets the widget that
baris capturing key events from.Declaration
Swift
@inlinable var keyCaptureWidget: WidgetRef! { get nonmutating set } -
searchModeExtension methodReturns whether the search mode is on or off.
Declaration
Swift
@inlinable var searchMode: Bool { get nonmutating set } -
showCloseButtonExtension methodReturns whether the close button is shown.
Declaration
Swift
@inlinable var showCloseButton: Bool { get nonmutating set }
View on GitHub
Install in Dash
SearchBarProtocol Protocol Reference