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>2010-09-16 14:12:27 +0000
committerStijn Buys <ingar@osirion.org>2010-09-16 14:12:27 +0000
commit0c509866a37ab47ff0e48d357ca55e31658c37c2 (patch)
tree57f69397ac1b30ce42a3e3fcd19c2fd8ed67d4e0 /src/ui/listview.cc
parent3392cb739f212aea561eceb1781cd2e10e55c932 (diff)
map info support, initial trade window
Diffstat (limited to 'src/ui/listview.cc')
-rw-r--r--src/ui/listview.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/ui/listview.cc b/src/ui/listview.cc
new file mode 100644
index 0000000..56fa324
--- /dev/null
+++ b/src/ui/listview.cc
@@ -0,0 +1,68 @@
+/*
+ ui/listview.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/listview.h"
+
+namespace ui
+{
+
+ListView::ListView(Widget *parent) : Widget(parent)
+{
+ set_label("listview");
+ set_border(true);
+}
+
+ListView::~ListView()
+{
+}
+
+void ListView::set_scroll(float scroll)
+{
+ listview_scroll = scroll;
+ if (listview_scroll < 0)
+ listview_scroll = 0;
+
+ // calculate maximal scroll size
+ float top = 0;
+ for (Children::iterator it = children().begin(); it != children().end(); it++) {
+ top += (*it)->height();
+ }
+ if (listview_scroll > top) listview_scroll = top;
+}
+
+void ListView::inc_scroll(float scroll)
+{
+ set_scroll(listview_scroll + scroll);
+}
+
+void ListView::dec_scroll(float scroll)
+{
+ set_scroll(listview_scroll - scroll);
+}
+
+void ListView::resize()
+{
+ float content_top = 0;
+
+ // reposition all children within the container
+ for (Children::iterator it = children().begin(); it != children().end(); it++) {
+ (*it)->set_width(width());
+ if (content_top - listview_scroll < 0) {
+ // child widget is invisible
+ (*it)->hide();
+ } else if ((content_top - listview_scroll) >= height()) {
+ // child widget is invisible
+ (*it)->hide();
+ } else {
+ (*it)->show();
+ (*it)->set_location(0, content_top - listview_scroll);
+ }
+
+ content_top += (*it)->height();
+ }
+}
+
+}