I am trying to create a custom gtk container containing multiple children using the Rust binding for gtk. I derive my custom class from gtk::Container
and gtk::Widget
. The problem is as follows:
gtk::subclass::container::ContainerImpl
(documentation) only provides a few methods to implement. Those methods include the add
and remove
methods required to make the container able to handle children.
My subclass uses its own vector of widgets which is filled by the add
method. Custom size negotiation and allocation is implemented and works as expected. For the most parts, I followed this tutorial (which is for plain C). But the get_children
method does not work, it returns an empty vector. This is expected as the method uses the forall
and foreach
methods which do not know about my custom storage of widgets. But those methods are parts of gtk::ContainerExt
and thus not definable by my subclass (at least without implementing all associated methods manually). The tutorial I followed overrides those methods.
I do not know how to proceed as it feels like the children not being correctly registered may lead to later memory leaks and as it renders some methods like get_children
useless. Does gtk-rs have any special functionality for handling children? I am unable to find any documentation in this direction. But there must be a possibility as subclassing a container without being able to handle children is nearly useless.
question from:
https://stackoverflow.com/questions/65887490/handle-children-when-subclassing-gtkcontainer-in-rust 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…