mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add SelectView.get_item
This commit is contained in:
parent
9510d92736
commit
4dc403df78
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user