X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcontainer.h;h=d100dacf94aaa80538194fc77e2d95a486c869b3;hb=HEAD;hp=45985bc0ad585c304d5735f2ad037b016bbdc53b;hpb=eeec8c83778e73c02c414db772f790540e626d2c;p=libs%2Fgltk.git diff --git a/source/container.h b/source/container.h index 45985bc..d100dac 100644 --- a/source/container.h +++ b/source/container.h @@ -1,6 +1,7 @@ #ifndef MSP_GLTK_CONTAINER_H_ #define MSP_GLTK_CONTAINER_H_ +#include #include #include #include @@ -23,10 +24,12 @@ protected: struct Child: public sigc::trackable { Container &container; + std::unique_ptr own_widget; Widget *widget = nullptr; Time::TimeDelta time_since_animate; Child(Container &, Widget *); + Child(Container &, std::unique_ptr); virtual ~Child(); void visibility_changed(bool); @@ -37,7 +40,7 @@ protected: void rebuild_needed(); }; - std::vector children; + std::vector> children; Widget *click_focus = nullptr; unsigned click_button = 0; Widget *pointer_focus = nullptr; @@ -51,9 +54,15 @@ protected: public: virtual ~Container(); - void add(Widget &); + void add(Widget &w) { add_child(w); } + void add(std::unique_ptr); + + template + T &add_new(Args &&...); + void remove(Widget &); protected: + Child &add_child(Widget &); Geometry determine_child_geometry(const Widget &, const Part &) const; void autosize_child(const Widget &, const Part &, Geometry &) const; void reposition_child(Widget &, const Part &) const; @@ -101,6 +110,16 @@ protected: virtual void on_input_focus_changed(Widget *); }; + +template +T &Container::add_new(Args &&... args) +{ + std::unique_ptr wdg = std::make_unique(std::forward(args)...); + T *ptr = wdg.get(); + add(move(wdg)); + return *ptr; +} + } // namespace GLtk } // namespace Msp