From 3588955f0b420123fcc3731fb3209d96ab86f85c Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 25 Mar 2018 00:30:48 -0700 Subject: [PATCH] Add `SelectView::insert_item` --- src/views/select_view.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 7919df1..f42f9fc 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -260,6 +260,15 @@ impl SelectView { self.make_select_cb().unwrap_or_else(Callback::dummy) } + /// Inserts an item at position `index`, shifting all elements after it to + /// the right. + pub fn insert_item(&mut self, index: usize, label: S, value: T) + where + S: Into, + { + self.items.insert(index, Item::new(label.into(), value)); + } + /// Chainable variant of add_item pub fn item>(self, label: S, value: T) -> Self { self.with(|s| s.add_item(label, value)) @@ -630,6 +639,12 @@ impl SelectView { self.with(|s| s.add_item_str(label)) } + /// Convenient method to use the label as value. + pub fn insert_item_str(&mut self, index: usize, label: S) where S: Into { + let label = label.into(); + self.insert_item(index, label.clone(), label); + } + /// Adds all strings from an iterator. /// /// # Examples