mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
eb6af9b981
Don't show the popup at start, let the user read the text.
35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
extern crate cursive;
|
|
|
|
use cursive::Cursive;
|
|
use cursive::view::{IdView,TextView,Dialog,Selector,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 content: String = view.get_content().chars().rev().collect();
|
|
view.set_content(&content);
|
|
})
|
|
.dismiss_button("Ok"));
|
|
|
|
}
|
|
|
|
fn main() {
|
|
let mut siv = Cursive::new();
|
|
|
|
let content = "Press Q to quit the application.\n\nPress P to open the popup.";
|
|
|
|
siv.add_global_callback('q' as i32, |s| s.quit());
|
|
|
|
// Let's wrap the view to give it a recognizable ID, so we can look for it.
|
|
// We add the P callback on the textview only (and not globally),
|
|
// so that we can't call it when the popup is already visible.
|
|
siv.add_layer(KeyEventView::new(IdView::new("text", TextView::new(content)))
|
|
.register('p' as i32, |s| show_popup(s)));
|
|
|
|
|
|
siv.run();
|
|
}
|