raylib_wasm/
fns.rs

1#[cfg(not(feature = "web"))]
2use crate::native_fns::*;
3use crate::small_c_string::run_with_cstr;
4use crate::structs::*;
5#[cfg(feature = "web")]
6use crate::web_fns::*;
7
8#[inline]
9pub fn init_window(w: i32, h: i32, title: &str) {
10    run_with_cstr(title.as_bytes(), |ctitle| unsafe {
11        InitWindow(w, h, ctitle.as_ptr());
12    })
13}
14
15#[inline]
16pub fn measure_text(text: &str, font_size: usize) -> i32 {
17    let mut m: i32 = 0;
18    run_with_cstr(text.as_bytes(), |text| unsafe {
19        m = MeasureText(text.as_ptr(), font_size as i32);
20    });
21    return m;
22}
23
24#[inline]
25pub fn draw_text(text: &str, x: i32, y: i32, font_size: usize, color: Color) {
26    run_with_cstr(text.as_bytes(), |text| unsafe {
27        DrawText(text.as_ptr(), x, y, font_size as i32, color);
28    })
29}
30
31#[inline]
32pub fn load_texture(filename: &str) -> Texture {
33    let mut t: Texture = Texture {
34        id: 0,
35        width: 0,
36        height: 0,
37        mipmaps: 0,
38        format: 0,
39    };
40    run_with_cstr(filename.as_bytes(), |filename| unsafe {
41        t = LoadTexture(filename.as_ptr());
42    });
43    return t;
44}