From 0e08d7d05890eca3ce8312bb970f574797fc28a6 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Wed, 31 Aug 2016 17:00:48 -0700 Subject: [PATCH] Add `remove_item` to SelectView And made `focus` public. --- src/views/select_view.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 4a2fd8c..9ed0f05 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -195,6 +195,15 @@ impl SelectView { 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 pub fn item>(self, label: S, value: T) -> Self { self.with(|s| s.add_item(label, value)) @@ -230,7 +239,8 @@ impl SelectView { } } - fn focus(&self) -> usize { + /// Returns the id of the item currently selected. + pub fn focus(&self) -> usize { self.focus.get() }