SearchBarProtocol

public protocol SearchBarProtocol : BinProtocol

GtkSearchBar is a container made to have a search entry (possibly with additional connex widgets, such as drop-down menus, or buttons) built-in. 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, events will need to be forwarded from the top-level window that contains the search bar. See gtk_search_bar_handle_event() for example code. 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 gtk_search_bar_connect_entry(). The following example shows you how to create a more complex search entry.

CSS nodes

GtkSearchBar has a single CSS node with name searchbar.

A simple example

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 GtkEntry widget passed as the one to be used in this search bar. The entry should be a descendant of the search bar. This 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<EntryT>(entry: EntryT) where EntryT : EntryProtocol
  • 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
  • handle(event:) Extension method

    This function should be called when the top-level window which contains the search bar received a key event.

    If the key event is handled by the search bar, the bar will be shown, the entry populated with the entered text and GDK_EVENT_STOP will be returned. The caller should ensure that events are not propagated further.

    If no entry has been connected to the search bar, using gtk_search_bar_connect_entry(), this function will return immediately with a warning.

    Showing the search bar on key presses

    (C Language Example):

    static gboolean
    on_key_press_event (GtkWidget *widget,
                        GdkEvent  *event,
                        gpointer   user_data)
    {
      GtkSearchBar *bar = GTK_SEARCH_BAR (user_data);
      return gtk_search_bar_handle_event (bar, event);
    }
    
    static void
    create_toplevel (void)
    {
      GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      GtkWindow *search_bar = gtk_search_bar_new ();
    
     // Add more widgets to the window...
    
      g_signal_connect (window,
                       "key-press-event",
                        G_CALLBACK (on_key_press_event),
                        search_bar);
    }
    

    Declaration

    Swift

    @inlinable
    func handle<EventT>(event: EventT) -> Bool where EventT : EventProtocol
  • 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)
  • 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 }