dear_imgui_rs/draw/list/
texture.rs1use std::marker::PhantomData;
2
3use crate::sys;
4
5use super::DrawListMut;
6
7#[must_use]
12pub struct DrawListTextureToken<'draw_list, 'tex> {
13 draw_list: *mut sys::ImDrawList,
14 _phantom: PhantomData<(&'draw_list (), &'tex mut crate::texture::TextureData)>,
15}
16
17impl<'draw_list, 'tex> DrawListTextureToken<'draw_list, 'tex> {
18 fn new(draw_list: *mut sys::ImDrawList) -> Self {
19 Self {
20 draw_list,
21 _phantom: PhantomData,
22 }
23 }
24
25 #[doc(alias = "PopTexture")]
27 pub fn pop(self) {}
28
29 #[doc(alias = "PopTexture")]
31 pub fn end(self) {}
32}
33
34impl Drop for DrawListTextureToken<'_, '_> {
35 fn drop(&mut self) {
36 unsafe { sys::ImDrawList_PopTexture(self.draw_list) }
37 }
38}
39
40impl<'ui> DrawListMut<'ui> {
41 #[doc(alias = "PushTexture")]
59 pub fn push_texture<'tex>(
60 &self,
61 texture: impl Into<crate::texture::TextureRef<'tex>>,
62 ) -> DrawListTextureToken<'_, 'tex> {
63 let tex_ref = texture.into().raw();
64 unsafe { sys::ImDrawList_PushTexture(self.draw_list, tex_ref) };
65 DrawListTextureToken::new(self.draw_list)
66 }
67
68 #[doc(alias = "PushTexture", alias = "PopTexture")]
72 pub fn with_texture<'tex, R>(
73 &self,
74 texture: impl Into<crate::texture::TextureRef<'tex>>,
75 f: impl FnOnce() -> R,
76 ) -> R {
77 let _texture = self.push_texture(texture);
78 f()
79 }
80}