Sharing a ListModel over many DropDown widgets using GTK-RS bindings - Solved (original) (raw)
I have a ColumnView which for each row has a DropDown widget to select one of x options, where x is small, typically less than 6 and is static for the life of the ColumnView.
I cannot find a way to share a copy of the ListModel that provides the data for the DropDown. Currently I am doing as follows when building my SignalListItemFactory.
let factory = SignalListItemFactory::new();
factory.connect_setup(move |_, list_item| {
let drop = DropDown::new(model.borrow().clone(), None::<Expression>);
list_item
.downcast_ref::<ListItem>()
.expect("Needs to be ListItem")
.set_child(Some(&drop));
});
where model is defined as model: RefCell<Option<StringList>>
This is obviously cloning the model, which has many downsides for me, but as the gtk-rs binding take ownership of the model, I can see no way to share the model.
From reading the code for the DropDown rust bindings, it seems only a pointer is eventually passed to GTK with .into_glib_ptr()
.
shartrec (Trevor Campbell) May 23, 2025, 4:28am 2
As is always the way, I just read a chunk more code and found an easy workaround of not setting the model on construction, but using setModel
let drop = DropDown::new(None::<ListModel>, None::<Expression>);
drop.set_model(model.borrow().as_ref());