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>
where F1: FnMut(&mut InputMap<BINDS>), F2: FnMut(&Event<()>, &WindowTarget),
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.

use thin_engine::prelude::*;
let (event_loop, window, display) = thin_engine::set_up().unwrap();
#[derive(ToUsize)]
enum Actions{
    Debug
}
use Actions::*;
let mut input = input_map!(
    (Debug, KeyCode::Space)
);


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.0, 0.0, 1.0);
        frame.finish().unwrap();
});