Add SelectView.get_item

This commit is contained in:
Tymoteusz Jankowski 2018-01-26 13:25:19 +01:00
parent 9510d92736
commit 4dc403df78

View File

@ -215,6 +215,19 @@ impl<T: 'static> SelectView<T> {
self.items.push(Item::new(label.into(), value));
}
/// Gets an item at given idx or None.
///
/// ```
/// use cursive::Cursive;
/// use cursive::views::{SelectView, TextView};
/// let select = SelectView::new()
/// .item("Short", 1);
/// assert_eq!(select.get_item(0), Some(("Short", &1)));
/// ```
pub fn get_item(&self, i: usize) -> Option<(&str, &T)> {
self.items.get(i).map(|item| (item.label.as_ref(), &*item.value))
}
/// Removes an item from the list.
pub fn remove_item(&mut self, id: usize) {
self.items.remove(id);