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>2013-03-10 14:04:08 +0000
committerStijn Buys <ingar@osirion.org>2013-03-10 14:04:08 +0000
commit57563d06e9947380a2cf4a7f97ca5835c4bd8b2b (patch)
tree1654f83f0a909ac05ab7f8e288055766403d186d
parent025a4defa7cc1ad42c86fe9e1b49d1cb6fa45737 (diff)
Improved ui::ListView::sort().
-rw-r--r--src/client/savegamemenu.cc2
-rw-r--r--src/ui/listview.cc21
-rw-r--r--src/ui/listview.h20
3 files changed, 22 insertions, 21 deletions
diff --git a/src/client/savegamemenu.cc b/src/client/savegamemenu.cc
index e6ad330..cb2cdeb 100644
--- a/src/client/savegamemenu.cc
+++ b/src/client/savegamemenu.cc
@@ -264,7 +264,7 @@ void SaveGameMenu::refresh()
}
}
- savegamemenu_filelistview->sort_reverse();
+ savegamemenu_filelistview->sort(false);
savegamemenu_filelistview->event_resize();
show_file_info();
diff --git a/src/ui/listview.cc b/src/ui/listview.cc
index ac2a4e8..0c01596 100644
--- a/src/ui/listview.cc
+++ b/src/ui/listview.cc
@@ -132,6 +132,11 @@ void ListView::clear()
listview_scrollbar->set_value(listview_scroll);
}
+ListItem *ListView::add_item(const std::string & text)
+{
+ return new ui::ListItem(this, text.c_str());
+}
+
bool ListView::on_emit(Widget *sender, const Event event, void *data)
{
if (sender == listview_scrollbar) {
@@ -173,7 +178,7 @@ bool ListView::on_keypress(const int key, const unsigned int modifier)
return false;
}
-bool compare_listitems(const Widget *first, const Widget *second)
+bool compare_listitems_ascending(const Widget *first, const Widget *second)
{
const ListItem *firstitem = dynamic_cast<const ListItem *>(first);
const ListItem *seconditem = dynamic_cast<const ListItem *>(second);
@@ -192,12 +197,8 @@ bool compare_listitems(const Widget *first, const Widget *second)
}
}
-void ListView::sort()
-{
- children().sort(compare_listitems);
-}
-bool compare_listitems_reverse(const Widget *first, const Widget *second)
+bool compare_listitems_descending(const Widget *first, const Widget *second)
{
const ListItem *firstitem = dynamic_cast<const ListItem *>(first);
const ListItem *seconditem = dynamic_cast<const ListItem *>(second);
@@ -216,9 +217,13 @@ bool compare_listitems_reverse(const Widget *first, const Widget *second)
}
}
-void ListView::sort_reverse()
+void ListView::sort(bool ascending)
{
- children().sort(compare_listitems_reverse);
+ if (ascending) {
+ children().sort(compare_listitems_ascending);
+ } else {
+ children().sort(compare_listitems_descending);
+ }
}
}
diff --git a/src/ui/listview.h b/src/ui/listview.h
index b4c00dc..7678b8b 100644
--- a/src/ui/listview.h
+++ b/src/ui/listview.h
@@ -41,6 +41,11 @@ public:
}
/* -- mutators --------------------------------------------- */
+
+ /**
+ * @brief add a new item
+ * */
+ ListItem *add_item(const std::string & text);
/// set scroll
void set_scroll(float scroll);
@@ -51,7 +56,7 @@ public:
/// scroll up
void dec_scroll(float scroll);
- /// clear all listitems
+ /// delete all listitems
void clear();
/// set selection to specified ListItem
@@ -61,18 +66,9 @@ public:
void deselect();
/**
- * @brief sort child ListItems according to their sortkey
- * Sort will fail with an assert error if the ListView
- * contains any non-ListItem child widgets
- * */
- void sort();
-
- /**
- * @brief reverse sort child ListItems according to their sortkey
- * Sort will fail with an assert error if the ListView
- * contains any non-ListItem child widgets
+ * @brief sort listitems according to their sortkey
* */
- void sort_reverse();
+ void sort(bool ascending = true);
protected:
virtual void resize();