Give multi-child containers a convenience Container::add(std::initializer_list) [and maybe ctor] ?



I don't know about you, but often I just want to create a Container, add a bunch of child Widgets to it, add it to a window or something, and forget about it.

We then get repetitive code like this:

  box.add(foo);
  box.add(bar);
  box.add(bongo);



Way back when, I had a wrapper class around Gtk::Box, which avoided the need for this by having an add() method that took an std::initializer_list:

  box.add( {&foo, &bar, &bongo} );

i.e.: it took an std::initializer_list<Gtk::Widget*> and did the repetition for me - abstracting away that tedious part of the process and making the code look more like a visual representation of the UI layout.


I also had an equivalent constructor overload, which did something like this:

  auto custom_box = CustomBox{ Gtk::ORIENTATION_HORIZONTAL, 8, {&foo, &bar, &bongo} );

i.e. which allowed constructing the container then adding to it in one step.


Sometimes such Containers are even nested, and although I never got around to it, I can imagine being able to support that nicely too. Something like the following:

  auto nested_box = Box{
    Gtk::ORIENTATION_VERTICAL, 8, // (assumes Box::spacing is kept!)
    { &blah,
      &wow,
      Gtk::manage( new Box{&some,
                           &other,
                           &widgets} )
    }
  };


I stopped using that class for other reasons, but always missed the more succinct and visual representation of layout that it gave me in the code.


I'm aware that .ui files exist for a similar goal, but call me old-fashioned: I want to create my layouts in code, not in an XML file that takes an additional round trip through Gtk::Builder to parse and create - plus still requires using C class names, afaict,


Assuming it's not been discounted already, it would be great if this is the kind of overload of add(), and maybe also construction, that could be added to gtkmm.

Has this been considered and rejected anywhere already? If not, I can add it as an RFE on Bugzilla.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]