0

I am using GTK-RS to develop an application and I am struggling to make a dropdown searchable.

The documentation for drop-down has a method for making them searchable which states you need to use an expression however I do not know how to instantiate an expression.

I have a code example below where I create a dropdown from a set of strings, make it searchable but when you build the app the search option does nothing. I need to know how to make the dropdown searchable.

use gtk::prelude::*;
use adw::{Application, ApplicationWindow};
use adw::prelude::*;

const APP_ID: &str = "org.gtk_rs.HelloWorld2";

fn main() {
    // Create a new application
    let app = Application::builder().application_id(APP_ID).build();

    // Connect to "activate" signal of `app`
    app.connect_activate(build_ui);

    // Run the application
    app.run();
}

fn build_ui(app: &Application) {
    // Create a window and set the title
    let this_list = vec!["thing1", "thing2", "thing3", "other_thing", "fruit", "vegetable", "meat", "dairy", "grain", "other"];
    
    let dropdown = gtk::DropDown::from_strings(&this_list.as_slice());
    dropdown.set_enable_search(true);

    let dropdown_box = gtk::Box::builder()
        .orientation(gtk::Orientation::Vertical)
        .build();
    
    dropdown_box.append(&dropdown);

    let window = ApplicationWindow::builder()
        .application(app)
        .title("My GTK App")
        .build();

    window.set_content(Some(&dropdown_box));

    // Present window
    window.present();
}

My best guess is that this is done by using the this_list vector to make an expression and then use set_expression on the dropdown so it knows to search the vector but I have not been able to figure out how to use the vector to create an expression so I am no where near close to achieving this.

John554
  • 145
  • 1
  • 7

0 Answers0