poll_event
This commit is contained in:
+6
-5
@@ -28,17 +28,18 @@ fn main() {
|
||||
// Event schlafen — gut für statische UIs, schlecht für Animation.
|
||||
p.poll_events(Some(Duration::from_millis(0)));
|
||||
|
||||
// drain_events() borrowt &mut self → Aktionen auf p erst nach dem Loop.
|
||||
let mut close = false;
|
||||
for ev in p.drain_events() {
|
||||
// poll_event() gibt &mut self nach jedem Call wieder frei → Aktionen
|
||||
// auf p (request_close, set_mouse_capture, palette_mut …) sind direkt
|
||||
// im Loop erlaubt. drain_events() existiert weiter für den Fall, dass
|
||||
// nur gelesen wird.
|
||||
while let Some(ev) = p.poll_event() {
|
||||
match ev {
|
||||
Event::Key { key: Key::Escape, pressed: true, .. } => close = true,
|
||||
Event::Key { key: Key::Escape, pressed: true, .. } => p.request_close(),
|
||||
Event::MouseMove { x, y } => mouse = (x, y),
|
||||
Event::MouseBtn { button: MouseButton::Left, pressed } => paint = pressed,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if close { p.request_close(); }
|
||||
|
||||
let (w, h) = p.framebuffer_size();
|
||||
let fb = p.framebuffer_mut();
|
||||
|
||||
Reference in New Issue
Block a user