mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-30 05:10:03 -04:00
Add request_redraw
This commit is contained in:
28
examples/request_redraw.rs
Normal file
28
examples/request_redraw.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
extern crate winit;
|
||||
use winit::{Event, WindowEvent};
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
fn main() {
|
||||
let events_loop = winit::EventLoop::new();
|
||||
|
||||
let window = winit::WindowBuilder::new()
|
||||
.with_title("A fantastic window!")
|
||||
.build(&events_loop)
|
||||
.unwrap();
|
||||
|
||||
events_loop.run(move |event, _, control_flow| {
|
||||
println!("{:?}", event);
|
||||
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
..
|
||||
} => *control_flow = winit::ControlFlow::Exit,
|
||||
Event::EventsCleared => {
|
||||
window.request_redraw();
|
||||
*control_flow = winit::ControlFlow::WaitUntil(Instant::now() + Duration::new(1, 0))
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user