2016-08-13 08:03:40 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
2016-09-29 05:45:27 +00:00
|
|
|
use cursive::Cursive;
|
|
|
|
use cursive::traits::*;
|
2017-02-07 02:18:17 +00:00
|
|
|
use cursive::views::{Dialog, SliderView};
|
2016-08-13 08:03:40 +00:00
|
|
|
|
|
|
|
fn main() {
|
2018-04-01 23:39:03 +00:00
|
|
|
let mut siv = Cursive::default();
|
2016-08-13 08:03:40 +00:00
|
|
|
|
2018-01-16 02:55:27 +00:00
|
|
|
siv.add_global_callback('q', |s| s.quit());
|
|
|
|
|
2016-08-13 08:03:40 +00:00
|
|
|
// Let's add a simple slider in a dialog.
|
|
|
|
// Moving the slider will update the dialog's title.
|
|
|
|
// And pressing "Enter" will show a new dialog.
|
2017-10-12 23:38:55 +00:00
|
|
|
siv.add_layer(
|
|
|
|
Dialog::around(
|
2018-01-16 02:55:27 +00:00
|
|
|
// We give the number of steps in the constructor
|
2017-10-12 23:38:55 +00:00
|
|
|
SliderView::horizontal(15)
|
2018-01-16 02:55:27 +00:00
|
|
|
// Sets the initial value
|
2017-10-12 23:38:55 +00:00
|
|
|
.value(7)
|
|
|
|
.on_change(|s, v| {
|
|
|
|
let title = format!("[ {} ]", v);
|
2017-12-30 22:03:42 +00:00
|
|
|
s.call_on_id("dialog", |view: &mut Dialog| {
|
|
|
|
view.set_title(title)
|
|
|
|
});
|
2017-10-12 23:38:55 +00:00
|
|
|
})
|
|
|
|
.on_enter(|s, v| {
|
|
|
|
s.pop_layer();
|
|
|
|
s.add_layer(
|
|
|
|
Dialog::text(format!("Lucky number {}!", v))
|
|
|
|
.button("Ok", Cursive::quit),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
).title("[ 7 ]")
|
|
|
|
.with_id("dialog"),
|
|
|
|
);
|
2016-08-13 08:03:40 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|