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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
use std::sync::mpsc::Receiver;
use tui::layout::Rect;
use crate::tuice::Status;
use super::{Application, Event, TmpComponent};
#[derive(Clone, Copy, Debug)]
pub enum RuntimeEvent<Message> {
UserInterface(Event),
Resize { width: u16, height: u16 },
Custom(Message),
}
pub(crate) fn launch<A: Application + 'static>(
mut application: A, receiver: Receiver<RuntimeEvent<A::Message>>,
) {
let mut user_interface = application.view();
while !application.is_terminated() {
if let Ok(event) = receiver.recv() {
match event {
RuntimeEvent::UserInterface(event) => {
let mut messages = vec![];
let rect = Rect::default(); // FIXME: TEMP
match user_interface.on_event(rect, event, &mut messages) {
Status::Captured => {}
Status::Ignored => {
application.global_event_handler(event, &mut messages);
}
}
for msg in messages {
debug!("Message: {:?}", msg); // FIXME: Remove this debug line!
application.update(msg);
}
user_interface = application.view();
// FIXME: Draw!
}
RuntimeEvent::Custom(message) => {
application.update(message);
}
RuntimeEvent::Resize {
width: _,
height: _,
} => {
user_interface = application.view();
}
}
} else {
break;
}
}
application.destroy();
}
|