bjz/glfw-rs — pull request #87 by bjz (2014-02-02 03:24:32+00:00)
Title: [WIP] Use messaging instead of trait objects for event handling

Instead of traits this uses ports and channels. Whenever `glfw::poll_events();` is called, the events are sent to window-specific ports, along with the time stamp of when they were triggered. The events can be accessed using either the `Window::events` or `Window::flush_events` methods. For example:

~~~rust
let window = glfw::Window::create(300, 300, "Hello this is window", glfw::Windowed)
.expect("Failed to create GLFW window.");

window.set_key_polling(true); // polling must be registered for the specific `WindowEvent` type
window.make_context_current();

while !window.should_close() {
glfw::poll_events();
// `flush_events` returns an iterator that empties the messages received since
// `events` or `flush_events` was last called.
for (_, event) in window.flush_events() {
match event {
glfw::KeyEvent(glfw::KeyEscape, _, glfw::Press, _) => {
window.set_should_close(true)
}
_ => {}
}
}
}
~~~