diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/listview.cc | 21 | ||||
-rw-r--r-- | src/ui/listview.h | 20 |
2 files changed, 21 insertions, 20 deletions
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(); |