Skip to main content

dear_imgui_rs/texture/
status.rs

1use crate::sys;
2
3/// Status of a texture to communicate with Renderer Backend
4#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
5#[repr(i32)]
6pub enum TextureStatus {
7    /// Texture is ready and can be used
8    OK = sys::ImTextureStatus_OK as i32,
9    /// Backend destroyed the texture
10    Destroyed = sys::ImTextureStatus_Destroyed as i32,
11    /// Requesting backend to create the texture. Set status OK when done.
12    WantCreate = sys::ImTextureStatus_WantCreate as i32,
13    /// Requesting backend to update specific blocks of pixels. Set status OK when done.
14    WantUpdates = sys::ImTextureStatus_WantUpdates as i32,
15    /// Requesting backend to destroy the texture. Set status to Destroyed when done.
16    WantDestroy = sys::ImTextureStatus_WantDestroy as i32,
17}
18
19impl From<sys::ImTextureStatus> for TextureStatus {
20    fn from(status: sys::ImTextureStatus) -> Self {
21        match status {
22            sys::ImTextureStatus_OK => TextureStatus::OK,
23            sys::ImTextureStatus_Destroyed => TextureStatus::Destroyed,
24            sys::ImTextureStatus_WantCreate => TextureStatus::WantCreate,
25            sys::ImTextureStatus_WantUpdates => TextureStatus::WantUpdates,
26            sys::ImTextureStatus_WantDestroy => TextureStatus::WantDestroy,
27            _ => TextureStatus::Destroyed, // Default fallback
28        }
29    }
30}
31
32impl From<TextureStatus> for sys::ImTextureStatus {
33    fn from(status: TextureStatus) -> Self {
34        status as sys::ImTextureStatus
35    }
36}
37
38/// Get the name of a texture status (for debugging)
39pub fn get_status_name(status: TextureStatus) -> &'static str {
40    unsafe {
41        let ptr = sys::igImTextureDataGetStatusName(status.into());
42        if ptr.is_null() {
43            "Unknown"
44        } else {
45            std::ffi::CStr::from_ptr(ptr).to_str().unwrap_or("Invalid")
46        }
47    }
48}