[−][src]Struct cursive::views::SelectView
View to select an item among a list.
It contains a list of values of type T, with associated labels.
Examples
let mut time_select = SelectView::new().h_align(HAlign::Center); time_select.add_item("Short", 1); time_select.add_item("Medium", 5); time_select.add_item("Long", 10); time_select.set_on_submit(|s, time| { s.pop_layer(); let text = format!("You will wait for {} minutes...", time); s.add_layer(Dialog::around(TextView::new(text)) .button("Quit", |s| s.quit())); }); let mut siv = Cursive::dummy(); siv.add_layer(Dialog::around(time_select) .title("How long is your wait?"));
Implementations
impl<T> SelectView<T> where
T: 'static,
[src]
T: 'static,
pub fn disable(&mut self)
[src]
Disables this view.
A disabled view cannot be selected.
pub fn disabled(self) -> SelectView<T>
[src]
Disables this view.
Chainable variant.
pub fn enable(&mut self)
[src]
Re-enables this view.
pub fn set_enabled(&mut self, enabled: bool)
[src]
Enable or disable this view.
pub fn with_enabled(self, is_enabled: bool) -> SelectView<T>
[src]
Enable or disable this view.
Chainable variant.
pub fn is_enabled(&self) -> bool
[src]
Returns true
if this view is enabled.
pub fn new() -> SelectView<T>
[src]
Creates a new empty SelectView.
pub fn set_autojump(&mut self, autojump: bool)
[src]
Sets the "auto-jump" property for this view.
If enabled, when a key is pressed, the selection will jump to the next item beginning with the pressed letter.
pub fn autojump(self) -> SelectView<T>
[src]
Sets the "auto-jump" property for this view.
If enabled, when a key is pressed, the selection will jump to the next item beginning with the pressed letter.
Chainable variant.
pub fn popup(self) -> SelectView<T>
[src]
Turns self
into a popup select view.
Chainable variant.
pub fn set_popup(&mut self, popup: bool)
[src]
Turns self
into a popup select view.
pub fn set_on_select<F>(&mut self, cb: F) where
F: Fn(&mut Cursive, &T) + 'static,
[src]
F: Fn(&mut Cursive, &T) + 'static,
Sets a callback to be used when an item is selected.
pub fn on_select<F>(self, cb: F) -> SelectView<T> where
F: Fn(&mut Cursive, &T) + 'static,
[src]
F: Fn(&mut Cursive, &T) + 'static,
Sets a callback to be used when an item is selected.
Chainable variant.
Examples
use cursive_core::traits::Identifiable; use cursive_core::views::{TextView, SelectView}; let text_view = TextView::new("").with_name("text"); let select_view = SelectView::new() .item("One", 1) .item("Two", 2) .on_select(|s, item| { let content = match *item { 1 => "Content number one", 2 => "Content number two! Much better!", _ => unreachable!("no such item"), }; // Update the textview with the currently selected item. s.call_on_name("text", |v: &mut TextView| { v.set_content(content); }).unwrap(); });
pub fn set_on_submit<F, R, V>(&mut self, cb: F) where
F: 'static + Fn(&mut Cursive, &V) -> R,
T: Borrow<V>,
V: ?Sized,
[src]
F: 'static + Fn(&mut Cursive, &V) -> R,
T: Borrow<V>,
V: ?Sized,
Sets a callback to be used when <Enter>
is pressed.
Also happens if the user clicks an item.
The item currently selected will be given to the callback.
Here, V
can be T
itself, or a type that can be borrowed from T
.
pub fn on_submit<F, V>(self, cb: F) -> SelectView<T> where
F: Fn(&mut Cursive, &V) + 'static,
T: Borrow<V>,
V: ?Sized,
[src]
F: Fn(&mut Cursive, &V) + 'static,
T: Borrow<V>,
V: ?Sized,
Sets a callback to be used when <Enter>
is pressed.
Also happens if the user clicks an item.
The item currently selected will be given to the callback.
Chainable variant.
Examples
use cursive_core::views::{Dialog, SelectView}; let select_view = SelectView::new() .item("One", 1) .item("Two", 2) .on_submit(|s, item| { let content = match *item { 1 => "Content number one", 2 => "Content number two! Much better!", _ => unreachable!("no such item"), }; // Show a popup whenever the user presses <Enter>. s.add_layer(Dialog::info(content)); });
pub fn align(self, align: Align) -> SelectView<T>
[src]
Sets the alignment for this view.
Examples
use cursive_core::align; use cursive_core::views::SelectView; let select_view = SelectView::new() .item("One", 1) .align(align::Align::top_center());
pub fn v_align(self, v: VAlign) -> SelectView<T>
[src]
Sets the vertical alignment for this view. (If the view is given too much space vertically.)
pub fn h_align(self, h: HAlign) -> SelectView<T>
[src]
Sets the horizontal alignment for this view.
pub fn selection(&self) -> Option<Rc<T>>
[src]
Returns the value of the currently selected item.
Returns None
if the list is empty.
pub fn clear(&mut self)
[src]
Removes all items from this view.
pub fn add_item<S>(&mut self, label: S, value: T) where
S: Into<SpannedString<Style>>,
[src]
S: Into<SpannedString<Style>>,
Adds a item to the list, with given label and value.
Examples
use cursive_core::views::SelectView; let mut select_view = SelectView::new(); select_view.add_item("Item 1", 1); select_view.add_item("Item 2", 2);
pub fn get_item(&self, i: usize) -> Option<(&str, &T)>
[src]
Gets an item at given idx or None.
use cursive_core::Cursive; use cursive_core::views::{SelectView, TextView}; let select = SelectView::new() .item("Short", 1); assert_eq!(select.get_item(0), Some(("Short", &1)));
pub fn get_item_mut(
&mut self,
i: usize
) -> Option<(&mut SpannedString<Style>, &mut T)>
[src]
&mut self,
i: usize
) -> Option<(&mut SpannedString<Style>, &mut T)>
Gets a mut item at given idx or None.
pub fn iter_mut(
&mut self
) -> impl Iterator<Item = (&mut SpannedString<Style>, &mut T)> where
T: Clone,
[src]
&mut self
) -> impl Iterator<Item = (&mut SpannedString<Style>, &mut T)> where
T: Clone,
Iterate mutably on the items in this view.
Returns an iterator with each item and their labels.
In some cases some items will need to be cloned (for example if a
Rc<T>
is still alive after calling SelectView::selection()
).
If T
does not implement Clone
, check SelectView::try_iter_mut()
.
pub fn try_iter_mut(
&mut self
) -> impl Iterator<Item = (&mut SpannedString<Style>, Option<&mut T>)>
[src]
&mut self
) -> impl Iterator<Item = (&mut SpannedString<Style>, Option<&mut T>)>
Try to iterate mutably on the items in this view.
Returns an iterator with each item and their labels.
Some items may not be returned mutably, for example if a Rc<T>
is
still alive after calling SelectView::selection()
.
pub fn iter(&self) -> impl Iterator<Item = (&str, &T)>
[src]
Iterate on the items in this view.
Returns an iterator with each item and their labels.
pub fn remove_item(&mut self, id: usize) -> Callback
[src]
Removes an item from the list.
Returns a callback in response to the selection change.
You should run this callback with a &mut Cursive
.
pub fn insert_item<S>(&mut self, index: usize, label: S, value: T) where
S: Into<SpannedString<Style>>,
[src]
S: Into<SpannedString<Style>>,
Inserts an item at position index
, shifting all elements after it to
the right.
pub fn item<S>(self, label: S, value: T) -> SelectView<T> where
S: Into<SpannedString<Style>>,
[src]
S: Into<SpannedString<Style>>,
Chainable variant of add_item
Examples
use cursive_core::views::SelectView; let select_view = SelectView::new() .item("Item 1", 1) .item("Item 2", 2) .item("Surprise item", 42);
pub fn add_all<S, I>(&mut self, iter: I) where
I: IntoIterator<Item = (S, T)>,
S: Into<SpannedString<Style>>,
[src]
I: IntoIterator<Item = (S, T)>,
S: Into<SpannedString<Style>>,
Adds all items from from an iterator.
pub fn with_all<S, I>(self, iter: I) -> SelectView<T> where
I: IntoIterator<Item = (S, T)>,
S: Into<SpannedString<Style>>,
[src]
I: IntoIterator<Item = (S, T)>,
S: Into<SpannedString<Style>>,
Adds all items from from an iterator.
Chainable variant.
Examples
use cursive_core::views::SelectView; // Create a SelectView with 100 items let select_view = SelectView::new() .with_all((1u8..100).into_iter().map(|i| { (format!("Item {}", i), i) }));
pub fn selected_id(&self) -> Option<usize>
[src]
Returns the id of the item currently selected.
Returns None
if the list is empty.
pub fn len(&self) -> usize
[src]
Returns the number of items in this list.
Examples
use cursive_core::views::SelectView; let select_view = SelectView::new() .item("Item 1", 1) .item("Item 2", 2) .item("Item 3", 3); assert_eq!(select_view.len(), 3);
pub fn is_empty(&self) -> bool
[src]
Returns true
if this list has no item.
Examples
use cursive_core::views::SelectView; let mut select_view = SelectView::new(); assert!(select_view.is_empty()); select_view.add_item("Item 1", 1); select_view.add_item("Item 2", 2); assert!(!select_view.is_empty()); select_view.clear(); assert!(select_view.is_empty());
pub fn sort_by_label(&mut self)
[src]
Sort the current items lexicographically by their label.
Note that this does not change the current focus index, which means that the current selection will likely be changed by the sorting.
This sort is stable: items with identical label will not be reordered.
pub fn sort_by<F>(&mut self, compare: F) where
F: FnMut(&T, &T) -> Ordering,
[src]
F: FnMut(&T, &T) -> Ordering,
Sort the current items with the given comparator function.
Note that this does not change the current focus index, which means that the current selection will likely be changed by the sorting.
The given comparator function must define a total order for the items.
If the comparator function does not define a total order, then the order after the sort is unspecified.
This sort is stable: equal items will not be reordered.
pub fn sort_by_key<K, F>(&mut self, key_of: F) where
F: FnMut(&T) -> K,
K: Ord,
[src]
F: FnMut(&T) -> K,
K: Ord,
Sort the current items with the given key extraction function.
Note that this does not change the current focus index, which means that the current selection will likely be changed by the sorting.
This sort is stable: items with equal keys will not be reordered.
pub fn set_selection(&mut self, i: usize) -> Callback
[src]
Moves the selection to the given position.
Returns a callback in response to the selection change.
You should run this callback with a &mut Cursive
.
pub fn selected(self, i: usize) -> SelectView<T>
[src]
Sets the selection to the given position.
Chainable variant.
Does not apply on_select
callbacks.
pub fn select_up(&mut self, n: usize) -> Callback
[src]
Moves the selection up by the given number of rows.
Returns a callback in response to the selection change.
You should run this callback with a &mut Cursive
:
fn select_up(siv: &mut Cursive, view: &mut SelectView<()>) { let cb = view.select_up(1); cb(siv); }
pub fn select_down(&mut self, n: usize) -> Callback
[src]
Moves the selection down by the given number of rows.
Returns a callback in response to the selection change.
You should run this callback with a &mut Cursive
.
impl SelectView<String>
[src]
pub fn add_item_str<S>(&mut self, label: S) where
S: Into<String>,
[src]
S: Into<String>,
Convenient method to use the label as value.
pub fn item_str<S>(self, label: S) -> SelectView<String> where
S: Into<String>,
[src]
S: Into<String>,
Chainable variant of add_item_str
Examples
use cursive_core::views::SelectView; let select_view = SelectView::new() .item_str("Paris") .item_str("New York") .item_str("Tokyo");
pub fn insert_item_str<S>(&mut self, index: usize, label: S) where
S: Into<String>,
[src]
S: Into<String>,
Convenient method to use the label as value.
pub fn add_all_str<S, I>(&mut self, iter: I) where
I: IntoIterator<Item = S>,
S: Into<String>,
[src]
I: IntoIterator<Item = S>,
S: Into<String>,
Adds all strings from an iterator.
Examples
let mut select_view = SelectView::new(); select_view.add_all_str(vec!["a", "b", "c"]);
pub fn with_all_str<S, I>(self, iter: I) -> SelectView<String> where
I: IntoIterator<Item = S>,
S: Into<String>,
[src]
I: IntoIterator<Item = S>,
S: Into<String>,
Adds all strings from an iterator.
Chainable variant.
Examples
use cursive_core::views::SelectView; let text = "..."; // Maybe read some config file let select_view = SelectView::new() .with_all_str(text.lines());
impl<T> SelectView<T> where
T: 'static + Ord,
[src]
T: 'static + Ord,
pub fn sort(&mut self)
[src]
Sort the current items by their natural ordering.
Note that this does not change the current focus index, which means that the current selection will likely be changed by the sorting.
This sort is stable: items that are equal will not be reordered.
Trait Implementations
impl<T> Default for SelectView<T> where
T: 'static,
[src]
T: 'static,
pub fn default() -> SelectView<T>
[src]
impl<T> View for SelectView<T> where
T: 'static,
[src]
T: 'static,
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, XY<usize>) -> XY<usize>
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn important_area(&self, size: XY<usize>) -> Rect
[src]
pub fn needs_relayout(&self) -> bool
[src]
pub fn call_on_any(
&mut self,
&Selector<'_>,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
&Selector<'_>,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn focus_view(&mut self, &Selector<'_>) -> Result<(), ()>
[src]
pub fn type_name(&self) -> &'static str
[src]
Auto Trait Implementations
impl<T = String> !RefUnwindSafe for SelectView<T>
[src]
impl<T = String> !Send for SelectView<T>
[src]
impl<T = String> !Sync for SelectView<T>
[src]
impl<T> Unpin for SelectView<T>
[src]
impl<T = String> !UnwindSafe for SelectView<T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AnyView for T where
T: View,
[src]
T: View,
pub fn as_any(&self) -> &(dyn Any + 'static)
[src]
Downcast self to a Any
.
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
Downcast self to a mutable Any
.
pub fn as_boxed_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> Finder for T where
T: View,
[src]
T: View,
pub fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
pub fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
pub fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
pub fn find_name<V>(
&mut self,
name: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
[src]
&mut self,
name: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
pub fn find_id<V>(
&mut self,
id: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
[src]
&mut self,
id: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoBoxedView for T where
T: View,
[src]
T: View,
pub fn as_boxed_view(self) -> Box<dyn View + 'static, Global>
[src]
impl<T> Nameable for T where
T: View,
[src]
T: View,
pub fn with_name<S>(self, name: S) -> NamedView<Self> where
S: Into<String>,
[src]
S: Into<String>,
pub fn with_id<S>(self, id: S) -> NamedView<Self> where
S: Into<String>,
[src]
S: Into<String>,
impl<T> Resizable for T where
T: View,
[src]
T: View,
pub fn boxed(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
[src]
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
pub fn resized(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
[src]
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
pub fn fixed_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
pub fn fixed_width(self, width: usize) -> ResizedView<Self>
[src]
pub fn fixed_height(self, height: usize) -> ResizedView<Self>
[src]
pub fn full_screen(self) -> ResizedView<Self>
[src]
pub fn full_width(self) -> ResizedView<Self>
[src]
pub fn full_height(self) -> ResizedView<Self>
[src]
pub fn max_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
pub fn max_width(self, max_width: usize) -> ResizedView<Self>
[src]
pub fn max_height(self, max_height: usize) -> ResizedView<Self>
[src]
pub fn min_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
pub fn min_width(self, min_width: usize) -> ResizedView<Self>
[src]
pub fn min_height(self, min_height: usize) -> ResizedView<Self>
[src]
impl<T> Scrollable for T where
T: View,
[src]
T: View,
pub fn scrollable(self) -> ScrollView<Self>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.