Skip to main content

ferroui_base/rendering/composition/
enums.rs

1use bitflags::bitflags;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
4#[repr(i32)]
5pub enum CompositionBlendMode {
6    /// No regions are enabled.
7    #[default]
8    Clear,
9    /// Only the source will be present.
10    Src,
11    /// Only the destination will be present.
12    Dst,
13    /// Source is placed over the destination.
14    SrcOver,
15    /// Destination is placed over the source.
16    DstOver,
17    /// The source that overlaps the destination, replaces the destination.
18    SrcIn,
19    /// Destination which overlaps the source, replaces the source.
20    DstIn,
21    /// Source is placed, where it falls outside of the destination.
22    SrcOut,
23    /// Destination is placed, where it falls outside of the source.
24    DstOut,
25    /// Source which overlaps the destination, replaces the destination.
26    SrcATop,
27    /// Destination which overlaps the source replaces the source.
28    DstATop,
29    /// The non-overlapping regions of source and destination are combined.
30    Xor,
31    /// Display the sum of the source image and destination image.
32    Plus,
33    /// Multiplies all components (= alpha and color).
34    Modulate,
35    /// Multiplies the complements of the backdrop and source color values,
36    /// then complements the result.
37    Screen,
38    /// Multiplies or screens the colors, depending on the backdrop color
39    /// value.
40    Overlay,
41    /// Selects the darker of the backdrop and source colors.
42    Darken,
43    /// Selects the lighter of the backdrop and source colors.
44    Lighten,
45    /// Brightens the backdrop color to reflect the source color.
46    ColorDodge,
47    /// Darkens the backdrop color to reflect the source color.
48    ColorBurn,
49    /// Multiplies or screens the colors, depending on the source color
50    /// value.
51    HardLight,
52    /// Darkens or lightens the colors, depending on the source color value.
53    SoftLight,
54    /// Subtracts the darker of the two constituent colors from the lighter
55    /// color.
56    Difference,
57    /// Produces an effect similar to that of the Difference mode but lower
58    /// in contrast.
59    Exclusion,
60    /// The source color is multiplied by the destination color and replaces
61    /// the destination.
62    Multiply,
63    /// Creates a color with the hue of the source color and the saturation
64    /// and luminosity of the backdrop color.
65    Hue,
66    /// Creates a color with the saturation of the source color and the hue
67    /// and luminosity of the backdrop color.
68    Saturation,
69    /// Creates a color with the hue and saturation of the source color and
70    /// the luminosity of the backdrop color.
71    Color,
72    /// Creates a color with the luminosity of the source color and the hue
73    /// and saturation of the backdrop color.
74    Luminosity,
75}
76
77#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
78#[repr(i32)]
79pub enum CompositionGradientExtendMode {
80    #[default]
81    Clamp,
82    Wrap,
83    Mirror,
84}
85
86bitflags! {
87    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
88    pub struct CompositionTileMode: i32 {
89        const NONE = 0;
90        const TILE_X = 1;
91        const TILE_Y = 2;
92        const FLIP_X = 4;
93        const FLIP_Y = 8;
94        const TILE = Self::TILE_X.bits() | Self::TILE_Y.bits();
95        const FLIP = Self::FLIP_X.bits() | Self::FLIP_Y.bits();
96    }
97}
98
99#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
100#[repr(i32)]
101pub enum CompositionStretch {
102    #[default]
103    None = 0,
104    Fill = 1,
105}
106
107#[cfg(test)]
108mod tests {
109    use super::*;
110
111    #[test]
112    fn values_match_the_reference() {
113        assert_eq!(CompositionBlendMode::Clear as i32, 0);
114        assert_eq!(CompositionBlendMode::SrcOver as i32, 3);
115        assert_eq!(CompositionBlendMode::Luminosity as i32, 28);
116        assert_eq!(CompositionGradientExtendMode::Mirror as i32, 2);
117        assert_eq!(CompositionTileMode::TILE.bits(), 3);
118        assert_eq!(CompositionTileMode::FLIP.bits(), 12);
119        assert_eq!(CompositionStretch::Fill as i32, 1);
120    }
121}