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")
|
.title("Enter your name")
|
||||||
.button("Ok", |s| {
|
.button("Ok", |s| {
|
||||||
// When the button is clicked, read the text and print it in a new dialog.
|
// 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().to_string();
|
||||||
let name = s.find_id::<EditView>("edit").unwrap().get_content();
|
if name.is_empty() {
|
||||||
format!("Hello {}!", name)
|
s.add_layer(Dialog::new(TextView::new("Please enter a name!"))
|
||||||
};
|
.dismiss_button("Ok"));
|
||||||
s.pop_layer();
|
} else {
|
||||||
s.add_layer(Dialog::new(TextView::new(&content))
|
let content = format!("Hello {}!", name);
|
||||||
.button("Quit", |s| s.quit()));
|
s.pop_layer();
|
||||||
|
s.add_layer(Dialog::new(TextView::new(&content))
|
||||||
|
.button("Quit", |s| s.quit()));
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
extern crate cursive;
|
extern crate cursive;
|
||||||
|
|
||||||
use cursive::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) {
|
fn show_popup(siv: &mut Cursive) {
|
||||||
|
|
||||||
siv.add_layer(Dialog::new(TextView::new("Tak!"))
|
siv.add_layer(Dialog::new(TextView::new("Tak!"))
|
||||||
.button("Change", |s| {
|
.button("Change", |s| {
|
||||||
// Look for a view tagged "text". We _know_ it's there, so unwrap it.
|
// 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();
|
let content: String = view.get_content().chars().rev().collect();
|
||||||
view.set_content(&content);
|
view.set_content(&content);
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user