]> git.tdb.fi Git - libs/gltk.git/blobdiff - examples/widgetdemo/demoselector.cpp
Add another example application to demonstrate various widgets
[libs/gltk.git] / examples / widgetdemo / demoselector.cpp
diff --git a/examples/widgetdemo/demoselector.cpp b/examples/widgetdemo/demoselector.cpp
new file mode 100644 (file)
index 0000000..de8d027
--- /dev/null
@@ -0,0 +1,45 @@
+#include <msp/gltk/column.h>
+#include <msp/gltk/label.h>
+#include "demoselector.h"
+
+using namespace std;
+using namespace Msp;
+
+DemoSelector::DemoSelector():
+       demos(&get_demo_title),
+       current_demo(0)
+{
+       set_layout(new GLtk::Layout);
+       layout->set_margin(GLtk::Sides(8));
+
+       GLtk::Column col(*layout);
+
+       GLtk::Label *lbl = new GLtk::Label("Select a widget:");
+       add(*lbl);
+
+       list.set_data(demos);
+       list.signal_item_selected.connect(sigc::mem_fun(this, &DemoSelector::item_selected));
+       add(list);
+       layout->set_expand(list, true, true);
+}
+
+void DemoSelector::add_demo(const string &t, GLtk::Panel *p)
+{
+       Demo demo;
+       demo.title = t;
+       demo.panel = p;
+       demos.append(demo);
+}
+
+void DemoSelector::item_selected(unsigned i)
+{
+       if(current_demo)
+               current_demo->panel->set_visible(false);
+       current_demo = &demos.get(i);
+       current_demo->panel->set_visible(true);
+}
+
+string DemoSelector::get_demo_title(const Demo &demo)
+{
+       return demo.title;
+}