pub struct TextureRef<'tex> { /* private fields */ }Expand description
A convenient, typed wrapper around ImGui’s ImTextureRef (v1.92+)
Can reference either a plain TextureId (legacy path) or a managed TextureData.
Managed texture references carry the lifetime of the referenced texture data; legacy
TextureId references can be converted into any texture-reference lifetime because they do not
borrow Rust texture data.
Examples
- With a plain GPU handle (legacy path):
let tex_id = TextureId::new(12345);
ui.image(tex_id, [64.0, 64.0]);- With a managed texture (ImGui 1.92 texture system):
let mut tex = TextureData::new();
tex.create(TextureFormat::RGBA32, 256, 256);
// Fill pixels or schedule updates...
ui.image(&mut *tex, [256.0, 256.0]);
// The renderer backend will honor WantCreate/WantUpdates/WantDestroy
// via DrawData::textures_mut() when rendering this frame.Managed references cannot be stored beyond the texture data they point at:
let leaked: TextureRef<'static>;
{
let mut tex = TextureData::new();
leaked = (&mut tex).into();
}
let _ = leaked.raw();Raw ImTextureRef values can contain arbitrary managed texture pointers, so constructing this
wrapper from raw data is unsafe:
let raw = sys::ImTextureRef {
_TexData: std::ptr::null_mut(),
_TexID: 0,
};
let _ = TextureRef::from_raw(raw);Implementations§
Source§impl<'tex> TextureRef<'tex>
impl<'tex> TextureRef<'tex>
Sourcepub unsafe fn from_raw(raw: ImTextureRef) -> Self
pub unsafe fn from_raw(raw: ImTextureRef) -> Self
Create a texture reference from a raw ImGui texture ref.
§Safety
If raw._TexData is non-null, the caller must guarantee that it points to a valid
ImTextureData for the entire 'tex lifetime and that using the resulting reference does
not violate Rust aliasing rules.
Sourcepub fn raw(self) -> ImTextureRef
pub fn raw(self) -> ImTextureRef
Get the underlying ImGui texture ref (by value)
Trait Implementations§
Source§impl<'tex> Clone for TextureRef<'tex>
impl<'tex> Clone for TextureRef<'tex>
Source§fn clone(&self) -> TextureRef<'tex>
fn clone(&self) -> TextureRef<'tex>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more