namespace Msp {
namespace GLtk {
+DataFile::LoadableTypeRegistry<Panel::Loader, Panel::Loader::AddChildType> Panel::widget_registry;
+bool Panel::widget_registry_init_done = false;
+
Panel::Panel():
layout(0)
{
wdg_map(m),
last_widget(0)
{
- add_child_type<Button>("button");
+ if(!widget_registry_init_done)
+ {
+ widget_registry_init_done = true;
+ register_child_type<Button>("button");
+ register_child_type<DragHandle>("draghandle");
+ register_child_type<Dropdown>("dropdown");
+ register_child_type<Entry>("entry");
+ register_child_type<HSlider>("hslider");
+ register_child_type<Image>("image");
+ register_child_type<Indicator>("indicator");
+ register_child_type<Label>("label");
+ register_child_type<List>("list");
+ register_child_type<Panel>("panel");
+ register_child_type<Toggle>("toggle");
+ register_child_type<VSlider>("vslider");
+ }
+
add("column", &Loader::arrangement<Column>);
add("constraint",&Loader::constraint);
- 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_child_type<HSlider>("hslider");
- add_child_type<Image>("image");
- add_child_type<Indicator>("indicator");
- add_child_type<Label>("label");
add("layout", &Loader::layout);
- add_child_type<List>("list");
- add_child_type<Panel>("panel");
add("row", &Loader::arrangement<Row>);
add("stack", &Loader::arrangement<Stack>);
- 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>);
+ widget_registry.add_all(*this);
}
Layout &Panel::Loader::get_layout()
load_sub_with(ldr);
}
-template<typename T>
-void Panel::Loader::child(const string &n)
-{
- unnamed_child<T>();
- wdg_map[n] = last_widget;
-}
-
void Panel::Loader::constraint(Layout::ConstraintType type, const string &n)
{
Widget &src = get_last_widget();
load_sub_with(ldr);
}
-template<typename T>
-void Panel::Loader::unnamed_child()
-{
- RefPtr<T> chl = new T();
- load_sub(*chl);
- obj.add(*chl.get());
- last_widget = chl.release();
-}
-
template<>
void Panel::Loader::unnamed_child<Panel>()
{
last_widget = pnl.release();
}
+
template<typename T>
Panel::ArrangedLoader<T>::ArrangedLoader(Loader &ldr, T &arr):
arr_loader(arr)
#ifndef MSP_GLTK_PANEL_H_
#define MSP_GLTK_PANEL_H_
+#include <msp/datafile/loadabletyperegistry.h>
#include "container.h"
#include "layout.h"
typedef std::map<std::string, Widget *> WidgetMap;
protected:
+ template<typename T>
+ struct AddChildType
+ {
+ static void add(Loader &, const std::string &);
+ };
+
WidgetMap &wdg_map;
Widget *last_widget;
Loader(Panel &, WidgetMap &);
private:
- template<typename T>
- void add_child_type(const std::string &);
Layout &get_layout();
Widget &get_last_widget();
template<typename T>
void layout();
template<typename T>
void unnamed_child();
+
+ friend class Panel;
};
private:
std::vector<Widget *> nav_order;
Layout *layout;
+ static DataFile::LoadableTypeRegistry<Loader, Loader::AddChildType> widget_registry;
+ static bool widget_registry_init_done;
+
Panel(const Panel &);
Panel &operator=(const Panel &);
public:
Panel();
virtual ~Panel();
+ template<typename T>
+ static void register_child_type(const std::string &);
+
virtual const char *get_class() const { return "panel"; }
void set_layout(Layout *);
virtual void on_child_removed(Widget &);
};
+
+template<typename T>
+void Panel::register_child_type(const std::string &name)
+{
+ widget_registry.register_type<T>(name);
+}
+
+
+template<typename T>
+void Panel::Loader::child(const std::string &n)
+{
+ unnamed_child<T>();
+ wdg_map[n] = last_widget;
+}
+
+template<typename T>
+void Panel::Loader::unnamed_child()
+{
+ RefPtr<T> chl = new T();
+ load_sub(*chl);
+ obj.add(*chl.get());
+ last_widget = chl.release();
+}
+
+
+template<typename T>
+void Panel::Loader::AddChildType<T>::add(Loader &ldr, const std::string &kwd)
+{
+ ldr.add(kwd, &Loader::child<T>);
+ ldr.add(kwd, &Loader::unnamed_child<T>);
+}
+
} // namespace GLtk
} // namespace Msp