-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathevents.rs
More file actions
61 lines (50 loc) · 1.32 KB
/
events.rs
File metadata and controls
61 lines (50 loc) · 1.32 KB
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
60
61
use std::collections::VecDeque;
use anathema_geometry::Size;
use anathema_widgets::components::events::{Event, KeyEvent};
pub struct EventsMut<'a> {
event_queue: &'a mut VecDeque<Option<Event>>,
}
impl EventsMut<'_> {
pub fn next(self) -> Self {
self.event_queue.push_back(None);
self
}
pub fn next_frames(self, count: usize) -> Self {
for _ in 0..count {
self.event_queue.push_back(None);
}
self
}
pub fn resize(self, new_size: impl Into<Size>) -> Self {
let size = new_size.into();
self.event_queue.push_back(Some(Event::Resize(size)));
self
}
pub fn stop(self) -> Self {
self.event_queue.push_back(Some(Event::Stop));
self
}
pub fn press(self, event: KeyEvent) -> Self {
self.event_queue.push_back(Some(Event::Key(event)));
self
}
}
#[derive(Debug)]
pub struct Events {
event_queue: VecDeque<Option<Event>>,
}
impl Events {
pub(super) fn new() -> Self {
Self {
event_queue: VecDeque::new(),
}
}
pub(super) fn mut_ref(&mut self) -> EventsMut<'_> {
EventsMut {
event_queue: &mut self.event_queue,
}
}
pub(super) fn pop(&mut self) -> Option<Event> {
self.event_queue.pop_front().flatten()
}
}