Add Drop implementation for Ui

This commit is contained in:
Joonas Javanainen 2018-08-14 22:42:36 +03:00
parent 1213feb800
commit 1eab502d01
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179

View File

@ -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()