Tao uses an event-driven model where an EventLoop manages and dispatches events. You start the loop by calling EventLoop::run.
Event Types
WindowEvent: Specific to a window (e.g., CloseRequested, cursor movement, key presses). In multi-window apps, check the WindowId to identify which window sent the event.DeviceEvent: Unfiltered input data from devices (e.g., mouse movement) that is not tied to a specific window.UserEvent: Custom events you can define and trigger.
Control Flow
Inside the run closure, you control how the loop behaves using ControlFlow:
ControlFlow::Poll: The loop runs continuously even if no events are pending. Best for games.ControlFlow::Wait: The loop pauses until the OS dispatches a new event. Best for power-efficient, non-game applications.ControlFlow::Exit (or ExitWithCode): Terminates the event loop and the program.
```rust
use tao::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
};
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
*control_flow = ControlFlow::Exit
},
Event::MainEventsCleared => {
window.request_redraw();
},
Event::RedrawRequested(_) => {
// Perform rendering here
},
_ => ()
}
});
```埋