Skip to main content

epaint/
color.rs

1use core::fmt::Debug;
2use std::sync::Arc;
3
4use ecolor::Color32;
5use emath::{Pos2, Rect};
6
7/// How paths will be colored.
8#[derive(Clone)]
9#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
10pub enum ColorMode {
11    /// The entire path is one solid color, this is the default.
12    Solid(Color32),
13
14    /// Provide a callback which takes in the path's bounding box and a position and converts it to a color.
15    /// When used with a path, the bounding box will have a margin of [`TessellationOptions::feathering_size_in_pixels`](`crate::tessellator::TessellationOptions::feathering_size_in_pixels`)
16    ///
17    /// **This cannot be serialized**
18    #[cfg_attr(feature = "serde", serde(skip))]
19    UV(Arc<dyn Fn(Rect, Pos2) -> Color32 + Send + Sync>),
20}
21
22impl Default for ColorMode {
23    fn default() -> Self {
24        Self::Solid(Color32::TRANSPARENT)
25    }
26}
27
28impl Debug for ColorMode {
29    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
30        match self {
31            Self::Solid(arg0) => f.debug_tuple("Solid").field(arg0).finish(),
32            Self::UV(_arg0) => f.debug_tuple("UV").field(&"<closure>").finish(),
33        }
34    }
35}
36
37impl PartialEq for ColorMode {
38    fn eq(&self, other: &Self) -> bool {
39        match (self, other) {
40            (Self::Solid(l0), Self::Solid(r0)) => l0 == r0,
41            (Self::UV(_l0), Self::UV(_r0)) => false,
42            _ => false,
43        }
44    }
45}
46
47impl ColorMode {
48    pub const TRANSPARENT: Self = Self::Solid(Color32::TRANSPARENT);
49}