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>2012-01-29 15:16:17 +0000
committerStijn Buys <ingar@osirion.org>2012-01-29 15:16:17 +0000
commit52bd0792d15e9a814cd38cf77b26784003b8569f (patch)
treeaaf0429fe0d93f66b3ecad49fb313523b3b24134 /src/ui/listview.cc
parent46b534fbc2b0468f112676ee3149a57088eff97b (diff)
Diffstat (limited to 'src/ui/listview.cc')
-rw-r--r--src/ui/listview.cc77
1 files changed, 55 insertions, 22 deletions
diff --git a/src/ui/listview.cc b/src/ui/listview.cc
index 99bcd3c..cd87639 100644
--- a/src/ui/listview.cc
+++ b/src/ui/listview.cc
@@ -11,12 +11,16 @@ namespace ui
ListView::ListView(Widget *parent) : Widget(parent)
{
+ listview_scroll = 0.0f;
+ listview_selecteditem = 0;
+
set_label("listview");
set_border(true);
set_background(true);
- listview_scroll = 0.0f;
- listview_selecteditem = 0;
+ listview_scrollbar = new ScrollBar(this);
+ listview_scrollbar->set_background(false);
+ listview_scrollbar->set_border(false);
}
ListView::~ListView()
@@ -30,11 +34,11 @@ void ListView::set_scroll(float scroll)
listview_scroll = 0;
// calculate maximal scroll size
- float top = 0;
- for (Children::iterator it = children().begin(); it != children().end(); it++) {
- top += (*it)->height();
+ float total_height = 0;
+ for (Children::iterator it = children().begin(); it != children().end(); it++) {
+ total_height += (*it)->height();
}
- if (listview_scroll > top) listview_scroll = top;
+ if (listview_scroll > total_height) listview_scroll = total_height;
}
void ListView::inc_scroll(float scroll)
@@ -49,24 +53,33 @@ void ListView::dec_scroll(float scroll)
void ListView::resize()
{
- float content_top = 0;
+ listview_scrollbar->set_size(font()->height(), height());
+ listview_scrollbar->set_location(width() - listview_scrollbar->width(), 0);
+
+ float total_height = 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);
+ if ((*it) != static_cast<Widget *>(listview_scrollbar)) {
+ (*it)->set_width(width() - listview_scrollbar->width());
+ if (total_height - listview_scroll < 0) {
+ // child widget is invisible
+ (*it)->hide();
+ } else if ((total_height - listview_scroll) >= height()) {
+ // child widget is invisible
+ (*it)->hide();
+ } else {
+ (*it)->show();
+ (*it)->set_location(0, total_height - listview_scroll);
+ }
+
+ total_height += (*it)->height();
}
-
- content_top += (*it)->height();
}
+
+ listview_scrollbar->set_range(0.0f, total_height);
+ listview_scrollbar->set_value(listview_scroll);
+
}
void ListView::deselect()
@@ -85,11 +98,23 @@ void ListView::clear()
{
listview_selecteditem = 0;
remove_children();
+
+ listview_scrollbar = new ScrollBar(this);
+ listview_scrollbar->set_background(false);
+ listview_scrollbar->set_border(false);
+ listview_scrollbar->set_range(0.0f, 0.0f);
}
bool ListView::on_emit(Widget *sender, const Event event, void *data)
{
- if ((sender->parent() == this) && (event == Widget::EventListItemClicked)) {
+ if (sender == listview_scrollbar) {
+ if (event == Widget::EventScrollBarChanged) {
+ listview_scroll = listview_scrollbar->value();
+ resize();
+ }
+ return true;
+
+ } else if ((sender->parent() == this) && (event == Widget::EventListItemClicked)) {
listview_selecteditem = static_cast<ListItem *>(sender);
emit(EventListViewChanged);
return true;
@@ -102,7 +127,11 @@ bool compare_listitems(const Widget *first, const Widget *second)
{
const ListItem *firstitem = dynamic_cast<const ListItem *>(first);
const ListItem *seconditem = dynamic_cast<const ListItem *>(second);
- assert(firstitem && seconditem);
+
+ if (!firstitem)
+ return true;
+ else if (!seconditem)
+ return false;
if (firstitem->sortkey() < seconditem->sortkey()) {
return true;
@@ -122,7 +151,11 @@ bool compare_listitems_reverse(const Widget *first, const Widget *second)
{
const ListItem *firstitem = dynamic_cast<const ListItem *>(first);
const ListItem *seconditem = dynamic_cast<const ListItem *>(second);
- assert(firstitem && seconditem);
+
+ if (!firstitem)
+ return true;
+ else if (!seconditem)
+ return false;
if (firstitem->sortkey() < seconditem->sortkey()) {
return false;