use std::marker::PhantomData;
use crate::sys;
use super::DrawListMut;
#[must_use]
pub struct DrawListTextureToken<'draw_list, 'tex> {
draw_list: *mut sys::ImDrawList,
_phantom: PhantomData<(&'draw_list (), &'tex mut crate::texture::TextureData)>,
}
impl<'draw_list, 'tex> DrawListTextureToken<'draw_list, 'tex> {
fn new(draw_list: *mut sys::ImDrawList) -> Self {
Self {
draw_list,
_phantom: PhantomData,
}
}
#[doc(alias = "PopTexture")]
pub fn pop(self) {}
}
impl Drop for DrawListTextureToken<'_, '_> {
fn drop(&mut self) {
unsafe { sys::ImDrawList_PopTexture(self.draw_list) }
}
}
impl<'ui> DrawListMut<'ui> {
#[doc(alias = "PushTexture")]
pub unsafe fn push_texture<'tex>(&self, texture: impl Into<crate::texture::TextureRef<'tex>>) {
let tex_ref = texture.into().raw();
unsafe { sys::ImDrawList_PushTexture(self.draw_list, tex_ref) }
}
#[doc(alias = "PushTexture")]
pub fn push_texture_token<'tex>(
&self,
texture: impl Into<crate::texture::TextureRef<'tex>>,
) -> DrawListTextureToken<'_, 'tex> {
unsafe { self.push_texture(texture) };
DrawListTextureToken::new(self.draw_list)
}
#[doc(alias = "PopTexture")]
pub fn pop_texture(&self) {
unsafe {
sys::ImDrawList_PopTexture(self.draw_list);
}
}
#[doc(alias = "PushTexture", alias = "PopTexture")]
pub fn with_texture<'tex, R>(
&self,
texture: impl Into<crate::texture::TextureRef<'tex>>,
f: impl FnOnce() -> R,
) -> R {
let _texture = self.push_texture_token(texture);
f()
}
}