How to reference an object using gtk builder compiled with glib_build_tools in rust?

Hello, good morning.

Im building an application using gtk_rs, and its pretty simple use the gtk builder to load a xml to describe interface, however, when using gtk_build_tools, the things gets a bit more complicated.

Im loading my resources using gio::resources_register_include!("resources.gresource").expect("Failed to register resources");, but I don’t know how to reference the xml objects as we do when loading with include_str! macro. I had read the gtk_rs book also. How I can access the objects in xml using gtk build tools?

Best Regards

I am loading my resources just as you are.

To reference the xml objects, I do the following in the imp of the window (or template object)

mod imp {
   use.....

    #[derive(Default, CompositeTemplate)]
    #[template(resource = "/com/shartrec/kelpie_planner/airport_view.ui")]
    pub struct AirportView {
        #[template_child]
        pub airport_window: TemplateChild<ScrolledWindow>,
        #[template_child]
        pub airport_list: TemplateChild<ColumnView>,
        #[template_child]
        pub col_id: TemplateChild<ColumnViewColumn>,
        #[template_child]
        pub col_name: TemplateChild<ColumnViewColumn>,
        #[template_child]
        pub col_lat: TemplateChild<ColumnViewColumn>,
        #[template_child]
        pub col_lon: TemplateChild<ColumnViewColumn>,
        #[template_child]
        pub col_elev: TemplateChild<ColumnViewColumn>,
        #[template_child]
        pub airport_search_name: TemplateChild<Entry>,
        #[template_child]
        pub airport_search_lat: TemplateChild<Entry>,
        #[template_child]
        pub airport_search_long: TemplateChild<Entry>,
        #[template_child]
        pub airport_search: TemplateChild<Button>,

        popover: RefCell<Option<PopoverMenu>>,
        filter_list_model: RefCell<Option<FilterListModel>>,

    }

The #[template(resource brings in the resource and each #[template_child] is a reference to each object in the XML efinition of the UI. The names must match up.

1 Like

Hello. Good morning.
I will try this way.

What Im seeing here is that I need to do a subclass for my widgets, thats correct? I cant use templates as the gtk4::Button directly.