re_types/blueprint/archetypes/
viewport_blueprint.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/viewport_blueprint.fbs".
3
4#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
15
16use ::re_types_core::try_serialize_field;
17use ::re_types_core::SerializationResult;
18use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
19use ::re_types_core::{ComponentDescriptor, ComponentType};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22/// **Archetype**: The top-level description of the viewport.
23///
24/// ⚠️ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
25#[derive(Clone, Debug, Default)]
26pub struct ViewportBlueprint {
27    /// The layout of the views
28    pub root_container: Option<SerializedComponentBatch>,
29
30    /// Show one tab as maximized?
31    pub maximized: Option<SerializedComponentBatch>,
32
33    /// Whether the viewport layout is determined automatically.
34    ///
35    /// If `true`, the container layout will be reset whenever a new view is added or removed.
36    /// This defaults to `false` and is automatically set to `false` when there is user determined layout.
37    pub auto_layout: Option<SerializedComponentBatch>,
38
39    /// Whether or not views should be created automatically.
40    ///
41    /// If `true`, the viewer will only add views that it hasn't considered previously (as identified by `past_viewer_recommendations`)
42    /// and which aren't deemed redundant to existing views.
43    /// This defaults to `false` and is automatically set to `false` when the user adds views manually in the viewer.
44    pub auto_views: Option<SerializedComponentBatch>,
45
46    /// Hashes of all recommended views the viewer has already added and that should not be added again.
47    ///
48    /// This is an internal field and should not be set usually.
49    /// If you want the viewer from stopping to add views, you should set `auto_views` to `false`.
50    ///
51    /// The viewer uses this to determine whether it should keep adding views.
52    pub past_viewer_recommendations: Option<SerializedComponentBatch>,
53}
54
55impl ViewportBlueprint {
56    /// Returns the [`ComponentDescriptor`] for [`Self::root_container`].
57    ///
58    /// The corresponding component is [`crate::blueprint::components::RootContainer`].
59    #[inline]
60    pub fn descriptor_root_container() -> ComponentDescriptor {
61        ComponentDescriptor {
62            archetype: Some("rerun.blueprint.archetypes.ViewportBlueprint".into()),
63            component: "ViewportBlueprint:root_container".into(),
64            component_type: Some("rerun.blueprint.components.RootContainer".into()),
65        }
66    }
67
68    /// Returns the [`ComponentDescriptor`] for [`Self::maximized`].
69    ///
70    /// The corresponding component is [`crate::blueprint::components::ViewMaximized`].
71    #[inline]
72    pub fn descriptor_maximized() -> ComponentDescriptor {
73        ComponentDescriptor {
74            archetype: Some("rerun.blueprint.archetypes.ViewportBlueprint".into()),
75            component: "ViewportBlueprint:maximized".into(),
76            component_type: Some("rerun.blueprint.components.ViewMaximized".into()),
77        }
78    }
79
80    /// Returns the [`ComponentDescriptor`] for [`Self::auto_layout`].
81    ///
82    /// The corresponding component is [`crate::blueprint::components::AutoLayout`].
83    #[inline]
84    pub fn descriptor_auto_layout() -> ComponentDescriptor {
85        ComponentDescriptor {
86            archetype: Some("rerun.blueprint.archetypes.ViewportBlueprint".into()),
87            component: "ViewportBlueprint:auto_layout".into(),
88            component_type: Some("rerun.blueprint.components.AutoLayout".into()),
89        }
90    }
91
92    /// Returns the [`ComponentDescriptor`] for [`Self::auto_views`].
93    ///
94    /// The corresponding component is [`crate::blueprint::components::AutoViews`].
95    #[inline]
96    pub fn descriptor_auto_views() -> ComponentDescriptor {
97        ComponentDescriptor {
98            archetype: Some("rerun.blueprint.archetypes.ViewportBlueprint".into()),
99            component: "ViewportBlueprint:auto_views".into(),
100            component_type: Some("rerun.blueprint.components.AutoViews".into()),
101        }
102    }
103
104    /// Returns the [`ComponentDescriptor`] for [`Self::past_viewer_recommendations`].
105    ///
106    /// The corresponding component is [`crate::blueprint::components::ViewerRecommendationHash`].
107    #[inline]
108    pub fn descriptor_past_viewer_recommendations() -> ComponentDescriptor {
109        ComponentDescriptor {
110            archetype: Some("rerun.blueprint.archetypes.ViewportBlueprint".into()),
111            component: "ViewportBlueprint:past_viewer_recommendations".into(),
112            component_type: Some("rerun.blueprint.components.ViewerRecommendationHash".into()),
113        }
114    }
115}
116
117static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
118    once_cell::sync::Lazy::new(|| []);
119
120static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
121    once_cell::sync::Lazy::new(|| []);
122
123static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 5usize]> =
124    once_cell::sync::Lazy::new(|| {
125        [
126            ViewportBlueprint::descriptor_root_container(),
127            ViewportBlueprint::descriptor_maximized(),
128            ViewportBlueprint::descriptor_auto_layout(),
129            ViewportBlueprint::descriptor_auto_views(),
130            ViewportBlueprint::descriptor_past_viewer_recommendations(),
131        ]
132    });
133
134static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 5usize]> =
135    once_cell::sync::Lazy::new(|| {
136        [
137            ViewportBlueprint::descriptor_root_container(),
138            ViewportBlueprint::descriptor_maximized(),
139            ViewportBlueprint::descriptor_auto_layout(),
140            ViewportBlueprint::descriptor_auto_views(),
141            ViewportBlueprint::descriptor_past_viewer_recommendations(),
142        ]
143    });
144
145impl ViewportBlueprint {
146    /// The total number of components in the archetype: 0 required, 0 recommended, 5 optional
147    pub const NUM_COMPONENTS: usize = 5usize;
148}
149
150impl ::re_types_core::Archetype for ViewportBlueprint {
151    #[inline]
152    fn name() -> ::re_types_core::ArchetypeName {
153        "rerun.blueprint.archetypes.ViewportBlueprint".into()
154    }
155
156    #[inline]
157    fn display_name() -> &'static str {
158        "Viewport blueprint"
159    }
160
161    #[inline]
162    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
163        REQUIRED_COMPONENTS.as_slice().into()
164    }
165
166    #[inline]
167    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
168        RECOMMENDED_COMPONENTS.as_slice().into()
169    }
170
171    #[inline]
172    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
173        OPTIONAL_COMPONENTS.as_slice().into()
174    }
175
176    #[inline]
177    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
178        ALL_COMPONENTS.as_slice().into()
179    }
180
181    #[inline]
182    fn from_arrow_components(
183        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
184    ) -> DeserializationResult<Self> {
185        re_tracing::profile_function!();
186        use ::re_types_core::{Loggable as _, ResultExt as _};
187        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
188        let root_container = arrays_by_descr
189            .get(&Self::descriptor_root_container())
190            .map(|array| {
191                SerializedComponentBatch::new(array.clone(), Self::descriptor_root_container())
192            });
193        let maximized = arrays_by_descr
194            .get(&Self::descriptor_maximized())
195            .map(|array| {
196                SerializedComponentBatch::new(array.clone(), Self::descriptor_maximized())
197            });
198        let auto_layout = arrays_by_descr
199            .get(&Self::descriptor_auto_layout())
200            .map(|array| {
201                SerializedComponentBatch::new(array.clone(), Self::descriptor_auto_layout())
202            });
203        let auto_views = arrays_by_descr
204            .get(&Self::descriptor_auto_views())
205            .map(|array| {
206                SerializedComponentBatch::new(array.clone(), Self::descriptor_auto_views())
207            });
208        let past_viewer_recommendations = arrays_by_descr
209            .get(&Self::descriptor_past_viewer_recommendations())
210            .map(|array| {
211                SerializedComponentBatch::new(
212                    array.clone(),
213                    Self::descriptor_past_viewer_recommendations(),
214                )
215            });
216        Ok(Self {
217            root_container,
218            maximized,
219            auto_layout,
220            auto_views,
221            past_viewer_recommendations,
222        })
223    }
224}
225
226impl ::re_types_core::AsComponents for ViewportBlueprint {
227    #[inline]
228    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
229        use ::re_types_core::Archetype as _;
230        [
231            self.root_container.clone(),
232            self.maximized.clone(),
233            self.auto_layout.clone(),
234            self.auto_views.clone(),
235            self.past_viewer_recommendations.clone(),
236        ]
237        .into_iter()
238        .flatten()
239        .collect()
240    }
241}
242
243impl ::re_types_core::ArchetypeReflectionMarker for ViewportBlueprint {}
244
245impl ViewportBlueprint {
246    /// Create a new `ViewportBlueprint`.
247    #[inline]
248    pub fn new() -> Self {
249        Self {
250            root_container: None,
251            maximized: None,
252            auto_layout: None,
253            auto_views: None,
254            past_viewer_recommendations: None,
255        }
256    }
257
258    /// Update only some specific fields of a `ViewportBlueprint`.
259    #[inline]
260    pub fn update_fields() -> Self {
261        Self::default()
262    }
263
264    /// Clear all the fields of a `ViewportBlueprint`.
265    #[inline]
266    pub fn clear_fields() -> Self {
267        use ::re_types_core::Loggable as _;
268        Self {
269            root_container: Some(SerializedComponentBatch::new(
270                crate::blueprint::components::RootContainer::arrow_empty(),
271                Self::descriptor_root_container(),
272            )),
273            maximized: Some(SerializedComponentBatch::new(
274                crate::blueprint::components::ViewMaximized::arrow_empty(),
275                Self::descriptor_maximized(),
276            )),
277            auto_layout: Some(SerializedComponentBatch::new(
278                crate::blueprint::components::AutoLayout::arrow_empty(),
279                Self::descriptor_auto_layout(),
280            )),
281            auto_views: Some(SerializedComponentBatch::new(
282                crate::blueprint::components::AutoViews::arrow_empty(),
283                Self::descriptor_auto_views(),
284            )),
285            past_viewer_recommendations: Some(SerializedComponentBatch::new(
286                crate::blueprint::components::ViewerRecommendationHash::arrow_empty(),
287                Self::descriptor_past_viewer_recommendations(),
288            )),
289        }
290    }
291
292    /// The layout of the views
293    #[inline]
294    pub fn with_root_container(
295        mut self,
296        root_container: impl Into<crate::blueprint::components::RootContainer>,
297    ) -> Self {
298        self.root_container =
299            try_serialize_field(Self::descriptor_root_container(), [root_container]);
300        self
301    }
302
303    /// Show one tab as maximized?
304    #[inline]
305    pub fn with_maximized(
306        mut self,
307        maximized: impl Into<crate::blueprint::components::ViewMaximized>,
308    ) -> Self {
309        self.maximized = try_serialize_field(Self::descriptor_maximized(), [maximized]);
310        self
311    }
312
313    /// Whether the viewport layout is determined automatically.
314    ///
315    /// If `true`, the container layout will be reset whenever a new view is added or removed.
316    /// This defaults to `false` and is automatically set to `false` when there is user determined layout.
317    #[inline]
318    pub fn with_auto_layout(
319        mut self,
320        auto_layout: impl Into<crate::blueprint::components::AutoLayout>,
321    ) -> Self {
322        self.auto_layout = try_serialize_field(Self::descriptor_auto_layout(), [auto_layout]);
323        self
324    }
325
326    /// Whether or not views should be created automatically.
327    ///
328    /// If `true`, the viewer will only add views that it hasn't considered previously (as identified by `past_viewer_recommendations`)
329    /// and which aren't deemed redundant to existing views.
330    /// This defaults to `false` and is automatically set to `false` when the user adds views manually in the viewer.
331    #[inline]
332    pub fn with_auto_views(
333        mut self,
334        auto_views: impl Into<crate::blueprint::components::AutoViews>,
335    ) -> Self {
336        self.auto_views = try_serialize_field(Self::descriptor_auto_views(), [auto_views]);
337        self
338    }
339
340    /// Hashes of all recommended views the viewer has already added and that should not be added again.
341    ///
342    /// This is an internal field and should not be set usually.
343    /// If you want the viewer from stopping to add views, you should set `auto_views` to `false`.
344    ///
345    /// The viewer uses this to determine whether it should keep adding views.
346    #[inline]
347    pub fn with_past_viewer_recommendations(
348        mut self,
349        past_viewer_recommendations: impl IntoIterator<
350            Item = impl Into<crate::blueprint::components::ViewerRecommendationHash>,
351        >,
352    ) -> Self {
353        self.past_viewer_recommendations = try_serialize_field(
354            Self::descriptor_past_viewer_recommendations(),
355            past_viewer_recommendations,
356        );
357        self
358    }
359}
360
361impl ::re_byte_size::SizeBytes for ViewportBlueprint {
362    #[inline]
363    fn heap_size_bytes(&self) -> u64 {
364        self.root_container.heap_size_bytes()
365            + self.maximized.heap_size_bytes()
366            + self.auto_layout.heap_size_bytes()
367            + self.auto_views.heap_size_bytes()
368            + self.past_viewer_recommendations.heap_size_bytes()
369    }
370}