macro_rules! create_token {
(
$(#[$struct_meta:meta])*
$v:vis struct $token_name:ident<'ui>;
$(#[$end_meta:meta])*
drop { $on_drop:expr }
) => {
#[must_use]
$(#[$struct_meta])*
pub struct $token_name<'a> {
ctx: *mut $crate::sys::ImGuiContext,
ctx_alive: $crate::ContextAliveToken,
_phantom: std::marker::PhantomData<&'a $crate::Ui>,
}
impl<'a> $token_name<'a> {
pub(crate) fn new(ui: &'a $crate::Ui) -> Self {
Self {
ctx: ui.context_raw(),
ctx_alive: ui.context_alive_token(),
_phantom: std::marker::PhantomData,
}
}
$(#[$end_meta])*
#[inline]
pub fn end(self) {
}
}
impl Drop for $token_name<'_> {
fn drop(&mut self) {
if self.ctx.is_null() || !self.ctx_alive.is_alive() {
return;
}
let _guard = $crate::context::binding::CTX_MUTEX.lock();
$crate::context::binding::with_bound_context(self.ctx, || {
$on_drop
});
}
}
}
}