mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Simplified examples
This commit is contained in:
parent
ac85a1f288
commit
fa4b52ee81
@ -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();
|
||||
|
@ -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);
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user