re_sdk_types/components/
colormap_ext.rs

1use super::Colormap;
2use crate::ColormapCategory;
3
4impl Colormap {
5    /// Instantiate a new [`Colormap`] from a u8 value.
6    ///
7    /// Returns `None` if the value doesn't match any of the enum's arms.
8    pub fn from_u8(value: u8) -> Option<Self> {
9        // NOTE: This code will be optimized out, it's only here to make sure this method fails to
10        // compile if the enum is modified.
11        match Self::default() {
12            Self::Grayscale
13            | Self::Inferno
14            | Self::Magma
15            | Self::Plasma
16            | Self::Turbo
17            | Self::Viridis
18            | Self::CyanToYellow
19            | Self::Spectral
20            | Self::Twilight => {}
21        }
22
23        match value {
24            v if v == Self::Grayscale as u8 => Some(Self::Grayscale),
25            v if v == Self::Inferno as u8 => Some(Self::Inferno),
26            v if v == Self::Magma as u8 => Some(Self::Magma),
27            v if v == Self::Plasma as u8 => Some(Self::Plasma),
28            v if v == Self::Turbo as u8 => Some(Self::Turbo),
29            v if v == Self::Viridis as u8 => Some(Self::Viridis),
30            v if v == Self::CyanToYellow as u8 => Some(Self::CyanToYellow),
31            v if v == Self::Spectral as u8 => Some(Self::Spectral),
32            v if v == Self::Twilight as u8 => Some(Self::Twilight),
33            _ => None,
34        }
35    }
36
37    /// Returns the [`ColormapCategory`] classification for this colormap.
38    pub fn category(&self) -> ColormapCategory {
39        ColormapCategory::from_colormap(*self)
40    }
41}