re_types/blueprint/archetypes/
plot_legend.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/blueprint/archetypes/plot_legend.fbs".
3
4#![allow(unused_imports)]
5#![allow(unused_parens)]
6#![allow(clippy::clone_on_copy)]
7#![allow(clippy::cloned_instead_of_copied)]
8#![allow(clippy::map_flatten)]
9#![allow(clippy::needless_question_mark)]
10#![allow(clippy::new_without_default)]
11#![allow(clippy::redundant_closure)]
12#![allow(clippy::too_many_arguments)]
13#![allow(clippy::too_many_lines)]
14
15use ::re_types_core::try_serialize_field;
16use ::re_types_core::SerializationResult;
17use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
18use ::re_types_core::{ComponentDescriptor, ComponentName};
19use ::re_types_core::{DeserializationError, DeserializationResult};
20
21/// **Archetype**: Configuration for the legend of a plot.
22///
23/// ⚠️ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
24#[derive(Clone, Debug, Default)]
25pub struct PlotLegend {
26    /// To what corner the legend is aligned.
27    ///
28    /// Defaults to the right bottom corner.
29    pub corner: Option<SerializedComponentBatch>,
30
31    /// Whether the legend is shown at all.
32    ///
33    /// True by default.
34    pub visible: Option<SerializedComponentBatch>,
35}
36
37impl PlotLegend {
38    /// Returns the [`ComponentDescriptor`] for [`Self::corner`].
39    #[inline]
40    pub fn descriptor_corner() -> ComponentDescriptor {
41        ComponentDescriptor {
42            archetype_name: Some("rerun.blueprint.archetypes.PlotLegend".into()),
43            component_name: "rerun.blueprint.components.Corner2D".into(),
44            archetype_field_name: Some("corner".into()),
45        }
46    }
47
48    /// Returns the [`ComponentDescriptor`] for [`Self::visible`].
49    #[inline]
50    pub fn descriptor_visible() -> ComponentDescriptor {
51        ComponentDescriptor {
52            archetype_name: Some("rerun.blueprint.archetypes.PlotLegend".into()),
53            component_name: "rerun.components.Visible".into(),
54            archetype_field_name: Some("visible".into()),
55        }
56    }
57
58    /// Returns the [`ComponentDescriptor`] for the associated indicator component.
59    #[inline]
60    pub fn descriptor_indicator() -> ComponentDescriptor {
61        ComponentDescriptor {
62            archetype_name: Some("rerun.blueprint.archetypes.PlotLegend".into()),
63            component_name: "rerun.blueprint.components.PlotLegendIndicator".into(),
64            archetype_field_name: None,
65        }
66    }
67}
68
69static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
70    once_cell::sync::Lazy::new(|| []);
71
72static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
73    once_cell::sync::Lazy::new(|| [PlotLegend::descriptor_indicator()]);
74
75static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 2usize]> =
76    once_cell::sync::Lazy::new(|| {
77        [
78            PlotLegend::descriptor_corner(),
79            PlotLegend::descriptor_visible(),
80        ]
81    });
82
83static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 3usize]> =
84    once_cell::sync::Lazy::new(|| {
85        [
86            PlotLegend::descriptor_indicator(),
87            PlotLegend::descriptor_corner(),
88            PlotLegend::descriptor_visible(),
89        ]
90    });
91
92impl PlotLegend {
93    /// The total number of components in the archetype: 0 required, 1 recommended, 2 optional
94    pub const NUM_COMPONENTS: usize = 3usize;
95}
96
97/// Indicator component for the [`PlotLegend`] [`::re_types_core::Archetype`]
98pub type PlotLegendIndicator = ::re_types_core::GenericIndicatorComponent<PlotLegend>;
99
100impl ::re_types_core::Archetype for PlotLegend {
101    type Indicator = PlotLegendIndicator;
102
103    #[inline]
104    fn name() -> ::re_types_core::ArchetypeName {
105        "rerun.blueprint.archetypes.PlotLegend".into()
106    }
107
108    #[inline]
109    fn display_name() -> &'static str {
110        "Plot legend"
111    }
112
113    #[inline]
114    fn indicator() -> SerializedComponentBatch {
115        #[allow(clippy::unwrap_used)]
116        PlotLegendIndicator::DEFAULT.serialized().unwrap()
117    }
118
119    #[inline]
120    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
121        REQUIRED_COMPONENTS.as_slice().into()
122    }
123
124    #[inline]
125    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
126        RECOMMENDED_COMPONENTS.as_slice().into()
127    }
128
129    #[inline]
130    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
131        OPTIONAL_COMPONENTS.as_slice().into()
132    }
133
134    #[inline]
135    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
136        ALL_COMPONENTS.as_slice().into()
137    }
138
139    #[inline]
140    fn from_arrow_components(
141        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
142    ) -> DeserializationResult<Self> {
143        re_tracing::profile_function!();
144        use ::re_types_core::{Loggable as _, ResultExt as _};
145        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
146        let corner = arrays_by_descr
147            .get(&Self::descriptor_corner())
148            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_corner()));
149        let visible = arrays_by_descr
150            .get(&Self::descriptor_visible())
151            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_visible()));
152        Ok(Self { corner, visible })
153    }
154}
155
156impl ::re_types_core::AsComponents for PlotLegend {
157    #[inline]
158    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
159        use ::re_types_core::Archetype as _;
160        [
161            Some(Self::indicator()),
162            self.corner.clone(),
163            self.visible.clone(),
164        ]
165        .into_iter()
166        .flatten()
167        .collect()
168    }
169}
170
171impl ::re_types_core::ArchetypeReflectionMarker for PlotLegend {}
172
173impl PlotLegend {
174    /// Create a new `PlotLegend`.
175    #[inline]
176    pub fn new() -> Self {
177        Self {
178            corner: None,
179            visible: None,
180        }
181    }
182
183    /// Update only some specific fields of a `PlotLegend`.
184    #[inline]
185    pub fn update_fields() -> Self {
186        Self::default()
187    }
188
189    /// Clear all the fields of a `PlotLegend`.
190    #[inline]
191    pub fn clear_fields() -> Self {
192        use ::re_types_core::Loggable as _;
193        Self {
194            corner: Some(SerializedComponentBatch::new(
195                crate::blueprint::components::Corner2D::arrow_empty(),
196                Self::descriptor_corner(),
197            )),
198            visible: Some(SerializedComponentBatch::new(
199                crate::components::Visible::arrow_empty(),
200                Self::descriptor_visible(),
201            )),
202        }
203    }
204
205    /// To what corner the legend is aligned.
206    ///
207    /// Defaults to the right bottom corner.
208    #[inline]
209    pub fn with_corner(
210        mut self,
211        corner: impl Into<crate::blueprint::components::Corner2D>,
212    ) -> Self {
213        self.corner = try_serialize_field(Self::descriptor_corner(), [corner]);
214        self
215    }
216
217    /// Whether the legend is shown at all.
218    ///
219    /// True by default.
220    #[inline]
221    pub fn with_visible(mut self, visible: impl Into<crate::components::Visible>) -> Self {
222        self.visible = try_serialize_field(Self::descriptor_visible(), [visible]);
223        self
224    }
225}
226
227impl ::re_byte_size::SizeBytes for PlotLegend {
228    #[inline]
229    fn heap_size_bytes(&self) -> u64 {
230        self.corner.heap_size_bytes() + self.visible.heap_size_bytes()
231    }
232}