dear_implot3d/style/
palette.rs1use crate::flags::Marker3D;
2use crate::sys;
3use crate::{Plot3DContext, Plot3DScope, Plot3DUi};
4
5use super::types::{Plot3DColorElement, Plot3DStyleVar};
6
7impl Plot3DContext {
8 #[inline]
10 pub fn style_colors_dark(&self) {
11 self.with_bound_context(|| unsafe { sys::ImPlot3D_StyleColorsDark(std::ptr::null_mut()) })
12 }
13
14 #[inline]
16 pub fn style_colors_light(&self) {
17 self.with_bound_context(|| unsafe { sys::ImPlot3D_StyleColorsLight(std::ptr::null_mut()) })
18 }
19
20 #[inline]
22 pub fn style_colors_classic(&self) {
23 self.with_bound_context(|| unsafe {
24 sys::ImPlot3D_StyleColorsClassic(std::ptr::null_mut())
25 })
26 }
27
28 #[inline]
30 pub fn style_colors_auto(&self) {
31 self.with_bound_context(|| unsafe { sys::ImPlot3D_StyleColorsAuto(std::ptr::null_mut()) })
32 }
33}
34
35impl Plot3DUi<'_> {
36 pub fn with_style_colors<R>(
38 &self,
39 colors: &[(Plot3DColorElement, [f32; 4])],
40 f: impl FnOnce() -> R,
41 ) -> R {
42 self.with_style_scope(
43 colors.len(),
44 || {
45 for &(element, [r, g, b, a]) in colors {
46 unsafe {
47 sys::ImPlot3D_PushStyleColor_Vec4(element as _, crate::imvec4(r, g, b, a))
48 };
49 }
50 },
51 sys::ImPlot3D_PopStyleColor,
52 f,
53 )
54 }
55
56 pub fn with_style_vars<R>(&self, vars: &[Plot3DStyleVar], f: impl FnOnce() -> R) -> R {
58 self.with_style_scope(
59 vars.len(),
60 || {
61 for var in vars {
62 unsafe { var.push() };
63 }
64 },
65 sys::ImPlot3D_PopStyleVar,
66 f,
67 )
68 }
69}
70
71impl Plot3DScope<'_> {
72 #[inline]
74 pub fn set_next_line_style(&self, col: [f32; 4], weight: f32) {
75 self.next_item.update(|spec| {
76 spec.LineColor = crate::imvec4(col[0], col[1], col[2], col[3]);
77 spec.LineWeight = weight;
78 })
79 }
80
81 #[inline]
83 pub fn set_next_fill_style(&self, col: [f32; 4], alpha_mod: f32) {
84 self.next_item.update(|spec| {
85 spec.FillColor = crate::imvec4(col[0], col[1], col[2], col[3]);
86 spec.FillAlpha = alpha_mod;
87 })
88 }
89
90 #[inline]
92 pub fn set_next_marker_style(
93 &self,
94 marker: Marker3D,
95 size: f32,
96 fill: [f32; 4],
97 weight: f32,
98 outline: [f32; 4],
99 ) {
100 self.next_item.update(|spec| {
101 spec.Marker = marker as sys::ImPlot3DMarker;
102 spec.MarkerSize = size;
103 spec.MarkerFillColor = crate::imvec4(fill[0], fill[1], fill[2], fill[3]);
104 spec.MarkerLineColor = crate::imvec4(outline[0], outline[1], outline[2], outline[3]);
105 spec.LineWeight = weight;
106 })
107 }
108}