From 77c5c34cc13b2033afdce8ee87559cfc826fa101 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 29 Jan 2012 16:17:52 +0000 Subject: Improved scrollbar handling in ui::ListView --- src/ui/listview.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ui/listview.cc b/src/ui/listview.cc index cd87639..9fe9b4e 100644 --- a/src/ui/listview.cc +++ b/src/ui/listview.cc @@ -65,7 +65,7 @@ void ListView::resize() if (total_height - listview_scroll < 0) { // child widget is invisible (*it)->hide(); - } else if ((total_height - listview_scroll) >= height()) { + } else if ((total_height - listview_scroll + (*it)->height()) > height()) { // child widget is invisible (*it)->hide(); } else { @@ -77,9 +77,13 @@ void ListView::resize() } } - listview_scrollbar->set_range(0.0f, total_height); - listview_scrollbar->set_value(listview_scroll); - + if (total_height > height()) { + listview_scrollbar->set_range(0.0f, total_height - height()); + listview_scrollbar->set_value(listview_scroll); + listview_scrollbar->show(); + } else { + listview_scrollbar->hide(); + } } void ListView::deselect() @@ -96,6 +100,7 @@ void ListView::select(ListItem *item) void ListView::clear() { + listview_scroll = 0; listview_selecteditem = 0; remove_children(); @@ -103,6 +108,7 @@ void ListView::clear() listview_scrollbar->set_background(false); listview_scrollbar->set_border(false); listview_scrollbar->set_range(0.0f, 0.0f); + listview_scrollbar->set_value(listview_scroll); } bool ListView::on_emit(Widget *sender, const Event event, void *data) -- cgit v1.2.3