pride_overlay/flags/
data.rs

1use super::{Flag, Svg, SvgScaleMode};
2use crate::Colour;
3#[cfg(target_arch = "wasm32")]
4use wasm_bindgen::prelude::*;
5
6// common colours
7const BLACK: Colour = Colour::hex(0x000000);
8const WHITE: Colour = Colour::hex(0xFFFFFF);
9
10macro_rules! gen_flags {
11    (
12         $(
13            $(#[doc = $doc:literal])*
14            $flag:ident
15        ),*$(,)?
16    ) => {
17        /// Built-in pride flags.
18        #[cfg_attr(target_arch = "wasm32", derive(Serialize, Deserialize))]
19        #[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
20        #[repr(u8)]
21        pub enum PresetFlag {
22            $(
23                #[cfg_attr(
24                    not(target_arch = "wasm32"),
25                    doc = concat!($($doc, "\n",)*)
26                )]
27                $flag,
28            )*
29        }
30
31        #[cfg(target_arch = "wasm32")]
32        impl PresetFlag {
33            /// Maximum discriminant value for [PresetFlag].
34            pub(crate) const fn max_discriminant() -> u8 {
35                let mut max = 0;
36                $(
37                    if PresetFlag::$flag as u8 > max {
38                        max = PresetFlag::$flag as u8;
39                    }
40                )*
41                max
42            }
43        }
44
45        impl std::str::FromStr for PresetFlag {
46            type Err = ();
47
48            fn from_str(s: &str) -> Result<Self, Self::Err> {
49                match s {
50                    $(
51                        stringify!($flag) => Ok(PresetFlag::$flag),
52                    )*
53                    _ => Err(()),
54                }
55            }
56        }
57
58        pastey::paste! {
59            impl PresetFlag {
60                pub const fn all() -> &'static [Flag<'static>] {
61                    &[
62                        $(
63                            [<$flag:upper>],
64                        )*
65                    ]
66                }
67            }
68
69            impl std::ops::Deref for PresetFlag {
70                type Target = Flag<'static>;
71
72                fn deref(&self) -> &Self::Target {
73                    match self {
74                        $(
75                            PresetFlag::$flag => &[<$flag:upper>],
76                        )*
77                    }
78                }
79            }
80        }
81    };
82}
83
84gen_flags! {
85    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/agender.svg" width="128" />
86    Agender,
87    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/aromantic.svg" width="128" />
88    Aromantic,
89    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/asexual.svg" width="128" />
90    Asexual,
91    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/bisexual.svg" width="128" />
92    Bisexual,
93    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/genderfluid.svg" width="128" />
94    Genderfluid,
95    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/genderqueer.svg" width="128" />
96    Genderqueer,
97    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/intersex.svg" width="128" />
98    Intersex,
99    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/lesbian.svg" width="128" />
100    Lesbian,
101    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/nonbinary.svg" width="128" />
102    Nonbinary,
103    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/pansexual.svg" width="128" />
104    Pansexual,
105    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/polyamory.svg" width="128" />
106    Polyamory,
107    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/rainbow.svg" width="128" />
108    Rainbow,
109    /// <img src="https://raw.githubusercontent.com/isitreallyalive/pride-overlay/refs/heads/main/flags/transgender.svg" width="128" />
110    Transgender,
111}
112
113pub(crate) const AGENDER: Flag = Flag::builder(
114    "Agender",
115    &[
116        BLACK,
117        Colour::hex(0xB9B9B9), // light gray
118        WHITE,
119        Colour::hex(0xB8F483), // light green
120        WHITE,
121        Colour::hex(0xB9B9B9), // light gray
122        BLACK,
123    ],
124)
125.build();
126
127pub(crate) const AROMANTIC: Flag = Flag::builder(
128    "Aromantic",
129    &[
130        Colour::hex(0x3DA542), // green
131        Colour::hex(0xA7D379), // lime
132        WHITE,
133        Colour::hex(0xA9A9A9), // gray
134        BLACK,
135    ],
136)
137.build();
138
139pub(crate) const ASEXUAL: Flag = Flag::builder(
140    "Asexual",
141    &[
142        BLACK,
143        Colour::hex(0xA3A3A3), // gray
144        WHITE,
145        Colour::hex(0x800080), // dark purple
146    ],
147)
148.build();
149
150pub(crate) const BISEXUAL: Flag = Flag::builder(
151    "Bisexual",
152    &[
153        Colour::hex(0xD60270), // pink
154        Colour::hex(0xD60270), // pink
155        Colour::hex(0x9B4F96), // purple
156        Colour::hex(0x0038A8), // dark blue
157        Colour::hex(0x0038A8), // dark blue
158    ],
159)
160.build();
161
162pub(crate) const GENDERFLUID: Flag = Flag::builder(
163    "Genderfluid",
164    &[
165        Colour::hex(0xFF75A2), // rose
166        WHITE,
167        Colour::hex(0xBE18D6), // purple
168        Colour::hex(0x2C2C2C), // dark gray
169        Colour::hex(0x333EBD), // indigo
170    ],
171)
172.build();
173
174pub(crate) const GENDERQUEER: Flag = Flag::builder(
175    "Genderqueer",
176    &[
177        Colour::hex(0xB67FDD), // lavender
178        WHITE,
179        Colour::hex(0x49821E), // dark green
180    ],
181)
182.build();
183
184pub(crate) const INTERSEX: Flag = Flag::builder(
185    "Intersex",
186    &[
187        Colour::hex(0xFFD800), // gold,
188        Colour::hex(0x7902AA), // dark purple
189    ],
190)
191.svg(
192    Svg::builder(include_bytes!("svg/intersex.svg"))
193        .scale(SvgScaleMode::Cover)
194        .build(),
195)
196.build();
197
198pub(crate) const LESBIAN: Flag = Flag::builder(
199    "Lesbian",
200    &[
201        Colour::hex(0xD52D00), // red
202        Colour::hex(0xFF9A56), // light orange
203        WHITE,
204        Colour::hex(0xD362A4), // pink
205        Colour::hex(0xA30262), // plum
206    ],
207)
208.build();
209
210pub(crate) const NONBINARY: Flag = Flag::builder(
211    "Nonbinary",
212    &[
213        Colour::hex(0xFFF433), // yellow
214        WHITE,
215        Colour::hex(0x9B59D0), // purple
216        Colour::hex(0x2D2D2D), // dark gray
217    ],
218)
219.build();
220
221pub(crate) const PANSEXUAL: Flag = Flag::builder(
222    "Pansexual",
223    &[
224        Colour::hex(0xFF218C), // pink
225        Colour::hex(0xFFD800), // gold
226        Colour::hex(0x21B1FF), // blue
227    ],
228)
229.build();
230
231pub(crate) const POLYAMORY: Flag = Flag::builder(
232    "Polyamory",
233    &[
234        Colour::hex(0x009FE3), // turquoise
235        Colour::hex(0xE50051), // red
236        Colour::hex(0x340C46), // dark purple
237    ],
238)
239.svg(
240    Svg::builder(include_bytes!("svg/polyamory.svg"))
241        .scale(SvgScaleMode::Cover)
242        .build(),
243)
244.build();
245
246pub(crate) const RAINBOW: Flag = Flag::builder(
247    "Rainbow",
248    &[
249        Colour::hex(0xE50000), // red
250        Colour::hex(0xFF8D00), // orange
251        Colour::hex(0xFFEE00), // yellow
252        Colour::hex(0x028121), // dark green
253        Colour::hex(0x004CFF), // blue
254        Colour::hex(0x770088), // dark purple
255    ],
256)
257.build();
258
259pub(crate) const TRANSGENDER: Flag = Flag::builder(
260    "Transgender",
261    &[
262        Colour::hex(0x5BCEFA), // light turquoise
263        Colour::hex(0xF5A9B8), // rose
264        WHITE,
265        Colour::hex(0xF5A9B8), // rose
266        Colour::hex(0x5BCEFA), // light turquoise
267    ],
268)
269.build();