From fa4b52ee8127214271c910893b71e2972a86be4c Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 30 Jul 2015 14:51:12 +0200 Subject: [PATCH] Simplified examples --- examples/edit.rs | 17 ++++++++++------- examples/mutation.rs | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/edit.rs b/examples/edit.rs index bb21e75..1b6b7c0 100644 --- a/examples/edit.rs +++ b/examples/edit.rs @@ -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::("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::("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(); diff --git a/examples/mutation.rs b/examples/mutation.rs index 7fce1e7..ff5010c 100644 --- a/examples/mutation.rs +++ b/examples/mutation.rs @@ -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::(&Selector::Id("text")).unwrap(); + let view = s.find_id::("text").unwrap(); let content: String = view.get_content().chars().rev().collect(); view.set_content(&content); })