1

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.

andrbrue
  • 721
  • 6
  • 15

1 Answers1

0

It seems like the current stable release of gtk-rs is not sufficient to implement custom containers as forall and foreach are needed but not defined in the interface. This will be fixed soon and already is in the gtk-rs git (source). If you need to implement forall (foreach will also depend on the same interface) and it still is not available in the stable release, just use the git-repo of gtk-rs as dependency source in your Cargo.toml.

andrbrue
  • 721
  • 6
  • 15