Hello,
I am making application using rust language with gtk4. Here is image of my application (at the top is my app window and below is GtkInspector window).
GtkApplicationWindow → GeoWindow → GeoReserves → GeoReservesList → GtkScrolledWindow → GtkListView -->GeoRow
GeoRow is custom GtkButton. I have connected to GeoRow clicked signal in GeoReservesList, but I need to move this signal to GeoWindow.
Every GeoRow holds i32 number and after it is clicked I need to move this number to GeoWindow. After GeoWindow gets number it will replace GeoReserves with new widget with data related to number.
I have tried to create new signal in GeoReservesList and emit it up to GeoReserves, but I have problem with rust lifetime of self. Some code from GeoReservesList in gtk::SignalListItemFactory
factory.connect_bind(move |_factory, item| {
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
let reserve = item.item().and_downcast::<Reserve>().unwrap();
let child = item.child().and_downcast::<Row>().unwrap();
child.set_reserve(&reserve);
let obj = self.obj();
child.connect_clicked(move |btn| {
obj.emit_by_name::<()>("reserve-pressed", &[&btn.id()]);
});
});
If I replaced obj.emit… with println!(“id: {}”, btn.id()); it would work and print GeoRow id to console, but obj.emit… don’t want to work because of lifetime.
Is here a better way to connect GeoRow clicked signal to GeoWindow to replace GeoReserves widget?