Skip to main content

dear_implot3d/style/
tokens.rs

1use crate::sys;
2use std::marker::PhantomData;
3use std::rc::Rc;
4
5/// Token for managing style variable changes.
6#[must_use]
7pub struct StyleVarToken {
8    pub(super) was_popped: bool,
9    pub(super) _not_send_or_sync: PhantomData<Rc<()>>,
10}
11
12impl StyleVarToken {
13    /// Pop this style variable from the stack.
14    pub fn pop(mut self) {
15        if self.was_popped {
16            panic!("Attempted to pop an ImPlot3D style var token twice.");
17        }
18        self.was_popped = true;
19        unsafe {
20            sys::ImPlot3D_PopStyleVar(1);
21        }
22    }
23}
24
25impl Drop for StyleVarToken {
26    fn drop(&mut self) {
27        if !self.was_popped {
28            unsafe {
29                sys::ImPlot3D_PopStyleVar(1);
30            }
31        }
32    }
33}
34
35/// Token for managing style color changes.
36#[must_use]
37pub struct StyleColorToken {
38    pub(super) was_popped: bool,
39    pub(super) _not_send_or_sync: PhantomData<Rc<()>>,
40}
41
42impl StyleColorToken {
43    /// Pop this style color from the stack.
44    pub fn pop(mut self) {
45        if self.was_popped {
46            panic!("Attempted to pop an ImPlot3D style color token twice.");
47        }
48        self.was_popped = true;
49        unsafe {
50            sys::ImPlot3D_PopStyleColor(1);
51        }
52    }
53}
54
55impl Drop for StyleColorToken {
56    fn drop(&mut self) {
57        if !self.was_popped {
58            unsafe {
59                sys::ImPlot3D_PopStyleColor(1);
60            }
61        }
62    }
63}
64
65/// Token for managing colormap changes.
66#[must_use]
67pub struct ColormapToken {
68    pub(super) was_popped: bool,
69    pub(super) _not_send_or_sync: PhantomData<Rc<()>>,
70}
71
72impl ColormapToken {
73    /// Pop this colormap from the stack.
74    pub fn pop(mut self) {
75        if self.was_popped {
76            panic!("Attempted to pop an ImPlot3D colormap token twice.");
77        }
78        self.was_popped = true;
79        unsafe {
80            sys::ImPlot3D_PopColormap(1);
81        }
82    }
83}
84
85impl Drop for ColormapToken {
86    fn drop(&mut self) {
87        if !self.was_popped {
88            unsafe {
89                sys::ImPlot3D_PopColormap(1);
90            }
91        }
92    }
93}