Simplified examples

This commit is contained in:
Alexandre Bury 2015-07-30 14:51:12 +02:00
parent ac85a1f288
commit fa4b52ee81
2 changed files with 12 additions and 9 deletions

View File

@ -12,13 +12,16 @@ fn main() {
.title("Enter your name")
.button("Ok", |s| {
// When the button is clicked, read the text and print it in a new dialog.
let content = {
let name = s.find_id::<EditView>("edit").unwrap().get_content();
format!("Hello {}!", name)
};
s.pop_layer();
s.add_layer(Dialog::new(TextView::new(&content))
.button("Quit", |s| s.quit()));
let name = s.find_id::<EditView>("edit").unwrap().get_content().to_string();
if name.is_empty() {
s.add_layer(Dialog::new(TextView::new("Please enter a name!"))
.dismiss_button("Ok"));
} else {
let content = format!("Hello {}!", name);
s.pop_layer();
s.add_layer(Dialog::new(TextView::new(&content))
.button("Quit", |s| s.quit()));
}
}));
siv.run();

View File

@ -1,14 +1,14 @@
extern crate cursive;
use cursive::Cursive;
use cursive::view::{IdView,TextView,Dialog,Selector,KeyEventView};
use cursive::view::{IdView,TextView,Dialog,KeyEventView};
fn show_popup(siv: &mut Cursive) {
siv.add_layer(Dialog::new(TextView::new("Tak!"))
.button("Change", |s| {
// Look for a view tagged "text". We _know_ it's there, so unwrap it.
let view = s.find::<TextView>(&Selector::Id("text")).unwrap();
let view = s.find_id::<TextView>("text").unwrap();
let content: String = view.get_content().chars().rev().collect();
view.set_content(&content);
})