mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-14 23:18:28 +00:00
Add Drop implementation for Ui
This commit is contained in:
parent
1213feb800
commit
1eab502d01
15
src/lib.rs
15
src/lib.rs
@ -402,11 +402,13 @@ impl ImGui {
|
||||
CURRENT_UI = Some(Ui {
|
||||
imgui: mem::transmute(self as &'a ImGui),
|
||||
frame_size,
|
||||
needs_cleanup: false,
|
||||
});
|
||||
}
|
||||
Ui {
|
||||
imgui: self,
|
||||
frame_size,
|
||||
needs_cleanup: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -491,6 +493,7 @@ pub struct DrawList<'a> {
|
||||
pub struct Ui<'ui> {
|
||||
imgui: &'ui ImGui,
|
||||
frame_size: FrameSize,
|
||||
needs_cleanup: bool,
|
||||
}
|
||||
|
||||
static FMT: &'static [u8] = b"%s\0";
|
||||
@ -545,7 +548,6 @@ impl<'ui> Ui<'ui> {
|
||||
raw: &mut *sys::igGetDrawData(),
|
||||
};
|
||||
f(&self, draw_data)?;
|
||||
CURRENT_UI = None;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -572,6 +574,17 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for Ui<'a> {
|
||||
fn drop(&mut self) {
|
||||
if self.needs_cleanup {
|
||||
unsafe {
|
||||
sys::igEndFrame();
|
||||
CURRENT_UI = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Ui<'a> {
|
||||
pub unsafe fn current_ui() -> Option<&'a Ui<'a>> {
|
||||
CURRENT_UI.as_ref()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user