2016-10-02 21:55:19 +00:00
|
|
|
use cursive::views::{Dialog, DummyView, LinearLayout, RadioGroup};
|
|
|
|
|
2018-01-16 02:55:27 +00:00
|
|
|
// This example uses radio buttons.
|
|
|
|
|
2016-10-02 21:55:19 +00:00
|
|
|
fn main() {
|
2020-04-15 19:20:50 +00:00
|
|
|
let mut siv = cursive::default();
|
2016-10-02 21:55:19 +00:00
|
|
|
|
|
|
|
// We need to pre-create the groups for our RadioButtons.
|
|
|
|
let mut color_group: RadioGroup<String> = RadioGroup::new();
|
|
|
|
let mut size_group: RadioGroup<u32> = RadioGroup::new();
|
|
|
|
|
2017-10-12 23:38:55 +00:00
|
|
|
siv.add_layer(
|
|
|
|
Dialog::new()
|
2019-03-01 00:04:14 +00:00
|
|
|
.title("Make your selection")
|
|
|
|
// We'll have two columns side-by-side
|
|
|
|
.content(
|
|
|
|
LinearLayout::horizontal()
|
|
|
|
.child(
|
|
|
|
LinearLayout::vertical()
|
|
|
|
// The color group uses the label itself as stored value
|
|
|
|
// By default, the first item is selected.
|
|
|
|
.child(color_group.button_str("Red"))
|
|
|
|
.child(color_group.button_str("Green"))
|
|
|
|
.child(color_group.button_str("Blue")),
|
|
|
|
)
|
|
|
|
// A DummyView is used as a spacer
|
|
|
|
.child(DummyView)
|
|
|
|
.child(
|
|
|
|
LinearLayout::vertical()
|
|
|
|
// For the size, we store a number separately
|
|
|
|
.child(size_group.button(5, "Small"))
|
|
|
|
// The initial selection can also be overriden
|
|
|
|
.child(size_group.button(15, "Medium").selected())
|
|
|
|
// The large size is out of stock, sorry!
|
|
|
|
.child(size_group.button(25, "Large").disabled()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.button("Ok", move |s| {
|
|
|
|
// We retrieve the stored value for both group.
|
|
|
|
let color = color_group.selection();
|
|
|
|
let size = size_group.selection();
|
2016-10-02 21:55:19 +00:00
|
|
|
|
2019-03-01 00:04:14 +00:00
|
|
|
s.pop_layer();
|
|
|
|
// And we simply print the result.
|
|
|
|
let text = format!("Color: {}\nSize: {}cm", color, size);
|
|
|
|
s.add_layer(Dialog::text(text).button("Ok", |s| s.quit()));
|
|
|
|
}),
|
2017-10-12 23:38:55 +00:00
|
|
|
);
|
2016-10-02 21:55:19 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|