antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.41k stars 79 forks source link

Dynamically create new widgets #302

Closed Jkillelea closed 1 year ago

Jkillelea commented 1 year ago

Hi there,

I'm trying to create a list of widgets, which are dynamically created in response to user actions. It doesn't seem like there's a way to create widgets on the fly, is there?

Ideally, I'd like to be able to do something like:

list_box.append(Widget::new())

I know that relm::create_component<T> exists, but it's difficult to use in the above context, as list_box above accepts a reference to the created component/widget, but the owning handle goes out of scope quickly, while the list_box hangs around much longer.

antoyo commented 1 year ago

Hi! Are the add_widget() and remove_widget() functions that you can see in this example insufficient?

Jkillelea commented 1 year ago

Thanks, I didn't see that method, and I didn't know about the ContainerWidget trait.