Skip to main content

dear_implot3d/style/
types.rs

1use crate::sys;
2
3/// Colorable ImPlot3D style elements.
4#[repr(i32)]
5#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6pub enum Plot3DColorElement {
7    TitleText = sys::ImPlot3DCol_TitleText as i32,
8    InlayText = sys::ImPlot3DCol_InlayText as i32,
9    FrameBg = sys::ImPlot3DCol_FrameBg as i32,
10    PlotBg = sys::ImPlot3DCol_PlotBg as i32,
11    PlotBorder = sys::ImPlot3DCol_PlotBorder as i32,
12    LegendBg = sys::ImPlot3DCol_LegendBg as i32,
13    LegendBorder = sys::ImPlot3DCol_LegendBorder as i32,
14    LegendText = sys::ImPlot3DCol_LegendText as i32,
15    AxisText = sys::ImPlot3DCol_AxisText as i32,
16    AxisGrid = sys::ImPlot3DCol_AxisGrid as i32,
17    AxisTick = sys::ImPlot3DCol_AxisTick as i32,
18    AxisBg = sys::ImPlot3DCol_AxisBg as i32,
19    AxisBgHovered = sys::ImPlot3DCol_AxisBgHovered as i32,
20    AxisBgActive = sys::ImPlot3DCol_AxisBgActive as i32,
21}
22
23/// ImPlot3D style variables.
24#[repr(i32)]
25#[derive(Copy, Clone, Debug, PartialEq, Eq)]
26pub enum Plot3DStyleVar {
27    LineWeight = sys::ImPlot3DStyleVar_LineWeight as i32,
28    Marker = sys::ImPlot3DStyleVar_Marker as i32,
29    MarkerSize = sys::ImPlot3DStyleVar_MarkerSize as i32,
30    FillAlpha = sys::ImPlot3DStyleVar_FillAlpha as i32,
31    PlotDefaultSize = sys::ImPlot3DStyleVar_PlotDefaultSize as i32,
32    PlotMinSize = sys::ImPlot3DStyleVar_PlotMinSize as i32,
33    PlotPadding = sys::ImPlot3DStyleVar_PlotPadding as i32,
34    LabelPadding = sys::ImPlot3DStyleVar_LabelPadding as i32,
35    ViewScaleFactor = sys::ImPlot3DStyleVar_ViewScaleFactor as i32,
36    LegendPadding = sys::ImPlot3DStyleVar_LegendPadding as i32,
37    LegendInnerPadding = sys::ImPlot3DStyleVar_LegendInnerPadding as i32,
38    LegendSpacing = sys::ImPlot3DStyleVar_LegendSpacing as i32,
39}
40
41/// Built-in ImPlot3D colormaps.
42#[repr(i32)]
43#[derive(Copy, Clone, Debug, PartialEq, Eq)]
44pub enum Colormap {
45    Deep = sys::ImPlot3DColormap_Deep as i32,
46    Dark = sys::ImPlot3DColormap_Dark as i32,
47    Pastel = sys::ImPlot3DColormap_Pastel as i32,
48    Paired = sys::ImPlot3DColormap_Paired as i32,
49    Viridis = sys::ImPlot3DColormap_Viridis as i32,
50    Plasma = sys::ImPlot3DColormap_Plasma as i32,
51    Hot = sys::ImPlot3DColormap_Hot as i32,
52    Cool = sys::ImPlot3DColormap_Cool as i32,
53    Pink = sys::ImPlot3DColormap_Pink as i32,
54    Jet = sys::ImPlot3DColormap_Jet as i32,
55    Twilight = sys::ImPlot3DColormap_Twilight as i32,
56    RdBu = sys::ImPlot3DColormap_RdBu as i32,
57    BrBG = sys::ImPlot3DColormap_BrBG as i32,
58    PiYG = sys::ImPlot3DColormap_PiYG as i32,
59    Spectral = sys::ImPlot3DColormap_Spectral as i32,
60    Greys = sys::ImPlot3DColormap_Greys as i32,
61}
62
63impl Colormap {
64    #[inline]
65    pub const fn index(self) -> ColormapIndex {
66        match ColormapIndex::from_raw(self as i32) {
67            Some(index) => index,
68            None => panic!("built-in ImPlot3D colormap index must be valid"),
69        }
70    }
71}
72
73/// Runtime ImPlot3D colormap index.
74#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
75#[repr(transparent)]
76pub struct ColormapIndex(i32);
77
78impl ColormapIndex {
79    #[inline]
80    pub const fn new(index: usize) -> Option<Self> {
81        if index <= i32::MAX as usize {
82            Some(Self(index as i32))
83        } else {
84            None
85        }
86    }
87
88    #[inline]
89    pub const fn get(self) -> usize {
90        self.0 as usize
91    }
92
93    #[inline]
94    pub const fn raw(self) -> i32 {
95        self.0
96    }
97
98    #[inline]
99    pub(crate) const fn from_raw(raw: i32) -> Option<Self> {
100        if raw >= 0 { Some(Self(raw)) } else { None }
101    }
102}
103
104impl From<Colormap> for ColormapIndex {
105    #[inline]
106    fn from(value: Colormap) -> Self {
107        value.index()
108    }
109}
110
111impl From<usize> for ColormapIndex {
112    #[inline]
113    fn from(value: usize) -> Self {
114        Self::new(value).expect("colormap index exceeded ImPlot3D's i32 range")
115    }
116}
117
118/// Zero-based color entry inside the active or selected colormap.
119#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
120#[repr(transparent)]
121pub struct ColormapColorIndex(i32);
122
123impl ColormapColorIndex {
124    #[inline]
125    pub const fn new(index: usize) -> Option<Self> {
126        Self::from_usize(index)
127    }
128
129    #[inline]
130    pub const fn from_usize(index: usize) -> Option<Self> {
131        if index <= i32::MAX as usize {
132            Some(Self(index as i32))
133        } else {
134            None
135        }
136    }
137
138    #[inline]
139    pub const fn get(self) -> usize {
140        self.0 as usize
141    }
142
143    #[inline]
144    pub const fn raw(self) -> i32 {
145        self.0
146    }
147}
148
149impl From<usize> for ColormapColorIndex {
150    #[inline]
151    fn from(value: usize) -> Self {
152        Self::new(value).expect("colormap color index exceeded ImPlot3D's i32 range")
153    }
154}