thin_engine

Function run_with_event_handler

Source
pub fn run_with_event_handler<T, F1, F2>(
    event_loop: EventLoop,
    input: InputMap<T>,
    settings: Settings,
    event_handler: F2,
    logic: F1,
) -> Result<(), EventLoopError>
where T: Hash + PartialEq + Eq + Clone + Copy, F1: FnMut(&mut InputMap<T>, &mut Settings, &WindowTarget), F2: FnMut(&Event<()>, &mut InputMap<T>, &mut Settings, &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(Hash, PartialEq, Eq, Clone, Copy)]
enum Actions{
    Debug
}
use Actions::*;
let mut input = input_map!(
    (Debug, KeyCode::Space)
);


thin_engine::run_with_event_handler(
    event_loop, input,
    Settings::default(),
    |event, input, settings, target| {
        match event {
            //do something with events
            _ => ()
        }
    }, |input, settings, target|{
        let mut frame = display.draw();
        frame.clear_color(0.0, 0.0, 0.0, 1.0);
        frame.finish().unwrap();
});