dear_implot3d/style/
item_arrays.rs1use crate::{Plot3DScope, sys};
2use std::borrow::Cow;
3
4#[derive(Debug, Clone, Default, PartialEq)]
7pub struct Plot3DItemArrayStyle<'a> {
8 line_colors: Option<Cow<'a, [u32]>>,
9 fill_colors: Option<Cow<'a, [u32]>>,
10 marker_sizes: Option<Cow<'a, [f32]>>,
11 marker_line_colors: Option<Cow<'a, [u32]>>,
12 marker_fill_colors: Option<Cow<'a, [u32]>>,
13}
14
15impl<'a> Plot3DItemArrayStyle<'a> {
16 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn with_line_colors(mut self, colors: &'a [u32]) -> Self {
23 self.line_colors = Some(Cow::Borrowed(colors));
24 self
25 }
26
27 pub fn with_fill_colors(mut self, colors: &'a [u32]) -> Self {
29 self.fill_colors = Some(Cow::Borrowed(colors));
30 self
31 }
32
33 pub fn with_marker_sizes(mut self, sizes: &'a [f32]) -> Self {
35 self.marker_sizes = Some(Cow::Borrowed(sizes));
36 self
37 }
38
39 pub fn with_marker_line_colors(mut self, colors: &'a [u32]) -> Self {
41 self.marker_line_colors = Some(Cow::Borrowed(colors));
42 self
43 }
44
45 pub fn with_marker_fill_colors(mut self, colors: &'a [u32]) -> Self {
47 self.marker_fill_colors = Some(Cow::Borrowed(colors));
48 self
49 }
50
51 pub(super) fn apply_to_spec(&self, spec: &mut sys::ImPlot3DSpec_c) {
52 spec.LineColors = self
53 .line_colors
54 .as_deref()
55 .filter(|values| !values.is_empty())
56 .map_or(std::ptr::null_mut(), |colors| colors.as_ptr() as *mut _);
57 spec.FillColors = self
58 .fill_colors
59 .as_deref()
60 .filter(|values| !values.is_empty())
61 .map_or(std::ptr::null_mut(), |colors| colors.as_ptr() as *mut _);
62 spec.MarkerSizes = self
63 .marker_sizes
64 .as_deref()
65 .filter(|values| !values.is_empty())
66 .map_or(std::ptr::null_mut(), |sizes| sizes.as_ptr() as *mut _);
67 spec.MarkerLineColors = self
68 .marker_line_colors
69 .as_deref()
70 .filter(|values| !values.is_empty())
71 .map_or(std::ptr::null_mut(), |colors| colors.as_ptr() as *mut _);
72 spec.MarkerFillColors = self
73 .marker_fill_colors
74 .as_deref()
75 .filter(|values| !values.is_empty())
76 .map_or(std::ptr::null_mut(), |colors| colors.as_ptr() as *mut _);
77 }
78}
79
80impl<'plot> Plot3DScope<'plot> {
81 pub unsafe fn with_next_plot3d_item_array_style<'a, R>(
94 &self,
95 style: Plot3DItemArrayStyle<'a>,
96 f: impl FnOnce(&Plot3DScope<'plot>) -> R,
97 ) -> R {
98 self.next_item
99 .scoped(|spec| style.apply_to_spec(spec), || f(self))
100 }
101}