re_types/blueprint/components/
view_fit.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/components/view_fit.fbs".
3
4#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::allow_attributes)]
8#![allow(clippy::clone_on_copy)]
9#![allow(clippy::cloned_instead_of_copied)]
10#![allow(clippy::map_flatten)]
11#![allow(clippy::needless_question_mark)]
12#![allow(clippy::new_without_default)]
13#![allow(clippy::redundant_closure)]
14#![allow(clippy::too_many_arguments)]
15#![allow(clippy::too_many_lines)]
16#![allow(clippy::wildcard_imports)]
17#![allow(non_camel_case_types)]
18
19use ::re_types_core::SerializationResult;
20use ::re_types_core::try_serialize_field;
21use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
22use ::re_types_core::{ComponentDescriptor, ComponentType};
23use ::re_types_core::{DeserializationError, DeserializationResult};
24
25/// **Component**: Determines whether an image or texture should be scaled to fit the viewport.
26#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
27#[repr(u8)]
28pub enum ViewFit {
29    /// No scaling, pixel size will match the image's width/height dimensions in pixels.
30    Original = 1,
31
32    /// Scale the image for the largest possible fit in the view's container.
33    Fill = 2,
34
35    /// Scale the image for the largest possible fit in the view's container, but keep the original aspect ratio.
36    #[default]
37    FillKeepAspectRatio = 3,
38}
39
40impl ::re_types_core::Component for ViewFit {
41    #[inline]
42    fn name() -> ComponentType {
43        "rerun.blueprint.components.ViewFit".into()
44    }
45}
46
47::re_types_core::macros::impl_into_cow!(ViewFit);
48
49impl ::re_types_core::Loggable for ViewFit {
50    #[inline]
51    fn arrow_datatype() -> arrow::datatypes::DataType {
52        use arrow::datatypes::*;
53        DataType::UInt8
54    }
55
56    fn to_arrow_opt<'a>(
57        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
58    ) -> SerializationResult<arrow::array::ArrayRef>
59    where
60        Self: Clone + 'a,
61    {
62        #![allow(clippy::manual_is_variant_and)]
63        use ::re_types_core::{Loggable as _, ResultExt as _, arrow_helpers::as_array_ref};
64        use arrow::{array::*, buffer::*, datatypes::*};
65        Ok({
66            let (somes, data0): (Vec<_>, Vec<_>) = data
67                .into_iter()
68                .map(|datum| {
69                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
70                    let datum = datum.map(|datum| *datum as u8);
71                    (datum.is_some(), datum)
72                })
73                .unzip();
74            let data0_validity: Option<arrow::buffer::NullBuffer> = {
75                let any_nones = somes.iter().any(|some| !*some);
76                any_nones.then(|| somes.into())
77            };
78            as_array_ref(PrimitiveArray::<UInt8Type>::new(
79                ScalarBuffer::from(
80                    data0
81                        .into_iter()
82                        .map(|v| v.unwrap_or_default())
83                        .collect::<Vec<_>>(),
84                ),
85                data0_validity,
86            ))
87        })
88    }
89
90    fn from_arrow_opt(
91        arrow_data: &dyn arrow::array::Array,
92    ) -> DeserializationResult<Vec<Option<Self>>>
93    where
94        Self: Sized,
95    {
96        use ::re_types_core::{Loggable as _, ResultExt as _, arrow_zip_validity::ZipValidity};
97        use arrow::{array::*, buffer::*, datatypes::*};
98        Ok(arrow_data
99            .as_any()
100            .downcast_ref::<UInt8Array>()
101            .ok_or_else(|| {
102                let expected = Self::arrow_datatype();
103                let actual = arrow_data.data_type().clone();
104                DeserializationError::datatype_mismatch(expected, actual)
105            })
106            .with_context("rerun.blueprint.components.ViewFit#enum")?
107            .into_iter()
108            .map(|typ| match typ {
109                Some(1) => Ok(Some(Self::Original)),
110                Some(2) => Ok(Some(Self::Fill)),
111                Some(3) => Ok(Some(Self::FillKeepAspectRatio)),
112                None => Ok(None),
113                Some(invalid) => Err(DeserializationError::missing_union_arm(
114                    Self::arrow_datatype(),
115                    "<invalid>",
116                    invalid as _,
117                )),
118            })
119            .collect::<DeserializationResult<Vec<Option<_>>>>()
120            .with_context("rerun.blueprint.components.ViewFit")?)
121    }
122}
123
124impl std::fmt::Display for ViewFit {
125    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126        match self {
127            Self::Original => write!(f, "Original"),
128            Self::Fill => write!(f, "Fill"),
129            Self::FillKeepAspectRatio => write!(f, "FillKeepAspectRatio"),
130        }
131    }
132}
133
134impl ::re_types_core::reflection::Enum for ViewFit {
135    #[inline]
136    fn variants() -> &'static [Self] {
137        &[Self::Original, Self::Fill, Self::FillKeepAspectRatio]
138    }
139
140    #[inline]
141    fn docstring_md(self) -> &'static str {
142        match self {
143            Self::Original => {
144                "No scaling, pixel size will match the image's width/height dimensions in pixels."
145            }
146            Self::Fill => "Scale the image for the largest possible fit in the view's container.",
147            Self::FillKeepAspectRatio => {
148                "Scale the image for the largest possible fit in the view's container, but keep the original aspect ratio."
149            }
150        }
151    }
152}
153
154impl ::re_byte_size::SizeBytes for ViewFit {
155    #[inline]
156    fn heap_size_bytes(&self) -> u64 {
157        0
158    }
159
160    #[inline]
161    fn is_pod() -> bool {
162        true
163    }
164}