use crate::sys;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct TextureId(u64);
impl TextureId {
#[inline]
pub const fn new(id: u64) -> Self {
Self(id)
}
#[inline]
pub const fn id(self) -> u64 {
self.0
}
#[inline]
pub const fn null() -> Self {
Self(0)
}
#[inline]
pub const fn is_null(self) -> bool {
self.0 == 0
}
pub fn try_as_usize(self) -> Option<usize> {
usize::try_from(self.0).ok()
}
pub fn try_as_ptr<T>(self) -> Option<*const T> {
self.try_as_usize().map(|value| value as *const T)
}
pub fn try_as_mut_ptr<T>(self) -> Option<*mut T> {
self.try_as_usize().map(|value| value as *mut T)
}
}
impl From<u64> for TextureId {
#[inline]
fn from(id: u64) -> Self {
TextureId(id)
}
}
impl<T> From<*const T> for TextureId {
#[inline]
fn from(ptr: *const T) -> Self {
TextureId(ptr as usize as u64)
}
}
impl<T> From<*mut T> for TextureId {
#[inline]
fn from(ptr: *mut T) -> Self {
TextureId(ptr as usize as u64)
}
}
impl From<usize> for TextureId {
#[inline]
fn from(id: usize) -> Self {
TextureId(id as u64)
}
}
impl Default for TextureId {
#[inline]
fn default() -> Self {
Self::null()
}
}
pub type RawTextureId = sys::ImTextureID;
impl From<TextureId> for RawTextureId {
#[inline]
fn from(id: TextureId) -> Self {
id.id() as sys::ImTextureID
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct ManagedTextureId(i32);
impl ManagedTextureId {
#[inline]
pub(crate) const fn from_raw(raw: i32) -> Self {
Self(raw)
}
#[inline]
pub const fn raw(self) -> i32 {
self.0
}
}