2017-02-07 02:18:17 +00:00
|
|
|
use cursive::traits::*;
|
2018-06-11 06:29:10 +00:00
|
|
|
use cursive::views::{
|
|
|
|
Checkbox, Dialog, EditView, LinearLayout, ListView, SelectView, TextView,
|
|
|
|
};
|
|
|
|
use cursive::Cursive;
|
2016-07-16 20:25:21 +00:00
|
|
|
|
2018-01-16 02:55:27 +00:00
|
|
|
// This example uses a ListView.
|
|
|
|
//
|
|
|
|
// ListView can be used to build forms, with a list of inputs.
|
|
|
|
|
2016-07-16 20:25:21 +00:00
|
|
|
fn main() {
|
2018-04-01 23:39:03 +00:00
|
|
|
let mut siv = Cursive::default();
|
2016-07-16 20:25:21 +00:00
|
|
|
|
2017-10-12 23:38:55 +00:00
|
|
|
siv.add_layer(
|
|
|
|
Dialog::new()
|
|
|
|
.title("Please fill out this form")
|
|
|
|
.button("Ok", |s| s.quit())
|
|
|
|
.content(
|
|
|
|
ListView::new()
|
2018-01-16 02:55:27 +00:00
|
|
|
// Each child is a single-line view with a label
|
2017-10-12 23:38:55 +00:00
|
|
|
.child("Name", EditView::new().fixed_width(10))
|
|
|
|
.child(
|
|
|
|
"Receive spam?",
|
2017-12-30 22:03:42 +00:00
|
|
|
Checkbox::new().on_change(|s, checked| {
|
2018-01-16 02:55:27 +00:00
|
|
|
// Enable/Disable the next field depending on this checkbox
|
2017-12-30 22:03:42 +00:00
|
|
|
for name in &["email1", "email2"] {
|
2020-01-06 23:39:30 +00:00
|
|
|
s.call_on_name(name, |view: &mut EditView| {
|
2017-10-12 23:38:55 +00:00
|
|
|
view.set_enabled(checked)
|
|
|
|
});
|
|
|
|
if checked {
|
2020-01-06 23:39:30 +00:00
|
|
|
s.focus_name("email1").unwrap();
|
2017-10-12 23:38:55 +00:00
|
|
|
}
|
2017-12-30 22:03:42 +00:00
|
|
|
}
|
|
|
|
}),
|
2017-10-12 23:38:55 +00:00
|
|
|
)
|
|
|
|
.child(
|
|
|
|
"Email",
|
2018-01-16 02:55:27 +00:00
|
|
|
// Each child must have a height of 1 line,
|
|
|
|
// but we can still combine multiple views!
|
2017-10-12 23:38:55 +00:00
|
|
|
LinearLayout::horizontal()
|
|
|
|
.child(
|
|
|
|
EditView::new()
|
|
|
|
.disabled()
|
2020-01-06 23:39:30 +00:00
|
|
|
.with_name("email1")
|
2017-10-12 23:38:55 +00:00
|
|
|
.fixed_width(15),
|
|
|
|
)
|
|
|
|
.child(TextView::new("@"))
|
|
|
|
.child(
|
|
|
|
EditView::new()
|
|
|
|
.disabled()
|
2020-01-06 23:39:30 +00:00
|
|
|
.with_name("email2")
|
2017-10-12 23:38:55 +00:00
|
|
|
.fixed_width(10),
|
|
|
|
),
|
|
|
|
)
|
2018-01-16 02:55:27 +00:00
|
|
|
// Delimiter currently are just a blank line
|
2017-10-12 23:38:55 +00:00
|
|
|
.delimiter()
|
|
|
|
.child(
|
|
|
|
"Age",
|
2018-01-16 02:55:27 +00:00
|
|
|
// Popup-mode SelectView are small enough to fit here
|
2017-10-12 23:38:55 +00:00
|
|
|
SelectView::new()
|
|
|
|
.popup()
|
|
|
|
.item_str("0-18")
|
|
|
|
.item_str("19-30")
|
|
|
|
.item_str("31-40")
|
|
|
|
.item_str("41+"),
|
|
|
|
)
|
2017-12-30 22:03:42 +00:00
|
|
|
.with(|list| {
|
2018-01-16 02:55:27 +00:00
|
|
|
// We can also add children procedurally
|
2017-12-30 22:03:42 +00:00
|
|
|
for i in 0..50 {
|
|
|
|
list.add_child(
|
|
|
|
&format!("Item {}", i),
|
|
|
|
EditView::new(),
|
|
|
|
);
|
|
|
|
}
|
2018-07-25 02:06:07 +00:00
|
|
|
})
|
|
|
|
.scrollable(),
|
2017-10-12 23:38:55 +00:00
|
|
|
),
|
|
|
|
);
|
2016-07-16 20:25:21 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|