Add remove_item to SelectView

And made `focus` public.
This commit is contained in:
Alexandre Bury 2016-08-31 17:00:48 -07:00
parent 2afe9787c2
commit 0e08d7d058

View File

@ -195,6 +195,15 @@ impl<T: 'static> SelectView<T> {
self.items.push(Item::new(label.into(), value)); self.items.push(Item::new(label.into(), value));
} }
/// Removes an item from the list.
pub fn remove_item(&mut self, id: usize) {
self.items.remove(id);
let focus = self.focus();
if focus > id {
self.focus.set(focus - 1);
}
}
/// Chainable variant of add_item /// Chainable variant of add_item
pub fn item<S: Into<String>>(self, label: S, value: T) -> Self { pub fn item<S: Into<String>>(self, label: S, value: T) -> Self {
self.with(|s| s.add_item(label, value)) self.with(|s| s.add_item(label, value))
@ -230,7 +239,8 @@ impl<T: 'static> SelectView<T> {
} }
} }
fn focus(&self) -> usize { /// Returns the id of the item currently selected.
pub fn focus(&self) -> usize {
self.focus.get() self.focus.get()
} }