Add `Gtk::Widget::get_children()` wrapping `get_first_child()`, `get_next_sibling()`, etc. - for API compatibility with `gtkmm` 3
GTK3 had gtk_container_get_children()
, which returned a GList
of the children. gtkmm
3 wrapped that as Container.get_children()
, returning a std::vector<Gtk::Widget *>
.
GTK4 dropped Container
and hence get_children()
, and so did gtkmm
4. So I guess now we are expected to do something like for (auto child = widget.get_first_child(); child != nullptr; child = child->get_next_sibling()) { /* FOO */ }
.
That's not really ideal C++, and it feels like unnecessary busy-work that we will have to replace when migrating apps that used Widget.get_children()
quite a lot, such as Inkscape in my current case.
Would it be possible for gtkmm
4 to add back its own Widget.get_children()
function, which will internally do the above loop and push back the children into a vector<Widget*>
, then return that?
If so, I'm happy to work on a merge request!
A future direction could be returning a ranges view, which would do the same internally, but might be able to avoid actually allocating a vector by just lazily doing get_first_child()
or get_sibling()
as the iterator was incremented. But of course, this is considerably more work, so more a 'nice to have', whereas I think getting back Widget.get_children()
is more important for migrating from v3.