Missing Trait Implementations for `FlowBox` and Potential Conflicts
Hello, I'm enjoying the process of designing an app thus var with relm! However, I've run into an issue when looking for elements that might enable the option for more dynamic layouts like FlowBox.
When trying to place items within FlowBox like this example codeblock:
view! {
...
#[name(overview)]
gtk::FlowBox::builder()
.css_classes(vec!["overview"])
.build()
{
set_orientation: gtk::Orientation::Horizontal,
set_spacing: 10,
#[name(title)]
gtk::Label::builder()
.label(&self.0.entry.name)
.css_classes(vec!["title"])
.build(),
#[name(comment)]
gtk::Label::builder()
.label(&self.0.entry.comment.clone().unwrap_or_else(|| "".to_owned()))
.css_classes(vec!["comment"])
.visible(self.0.comments)
.build(),
},
...
}
rust comes back with the following errors:
error[E0599]: the method `container_add` exists for struct `FlowBox`, but its trait bounds were not satisfied
...
| |_doesn't satisfy `FlowBox: RelmContainerExt`
| doesn't satisfy `FlowBox: RelmSetChildExt`
|
= note: the following trait bounds were not satisfied:
`FlowBox: RelmSetChildExt`
which is required by `FlowBox: RelmContainerExt`
I'm assuming this is because RelmContainerExt and RelmSetChildExt are not implemented for FlowBox. With little understanding of the codebase, I tried to implement them myself but it seems like there are potential conflicts in doing so:
https://github.com/Relm4/Relm4/blob/main/relm4/src/extensions/remove.rs#L11
https://github.com/Relm4/Relm4/blob/main/relm4/src/extensions/remove.rs#L30
I'm not sure how to proceed. Is it possible to use a FlowBox in the way I want to here? Any feedback is appreciated. Thanks!
Regarding this issue, you can read this section in the book: https://relm4.org/book/stable/tricks.html#method-container_add-is-missing
It sounds reasonable to me however, to implement RelmContainerExt for FlowBox using the append method, so you can keep this opened.
Can't believe I missed that. Thanks again!
I'm a little new to Rust and GTK, but I've been trying to use a factory to have children of a FlowBox automatically added, and I've been running into this same problem. Inside the view! macro:
gtk::ScrolledWindow {
gtk::FlowBox {
#[local_ref]
image_box -> gtk::FlowBoxChild {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 5,
}
}
}
Because this is a component factory, I can't just add append: in front of image_box. Is there another way to do this?
Theoretically, the correct approach would be to use append = ... (: is just for assigning values, = is for assigning widgets). If that doesn't work, let me know.
That worked, thank you! But now I am getting "the trait FactoryView is not implemented for FlowBoxChild" which I am assuming is another part that would be required for the factory to work with FlowBoxChild.
Never mind, figured it out - I was using FlowBoxChild in some places where I should have been using FlowBox. Thanks!
For historical reference, here is what I ended up doing:
In the parent widget's view! macro:
gtk::ScrolledWindow {
#[local_ref]
image_box -> gtk::FlowBox {
set_min_children_per_line: 4,
set_max_children_per_line: 50,
}
}
In the parent's init:
let images = FactoryVecDeque::builder()
.launch(gtk::FlowBox::default())
.detach();
let image_box = model.images.widget();
In the child widget:
type ParentWidget = gtk::FlowBox;
view! {
gtk::Box {
gtk::Label {
},
gtk::Picture {
},
}
}