raylib_wasm/
helpers.rs

1use crate::prelude::*;
2use crate::util::small_c_string::run_with_cstr;
3
4#[inline]
5pub fn init_window(w: i32, h: i32, title: &str) {
6    run_with_cstr(title.as_bytes(), |ctitle| unsafe {
7        InitWindow(w, h, ctitle.as_ptr());
8    })
9}
10
11#[inline]
12pub fn measure_text(text: &str, font_size: usize) -> i32 {
13    run_with_cstr(text.as_bytes(), |text| unsafe {
14        MeasureText(text.as_ptr(), font_size as _)
15    })
16}
17
18#[inline]
19pub fn draw_text(text: &str, x: i32, y: i32, font_size: usize, color: Color) {
20    run_with_cstr(text.as_bytes(), |text| unsafe {
21        DrawText(text.as_ptr(), x, y, font_size as i32, color);
22    })
23}
24
25#[inline]
26pub fn load_texture(filename: &str) -> Texture2D {
27    run_with_cstr(filename.as_bytes(), |filename| unsafe {
28        LoadTexture(filename.as_ptr())
29    })
30}