]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add nameless child keywords for Panel
authorMikko Rasa <tdb@tdb.fi>
Mon, 28 Nov 2016 00:35:12 +0000 (02:35 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 28 Nov 2016 00:35:12 +0000 (02:35 +0200)
Additionally, use a template specialization rather than separate function
for a child which is itself a Panel.

source/panel.cpp
source/panel.h

index dc2808ed4bf5a237d97aad9cd1ec75e068ac7580..b9ddbf18b969d757bff20b2ca5a551bb1c3af869 100644 (file)
@@ -178,27 +178,34 @@ Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
        wdg_map(m),
        last_widget(0)
 {
-       add("button",    &Loader::child<Button>);
+       add_child_type<Button>("button");
        add("column",    &Loader::arrangement<Column>);
        add("constraint",&Loader::constraint);
-       add("draghandle",&Loader::child<DragHandle>);
-       add("dropdown",  &Loader::child<Dropdown>);
-       add("entry",     &Loader::child<Entry>);
+       add_child_type<DragHandle>("draghandle");
+       add_child_type<Dropdown>("dropdown");
+       add_child_type<Entry>("entry");
        add("expand",    &Loader::expand);
        add("ghost",     &Loader::ghost);
        add("gravity",   &Loader::gravity);
        add("grid",      &Loader::grid);
-       add("hslider",   &Loader::child<HSlider>);
-       add("image",     &Loader::child<Image>);
-       add("indicator", &Loader::child<Indicator>);
-       add("label",     &Loader::child<Label>);
+       add_child_type<HSlider>("hslider");
+       add_child_type<Image>("image");
+       add_child_type<Indicator>("indicator");
+       add_child_type<Label>("label");
        add("layout",    &Loader::layout);
-       add("list",      &Loader::child<List>);
-       add("panel",     &Loader::panel);
+       add_child_type<List>("list");
+       add_child_type<Panel>("panel");
        add("row",       &Loader::arrangement<Row>);
        add("stack",     &Loader::arrangement<Stack>);
-       add("toggle",    &Loader::child<Toggle>);
-       add("vslider",   &Loader::child<VSlider>);
+       add_child_type<Toggle>("toggle");
+       add_child_type<VSlider>("vslider");
+}
+
+template<typename T>
+void Panel::Loader::add_child_type(const string &keyword)
+{
+       add(keyword, &Loader::child<T>);
+       add(keyword, &Loader::unnamed_child<T>);
 }
 
 Layout &Panel::Loader::get_layout()
@@ -228,10 +235,8 @@ void Panel::Loader::arrangement()
 template<typename T>
 void Panel::Loader::child(const string &n)
 {
-       RefPtr<T> chl = new T();
-       load_sub(*chl);
-       obj.add(*chl.get());
-       last_widget = wdg_map[n] = chl.release();
+       unnamed_child<T>();
+       wdg_map[n] = last_widget;
 }
 
 void Panel::Loader::constraint(Layout::ConstraintType type, const string &n)
@@ -269,14 +274,23 @@ void Panel::Loader::layout()
        load_sub_with(ldr);
 }
 
-void Panel::Loader::panel(const string &n)
+template<typename T>
+void Panel::Loader::unnamed_child()
 {
-       RefPtr<Panel> p = new Panel();
-       load_sub(*p, wdg_map);
-       obj.add(*p.get());
-       last_widget = wdg_map[n] = p.release();
+       RefPtr<T> chl = new T();
+       load_sub(*chl);
+       obj.add(*chl.get());
+       last_widget = chl.release();
 }
 
+template<>
+void Panel::Loader::unnamed_child<Panel>()
+{
+       RefPtr<Panel> pnl = new Panel();
+       load_sub(*pnl, wdg_map);
+       obj.add(*pnl.get());
+       last_widget = pnl.release();
+}
 
 template<typename T>
 Panel::ArrangedLoader<T>::ArrangedLoader(Loader &ldr, T &arr):
index 2bc7a5ffdfa01ff7ce80af7a16f67d3afb54e1b4..8d67d14ffe46ff7b7ef5afaedfb83ce912da09b9 100644 (file)
@@ -26,7 +26,10 @@ public:
 
        public:
                Loader(Panel &, WidgetMap &);
+
        private:
+               template<typename T>
+               void add_child_type(const std::string &);
                Layout &get_layout();
                Widget &get_last_widget();
                template<typename T>
@@ -39,7 +42,8 @@ public:
                void gravity(int, int);
                void grid(unsigned);
                void layout();
-               void panel(const std::string &);
+               template<typename T>
+               void unnamed_child();
        };
 
 private: