dear_implot/context/
token.rs1use super::callbacks::PlotScopeGuard;
2use super::core::PlotContextBinding;
3use crate::sys;
4
5pub struct PlotToken<'ui> {
9 binding: PlotContextBinding,
10 imgui_alive: Option<dear_imgui_rs::ContextAliveToken>,
11 _scope: PlotScopeGuard,
12 _lifetime: std::marker::PhantomData<&'ui ()>,
13}
14
15impl<'ui> PlotToken<'ui> {
16 pub(crate) fn new(
18 binding: PlotContextBinding,
19 imgui_alive: Option<dear_imgui_rs::ContextAliveToken>,
20 ) -> Self {
21 Self {
22 binding,
23 imgui_alive,
24 _scope: PlotScopeGuard::new(),
25 _lifetime: std::marker::PhantomData,
26 }
27 }
28
29 pub fn end(self) {
34 }
36}
37
38impl<'ui> Drop for PlotToken<'ui> {
39 fn drop(&mut self) {
40 if let Some(alive) = &self.imgui_alive {
41 assert!(
42 alive.is_alive(),
43 "dear-implot: ImGui context has been dropped"
44 );
45 }
46 self.binding.bind("dear-implot: PlotToken");
47 unsafe {
48 sys::ImPlot_EndPlot();
49 }
50 }
51}