Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-10-05 19:03:25 +0000
committerStijn Buys <ingar@osirion.org>2008-10-05 19:03:25 +0000
commitda9beb729c58ca2d91f67ab85a6728b628c27cf2 (patch)
tree96fd5df00a2431f40f515aa9fdf722377a0b6079 /src/ui/menu.cc
parent381c729e777b50771626703e60b422aafc791513 (diff)
user interface library
Diffstat (limited to 'src/ui/menu.cc')
-rw-r--r--src/ui/menu.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/ui/menu.cc b/src/ui/menu.cc
new file mode 100644
index 0000000..c20457d
--- /dev/null
+++ b/src/ui/menu.cc
@@ -0,0 +1,58 @@
+/*
+ ui/menu.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "ui/label.h"
+#include "ui/button.h"
+#include "ui/menu.h"
+#include "ui/ui.h"
+
+namespace ui {
+
+const float element_width = 256.0f;
+const float element_height = 64.0f;
+const float element_margin = 24.0f;
+
+Menu::Menu(Window *parent, const char *label) : Window(parent), menu_container(this)
+{
+ set_label(label);
+ set_border(false);
+
+ menu_container.set_label("container");
+}
+
+Menu::~Menu()
+{
+}
+
+void Menu::add_label(char const * text)
+{
+ new Label(&menu_container, text);
+}
+
+void Menu::add_button(char const *text, char const *command)
+{
+ new Button(&menu_container, text, command);
+}
+
+void Menu::resize()
+{
+ set_size(parent()->size().x, parent()->size().y);
+
+ float n = (float) menu_container.children().size();
+ menu_container.set_size(2.0f * element_width, n * (element_height + element_margin) + element_height);
+ menu_container.set_location(element_margin, (height() - menu_container.height()) / 2.0f);
+
+ // reposition all children within the container
+ size_t i = 0;
+ for (Children::iterator it = menu_container.children().begin(); it != menu_container.children().end(); it++) {
+ Widget *w = (*it);
+ w->set_size(element_width, element_height);
+ w->set_location(element_width * 0.5f, element_height * 0.5f + i * (element_height + element_margin));
+ i++;
+ }
+}
+
+}