dear_implot3d/style/
tokens.rs1use crate::Plot3DUi;
2use crate::sys;
3use crate::ui::Plot3DContextBinding;
4use std::marker::PhantomData;
5use std::rc::Rc;
6
7#[must_use]
9pub struct StyleVarToken<'ui> {
10 pub(super) binding: Plot3DContextBinding,
11 pub(super) was_popped: bool,
12 pub(super) _lifetime: PhantomData<&'ui Plot3DUi<'ui>>,
13 pub(super) _not_send_or_sync: PhantomData<Rc<()>>,
14}
15
16impl StyleVarToken<'_> {
17 pub fn pop(mut self) {
19 self.pop_inner();
20 }
21
22 fn pop_inner(&mut self) {
23 if self.was_popped {
24 panic!("Attempted to pop an ImPlot3D style var token twice.");
25 }
26 self.binding.with_bound_context(|| {
27 unsafe { sys::ImPlot3D_PopStyleVar(1) };
28 });
29 self.was_popped = true;
30 }
31}
32
33impl Drop for StyleVarToken<'_> {
34 fn drop(&mut self) {
35 if !self.was_popped {
36 let _ = self
37 .binding
38 .try_with_bound_context(|| unsafe { sys::ImPlot3D_PopStyleVar(1) });
39 self.was_popped = true;
40 }
41 }
42}
43
44#[must_use]
46pub struct StyleColorToken<'ui> {
47 pub(super) binding: Plot3DContextBinding,
48 pub(super) was_popped: bool,
49 pub(super) _lifetime: PhantomData<&'ui Plot3DUi<'ui>>,
50 pub(super) _not_send_or_sync: PhantomData<Rc<()>>,
51}
52
53impl StyleColorToken<'_> {
54 pub fn pop(mut self) {
56 self.pop_inner();
57 }
58
59 fn pop_inner(&mut self) {
60 if self.was_popped {
61 panic!("Attempted to pop an ImPlot3D style color token twice.");
62 }
63 self.binding.with_bound_context(|| {
64 unsafe { sys::ImPlot3D_PopStyleColor(1) };
65 });
66 self.was_popped = true;
67 }
68}
69
70impl Drop for StyleColorToken<'_> {
71 fn drop(&mut self) {
72 if !self.was_popped {
73 let _ = self
74 .binding
75 .try_with_bound_context(|| unsafe { sys::ImPlot3D_PopStyleColor(1) });
76 self.was_popped = true;
77 }
78 }
79}
80
81#[must_use]
83pub struct ColormapToken<'ui> {
84 pub(super) binding: Plot3DContextBinding,
85 pub(super) was_popped: bool,
86 pub(super) _lifetime: PhantomData<&'ui Plot3DUi<'ui>>,
87 pub(super) _not_send_or_sync: PhantomData<Rc<()>>,
88}
89
90impl ColormapToken<'_> {
91 pub fn pop(mut self) {
93 self.pop_inner();
94 }
95
96 fn pop_inner(&mut self) {
97 if self.was_popped {
98 panic!("Attempted to pop an ImPlot3D colormap token twice.");
99 }
100 self.binding.with_bound_context(|| {
101 unsafe { sys::ImPlot3D_PopColormap(1) };
102 });
103 self.was_popped = true;
104 }
105}
106
107impl Drop for ColormapToken<'_> {
108 fn drop(&mut self) {
109 if !self.was_popped {
110 let _ = self
111 .binding
112 .try_with_bound_context(|| unsafe { sys::ImPlot3D_PopColormap(1) });
113 self.was_popped = true;
114 }
115 }
116}