Function thin_engine::run_with_event_handler
source ยท pub fn run_with_event_handler<const BINDS: usize, F1, F2>(
event_loop: EventLoop,
input: &mut InputMap<BINDS>,
event_handler: F2,
logic: F1,
) -> Result<(), EventLoopError>
Expand description
used to quickly set up logic. handles closed and input events for you. the logic
var will be
run every frame. the event_handler
var is
for if you want more control over the event handling and is run multiple times before logic.
let (event_loop, window, display) = thin_engine::set_up();
enum Actions{
Debug
}
impl Into<usize> for Actions{
fn into(self) -> usize{
self as usize
}
}
use Actions::*;
let mut input = thin_engine::Input::new([
(vec![InputCode::keycode(KeyCode::Space), Debug)
]);
thin_engine::run_with_event_handler(
event_loop,
&mut input,
|event, target| {
match event {
//do something with events
_ => ()
}
}, |_|{
let mut frame = display.draw();
frame.clear_color(0, 0, 0, 1);
frame.finish().unwrap();
});