Struct cursive::views::SelectView
[−]
[src]
pub struct SelectView<T = String> { /* fields omitted */ }
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::new(); siv.add_layer(Dialog::around(time_select) .title("How long is your wait?"));
Methods
impl<T: 'static> SelectView<T>
[src]
fn new() -> Self
[src]
Creates a new empty SelectView.
fn popup(self) -> Self
[src]
Turns self
into a popup select view.
Chainable variant.
fn set_popup(&mut self, popup: bool)
[src]
Turns self
into a popup select view.
fn disable(&mut self)
[src]
Disables this view.
A disabled view cannot be selected.
fn disabled(self) -> Self
[src]
Disables this view.
Chainable variant.
fn enable(&mut self)
[src]
Re-enables this view.
fn set_enabled(&mut self, enabled: bool)
[src]
Enable or disable this view.
fn is_enabled(&self) -> bool
[src]
Returns true
if this view is enabled.
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.
fn on_select<F>(self, cb: F) -> Self 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.
fn set_on_submit<F, V: ?Sized>(&mut self, cb: F) where
F: Fn(&mut Cursive, &V) + 'static,
T: Borrow<V>,
[src]
F: Fn(&mut Cursive, &V) + 'static,
T: Borrow<V>,
Sets a callback to be used when <Enter>
is pressed.
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
.
fn on_submit<F, V: ?Sized>(self, cb: F) -> Self where
F: Fn(&mut Cursive, &V) + 'static,
T: Borrow<V>,
[src]
F: Fn(&mut Cursive, &V) + 'static,
T: Borrow<V>,
Sets a callback to be used when <Enter>
is pressed.
The item currently selected will be given to the callback.
Chainable variant.
fn align(self, align: Align) -> Self
[src]
Sets the alignment for this view.
fn v_align(self, v: VAlign) -> Self
[src]
Sets the vertical alignment for this view. (If the view is given too much space vertically.)
fn h_align(self, h: HAlign) -> Self
[src]
Sets the horizontal alignment for this view.
fn selection(&self) -> Rc<T>
[src]
Returns the value of the currently selected item.
Panics if the list is empty.
fn clear(&mut self)
[src]
Removes all items from this view.
fn add_item<S: Into<String>>(&mut self, label: S, value: T)
[src]
Adds a item to the list, with given label and value.
fn remove_item(&mut self, id: usize)
[src]
Removes an item from the list.
fn item<S: Into<String>>(self, label: S, value: T) -> Self
[src]
Chainable variant of add_item
fn add_all<S, I>(&mut self, iter: I) where
S: Into<String>,
I: IntoIterator<Item = (S, T)>,
[src]
S: Into<String>,
I: IntoIterator<Item = (S, T)>,
Adds all items from from an iterator.
fn with_all<S, I>(self, iter: I) -> Self where
S: Into<String>,
I: IntoIterator<Item = (S, T)>,
[src]
S: Into<String>,
I: IntoIterator<Item = (S, T)>,
Adds all items from from an iterator.
Chainable variant.
fn selected_id(&self) -> Option<usize>
[src]
Returns the id of the item currently selected.
Returns None
if the list is empty.
fn len(&self) -> usize
[src]
Returns the number of items in this list.
fn is_empty(&self) -> bool
[src]
Returns true
if this list has no item.
fn set_selection(&mut self, i: usize)
[src]
Moves the selection to the given position.
fn select_up(&mut self, n: usize)
[src]
Moves the selection up by the given number of rows.
fn select_down(&mut self, n: usize)
[src]
Moves the selection down by the given number of rows.
impl SelectView<String>
[src]
fn add_item_str<S: Into<String>>(&mut self, label: S)
[src]
Convenient method to use the label as value.
fn item_str<S: Into<String>>(self, label: S) -> Self
[src]
Chainable variant of add_item_str
fn add_all_str<S, I>(&mut self, iter: I) where
S: Into<String>,
I: IntoIterator<Item = S>,
[src]
S: Into<String>,
I: IntoIterator<Item = S>,
Adds all strings from an iterator.
Examples
let mut select_view = SelectView::new(); select_view.add_all_str(vec!["a", "b", "c"]);
fn with_all_str<S, I>(self, iter: I) -> Self where
S: Into<String>,
I: IntoIterator<Item = S>,
[src]
S: Into<String>,
I: IntoIterator<Item = S>,
Adds all strings from an iterator.
Chainable variant.
Trait Implementations
impl<T: 'static> Default for SelectView<T>
[src]
impl<T: 'static> View for SelectView<T>
[src]
fn draw(&self, printer: &Printer)
[src]
Draws the view with the given printer (includes bounds) and focus.
fn required_size(&mut self, req: Vec2) -> Vec2
[src]
Returns the minimum size the view requires with the given restrictions. Read more
fn on_event(&mut self, event: Event) -> EventResult
[src]
Called when a key was pressed. Read more
fn take_focus(&mut self, _: Direction) -> bool
[src]
This view is offered focus. Will it take it? Read more
fn layout(&mut self, size: Vec2)
[src]
Called once the size for this view has been decided, Read more
fn needs_relayout(&self) -> bool
[src]
Returns true
if the view content changed since last layout phase. Read more
fn call_on_any<'a>(&mut self, _: &Selector, _: Box<FnMut(&mut Any) + 'a>)
[src]
Runs a closure on the view identified by the given selector. Read more
fn focus_view(&mut self, &Selector) -> Result<(), ()>
[src]
Moves the focus to the view identified by the given selector. Read more