pub trait HdySearchBarExt: IsA<SearchBar> + Sealed + 'static {
    // Provided methods
    fn connect_entry(&self, entry: &impl IsA<Entry>) { ... }
    fn is_search_mode(&self) -> bool { ... }
    fn shows_close_button(&self) -> bool { ... }
    fn handle_event(&self, event: &Event) -> bool { ... }
    fn set_search_mode(&self, search_mode: bool) { ... }
    fn set_show_close_button(&self, visible: bool) { ... }
    fn is_search_mode_enabled(&self) -> bool { ... }
    fn set_search_mode_enabled(&self, search_mode_enabled: bool) { ... }
    fn connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId { ... }
    fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all SearchBar methods.

Implementors

SearchBar

Provided Methods§

source

fn connect_entry(&self, entry: &impl IsA<Entry>)

Sets the entry 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).

entry

an entry

source

fn is_search_mode(&self) -> bool

Gets whether the search mode is on.

Returns

whether search mode is toggled on

source

fn shows_close_button(&self) -> bool

Gets whether the close button is shown.

Returns

whether the close button is shown

source

fn handle_event(&self, event: &Event) -> bool

Handles key press events.

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 connect_entry(), this function will return immediately with a warning.

Showing the search bar on key presses

⚠️ The following code is in c ⚠️

static gboolean
on_key_press_event (GtkWidget *widget,
                    GdkEvent  *event,
                    gpointer   user_data)
{
  HdySearchBar *bar = HDY_SEARCH_BAR (user_data);
  return hdy_search_bar_handle_event (self, event);
}

static void
create_toplevel (void)
{
  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  GtkWindow *search_bar = hdy_search_bar_new ();

  // Add more widgets to the window...

  g_signal_connect (window,
                   "key-press-event",
                    G_CALLBACK (on_key_press_event),
                    search_bar);
}
event

a Gdk::Event containing key press events

Returns

GDK_EVENT_STOP if the key press event resulted in text being entered in the search entry (and revealing the search bar if necessary), GDK_EVENT_PROPAGATE otherwise.

source

fn set_search_mode(&self, search_mode: bool)

Switches the search mode on or off.

search_mode

the new state of the search mode

source

fn set_show_close_button(&self, visible: bool)

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.

visible

whether the close button will be shown or not

source

fn is_search_mode_enabled(&self) -> bool

Whether the search mode is on and the search bar shown.

source

fn set_search_mode_enabled(&self, search_mode_enabled: bool)

Whether the search mode is on and the search bar shown.

source

fn connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

source

fn connect_show_close_button_notify<F: Fn(&Self) + 'static>( &self, f: F ) -> SignalHandlerId

Object Safety§

This trait is not object safe.

Implementors§