Skip to main content

il2cpp_bridge_rs/structs/components/rendering/
screen.rs

1//! Unity Screen utility wrapper
2use crate::api::cache;
3
4pub struct Screen;
5
6impl Screen {
7    /// Gets the current screen width
8    ///
9    /// # Returns
10    /// * `Result<i32, String>` - The width of the screen window
11    pub fn get_width() -> Result<i32, String> {
12        let class = cache::coremodule()
13            .class("UnityEngine.Screen")
14            .ok_or("Class 'UnityEngine.Screen' not found")?;
15
16        unsafe {
17            let method = class
18                .method("get_width")
19                .ok_or("Method 'get_width' not found")?;
20            method.call::<i32>(&[])
21        }
22    }
23
24    /// Gets the current screen height
25    ///
26    /// # Returns
27    /// * `Result<i32, String>` - The height of the screen window
28    pub fn get_height() -> Result<i32, String> {
29        let class = cache::coremodule()
30            .class("UnityEngine.Screen")
31            .ok_or("Class 'UnityEngine.Screen' not found")?;
32
33        unsafe {
34            let method = class
35                .method("get_height")
36                .ok_or("Method 'get_height' not found")?;
37            method.call::<i32>(&[])
38        }
39    }
40}