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::dummy(); siv.add_layer(Dialog::around(time_select) .title("How long is your wait?"));
Methods
impl<T: 'static> SelectView<T>
[src]
impl<T: 'static> SelectView<T>
pub fn new() -> Self
[src]
pub fn new() -> Self
Creates a new empty SelectView.
pub fn popup(self) -> Self
[src]
pub fn popup(self) -> Self
Turns self
into a popup select view.
Chainable variant.
pub fn set_popup(&mut self, popup: bool)
[src]
pub fn set_popup(&mut self, popup: bool)
Turns self
into a popup select view.
pub fn disable(&mut self)
[src]
pub fn disable(&mut self)
Disables this view.
A disabled view cannot be selected.
pub fn disabled(self) -> Self
[src]
pub fn disabled(self) -> Self
Disables this view.
Chainable variant.
pub fn enable(&mut self)
[src]
pub fn enable(&mut self)
Re-enables this view.
pub fn set_enabled(&mut self, enabled: bool)
[src]
pub fn set_enabled(&mut self, enabled: bool)
Enable or disable this view.
pub fn is_enabled(&self) -> bool
[src]
pub fn is_enabled(&self) -> bool
Returns true
if this view is enabled.
pub fn set_on_select<F>(&mut self, cb: F) where
F: Fn(&mut Cursive, &T) + 'static,
[src]
pub fn set_on_select<F>(&mut self, cb: F) where
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) -> Self where
F: Fn(&mut Cursive, &T) + 'static,
[src]
pub fn on_select<F>(self, cb: F) -> Self where
F: Fn(&mut Cursive, &T) + 'static,
Sets a callback to be used when an item is selected.
Chainable variant.
pub fn set_on_submit<F, R, V: ?Sized>(&mut self, cb: F) where
F: 'static + Fn(&mut Cursive, &V) -> R,
T: Borrow<V>,
[src]
pub fn set_on_submit<F, R, V: ?Sized>(&mut self, cb: F) where
F: 'static + Fn(&mut Cursive, &V) -> R,
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
.
pub fn on_submit<F, V: ?Sized>(self, cb: F) -> Self where
F: Fn(&mut Cursive, &V) + 'static,
T: Borrow<V>,
[src]
pub fn on_submit<F, V: ?Sized>(self, cb: F) -> Self where
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.
pub fn align(self, align: Align) -> Self
[src]
pub fn align(self, align: Align) -> Self
Sets the alignment for this view.
pub fn v_align(self, v: VAlign) -> Self
[src]
pub fn v_align(self, v: VAlign) -> Self
Sets the vertical alignment for this view. (If the view is given too much space vertically.)
pub fn h_align(self, h: HAlign) -> Self
[src]
pub fn h_align(self, h: HAlign) -> Self
Sets the horizontal alignment for this view.
pub fn selection(&self) -> Option<Rc<T>>
[src]
pub fn selection(&self) -> Option<Rc<T>>
Returns the value of the currently selected item.
Returns None
if the list is empty.
pub fn clear(&mut self)
[src]
pub fn clear(&mut self)
Removes all items from this view.
pub fn add_item<S: Into<String>>(&mut self, label: S, value: T)
[src]
pub fn add_item<S: Into<String>>(&mut self, label: S, value: T)
Adds a item to the list, with given label and value.
pub fn get_item(&self, i: usize) -> Option<(&str, &T)>
[src]
pub fn get_item(&self, i: usize) -> Option<(&str, &T)>
Gets an item at given idx or None.
use cursive::Cursive; use cursive::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 String, &mut T)>
[src]
pub fn get_item_mut(&mut self, i: usize) -> Option<(&mut String, &mut T)>
Gets a mut item at given idx or None.
pub fn remove_item(&mut self, id: usize) -> Callback
[src]
pub fn remove_item(&mut self, id: usize) -> Callback
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<String>,
[src]
pub fn insert_item<S>(&mut self, index: usize, label: S, value: T) where
S: Into<String>,
Inserts an item at position index
, shifting all elements after it to
the right.
pub fn item<S: Into<String>>(self, label: S, value: T) -> Self
[src]
pub fn item<S: Into<String>>(self, label: S, value: T) -> Self
Chainable variant of add_item
pub fn add_all<S, I>(&mut self, iter: I) where
S: Into<String>,
I: IntoIterator<Item = (S, T)>,
[src]
pub fn add_all<S, I>(&mut self, iter: I) where
S: Into<String>,
I: IntoIterator<Item = (S, T)>,
Adds all items from from an iterator.
pub fn with_all<S, I>(self, iter: I) -> Self where
S: Into<String>,
I: IntoIterator<Item = (S, T)>,
[src]
pub fn with_all<S, I>(self, iter: I) -> Self where
S: Into<String>,
I: IntoIterator<Item = (S, T)>,
Adds all items from from an iterator.
Chainable variant.
pub fn selected_id(&self) -> Option<usize>
[src]
pub fn selected_id(&self) -> Option<usize>
Returns the id of the item currently selected.
Returns None
if the list is empty.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the number of items in this list.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true
if this list has no item.
pub fn set_selection(&mut self, i: usize) -> Callback
[src]
pub fn set_selection(&mut self, i: usize) -> Callback
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) -> Self
[src]
pub fn selected(self, i: usize) -> Self
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]
pub fn select_up(&mut self, n: usize) -> Callback
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]
pub fn select_down(&mut self, n: usize) -> Callback
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]
impl SelectView<String>
pub fn add_item_str<S: Into<String>>(&mut self, label: S)
[src]
pub fn add_item_str<S: Into<String>>(&mut self, label: S)
Convenient method to use the label as value.
pub fn item_str<S: Into<String>>(self, label: S) -> Self
[src]
pub fn item_str<S: Into<String>>(self, label: S) -> Self
Chainable variant of add_item_str
pub fn insert_item_str<S>(&mut self, index: usize, label: S) where
S: Into<String>,
[src]
pub fn insert_item_str<S>(&mut self, index: usize, label: S) where
S: Into<String>,
Convenient method to use the label as value.
pub fn add_all_str<S, I>(&mut self, iter: I) where
S: Into<String>,
I: IntoIterator<Item = S>,
[src]
pub fn add_all_str<S, I>(&mut self, iter: I) where
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"]);
pub fn with_all_str<S, I>(self, iter: I) -> Self where
S: Into<String>,
I: IntoIterator<Item = S>,
[src]
pub fn with_all_str<S, I>(self, iter: I) -> Self where
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> Default for SelectView<T>
impl<T: 'static> View for SelectView<T>
[src]
impl<T: 'static> View for SelectView<T>
fn draw(&self, printer: &Printer)
[src]
fn draw(&self, printer: &Printer)
Draws the view with the given printer (includes bounds) and focus. Read more
fn required_size(&mut self, _: Vec2) -> Vec2
[src]
fn required_size(&mut self, _: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions. Read more
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn on_event(&mut self, event: Event) -> EventResult
Called when an event is received (key press, mouse event, ...). Read more
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn take_focus(&mut self, _: Direction) -> bool
This view is offered focus. Will it take it? Read more
fn layout(&mut self, size: Vec2)
[src]
fn layout(&mut self, size: Vec2)
Called once the size for this view has been decided. Read more
fn important_area(&self, size: Vec2) -> Rect
[src]
fn important_area(&self, size: Vec2) -> Rect
What part of the view is important and should be visible? Read more
fn needs_relayout(&self) -> bool
[src]
fn needs_relayout(&self) -> bool
Returns true
if the view content changed since last layout phase. Read more
fn call_on_any<'a>(&mut self, _: &Selector, _: AnyCb<'a>)
[src]
fn call_on_any<'a>(&mut self, _: &Selector, _: AnyCb<'a>)
Runs a closure on the view identified by the given selector. Read more
fn focus_view(&mut self, &Selector) -> Result<(), ()>
[src]
fn focus_view(&mut self, &Selector) -> Result<(), ()>
Moves the focus to the view identified by the given selector. Read more
Auto Trait Implementations
impl<T = String> !Send for SelectView<T>
impl<T = String> !Send for SelectView<T>
impl<T = String> !Sync for SelectView<T>
impl<T = String> !Sync for SelectView<T>