X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcontainer.h;h=d100dacf94aaa80538194fc77e2d95a486c869b3;hb=HEAD;hp=26100b72d315234329b9814ffdd80d14fc50c8f8;hpb=d10d1de6d17c285c63d7b3cea549017aaa1ddb01;p=libs%2Fgltk.git diff --git a/source/container.h b/source/container.h index 26100b7..d100dac 100644 --- a/source/container.h +++ b/source/container.h @@ -1,8 +1,9 @@ #ifndef MSP_GLTK_CONTAINER_H_ #define MSP_GLTK_CONTAINER_H_ -#include +#include #include +#include #include #include "mspgltk_api.h" #include "widget.h" @@ -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::list children; + std::vector> children; Widget *click_focus = nullptr; unsigned click_button = 0; Widget *pointer_focus = nullptr; @@ -51,17 +54,22 @@ 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: - virtual Child *create_child(Widget *); + 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; public: - std::list get_children() const; - Widget *get_child_at(int, int) const; - Widget *get_descendant_at(int, int) const; + std::vector get_children() const; + Widget *find_child_at(int, int) const; + Widget *find_descendant_at(int, int) const; void raise(Widget &); protected: @@ -102,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