2016-07-16 20:25:21 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
2016-09-29 05:45:27 +00:00
|
|
|
use cursive::Cursive;
|
2017-02-07 02:18:17 +00:00
|
|
|
use cursive::traits::*;
|
2016-09-29 05:45:27 +00:00
|
|
|
use cursive::views::{Checkbox, Dialog, EditView, LinearLayout, ListView,
|
|
|
|
SelectView, TextView};
|
2016-07-16 20:25:21 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut siv = Cursive::new();
|
|
|
|
|
2016-10-02 22:15:30 +00:00
|
|
|
siv.add_layer(Dialog::new()
|
2016-07-26 03:43:01 +00:00
|
|
|
.title("Please fill out this form")
|
|
|
|
.button("Ok", |s| s.quit())
|
|
|
|
.content(ListView::new()
|
2016-08-04 04:58:00 +00:00
|
|
|
.child("Name", EditView::new().fixed_width(10))
|
2017-03-29 02:00:46 +00:00
|
|
|
.child("Receive spam?",
|
|
|
|
Checkbox::new()
|
|
|
|
.on_change(|s, checked| for name in &["email1",
|
|
|
|
"email2"] {
|
|
|
|
s.call_on_id(name, |view: &mut EditView| {
|
|
|
|
view.set_enabled(checked)
|
|
|
|
});
|
|
|
|
if checked {
|
|
|
|
s.focus_id("email1").unwrap();
|
|
|
|
}
|
|
|
|
}))
|
2016-07-20 07:30:00 +00:00
|
|
|
.child("Email",
|
|
|
|
LinearLayout::horizontal()
|
|
|
|
.child(EditView::new()
|
|
|
|
.disabled()
|
2016-08-04 04:58:00 +00:00
|
|
|
.with_id("email1")
|
|
|
|
.fixed_width(15))
|
2016-07-20 07:30:00 +00:00
|
|
|
.child(TextView::new("@"))
|
|
|
|
.child(EditView::new()
|
|
|
|
.disabled()
|
2016-08-04 04:58:00 +00:00
|
|
|
.with_id("email2")
|
|
|
|
.fixed_width(10)))
|
2016-07-20 07:30:00 +00:00
|
|
|
.delimiter()
|
|
|
|
.child("Age",
|
2016-07-26 03:43:01 +00:00
|
|
|
SelectView::new()
|
|
|
|
.popup()
|
2016-07-20 07:30:00 +00:00
|
|
|
.item_str("0-18")
|
|
|
|
.item_str("19-30")
|
|
|
|
.item_str("31-40")
|
|
|
|
.item_str("41+"))
|
2017-02-07 02:18:17 +00:00
|
|
|
.with(|list| for i in 0..50 {
|
|
|
|
list.add_child(&format!("Item {}", i), EditView::new());
|
2016-07-26 03:43:01 +00:00
|
|
|
})));
|
2016-07-16 20:25:21 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|