raylib-rs 0.1.0

Rust wrapper for raylib
use std::thread::JoinHandle;

use crate::ffi::{BeginDrawing, ClearBackground, CloseWindow, Color, EndDrawing, EndMode2D, InitWindow, SetTargetFPS, WindowShouldClose};

pub struct Window {
   title: String,
   width: u16,
   height: u16,
   fps: u16,
}

impl Window {
    pub fn new(width: u16, height: u16, fps: u16, title: impl Into<String>) -> Self {
        Self { width, height, fps, title: title.into() }
    }
}

pub fn raylib_init(window: Window) {
    unsafe {
            InitWindow(window.width as i32, window.height as i32, window.title.as_ptr() as *const i8);
            SetTargetFPS(window.fps as i32);
    }
}

pub fn raylib_loop(mut body: impl FnMut()) {
    while ! unsafe { WindowShouldClose() } {
        body()
    }
}

pub fn drawing(mut body: impl FnMut()) {
    unsafe { BeginDrawing() }
    body();
    unsafe { EndDrawing() }
}

macro_rules! colors {
    ($( $name:ident = $e:expr ; )*) => {
        $(
            pub const $name: Color = Color { r: $e.0, g: $e.1, b: $e.2, a: $e.3 };
        )*
    };
}

colors! {
    RAYWHITE = (245,245,245,255);
}

pub fn clear_background(col: Color) {
    unsafe { ClearBackground(col) }
}

pub fn raylib_end() {
    unsafe { CloseWindow() }
}