Struct cursive_core::views::SliderView
source · pub struct SliderView { /* private fields */ }
Expand description
A horizontal or vertical slider.
Examples
use cursive_core::views::{Dialog, SliderView};
let slider_view = SliderView::horizontal(10)
.on_change(|s, n| {
if n == 5 {
s.add_layer(Dialog::info("5! Pick 5!"));
}
})
.on_enter(|s, n| match n {
5 => s.add_layer(Dialog::info("You did it!")),
n => s.add_layer(Dialog::info(format!("Why {}? Why not 5?", n))),
});
Implementations§
source§impl SliderView
impl SliderView
sourcepub fn new(orientation: Orientation, max_value: usize) -> Self
pub fn new(orientation: Orientation, max_value: usize) -> Self
Creates a new SliderView
in the given orientation.
The view will have a fixed length of max_value
,
with one tick per block.
The actual range of values for this slider is [0, max_value - 1]
.
sourcepub fn horizontal(max_value: usize) -> Self
pub fn horizontal(max_value: usize) -> Self
Creates a new horizontal SliderView
.
sourcepub fn set_value(&mut self, value: usize) -> EventResult
pub fn set_value(&mut self, value: usize) -> EventResult
Sets the current value.
Returns an event result with a possible callback,
if on_change
was set..
sourcepub fn get_max_value(&self) -> usize
pub fn get_max_value(&self) -> usize
Gets the max value.
Trait Implementations§
source§impl View for SliderView
impl View for SliderView
source§fn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Draws the view with the given printer (includes bounds) and focus. Read more
source§fn required_size(&mut self, _: Vec2) -> Vec2
fn required_size(&mut self, _: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions. Read more
source§fn on_event(&mut self, event: Event) -> EventResult
fn on_event(&mut self, event: Event) -> EventResult
Called when an event is received (key press, mouse event, …). Read more
source§fn take_focus(&mut self, _: Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, _: Direction) -> Result<EventResult, CannotFocus>
Attempt to give this view the focus. Read more
source§fn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
source§fn call_on_any<'a>(&mut self, _: &Selector<'_>, _: AnyCb<'a>)
fn call_on_any<'a>(&mut self, _: &Selector<'_>, _: AnyCb<'a>)
Runs a closure on the view identified by the given selector. Read more
source§fn focus_view(&mut self, _: &Selector<'_>) -> Result<EventResult, ViewNotFound>
fn focus_view(&mut self, _: &Selector<'_>) -> Result<EventResult, ViewNotFound>
Moves the focus to the view identified by the given selector. Read more