1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use cursive::traits::*;
fn main() {
let mut siv = cursive::default();
siv.add_layer(
cursive::views::Dialog::new().content(
cursive::views::LinearLayout::vertical()
.child(
cursive::views::TextView::new("Focused").with_name("text"),
)
.child(
cursive::views::EditView::new()
.wrap_with(cursive::views::FocusTracker::new)
.on_focus(|_| {
cursive::event::EventResult::with_cb(|s| {
s.call_on_name(
"text",
|v: &mut cursive::views::TextView| {
v.set_content("Focused");
},
);
})
})
.on_focus_lost(|_| {
cursive::event::EventResult::with_cb(|s| {
s.call_on_name(
"text",
|v: &mut cursive::views::TextView| {
v.set_content("Focus lost");
},
);
})
}),
)
.child(cursive::views::Button::new("Quit", |s| s.quit()))
.fixed_width(20),
),
);
siv.run();
}