egui-map 0.5.0

Visual component to draw a map on screen.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
//! Color palettes and visual styling for the [`Map`](super::Map) widget.
//!
//! [`Theme`] is a built-in set of named color palettes, each with a light and
//! a dark variant ([`ColorMode`]); [`Theme::colors`] resolves a `(Theme,
//! ColorMode)` pair to the actual [`ThemeColors`] palette. [`MapTheme`] is
//! the customization point: implement it to install your own palette instead
//! of one of the built-ins, the same way [`NodeTemplate`](super::objects::NodeTemplate)
//! and [`SegmentTemplate`](super::objects::SegmentTemplate) let you replace
//! the built-in node/segment rendering. [`Style`] is the non-palette visual
//! configuration (stroke widths, font, background) that the active
//! [`MapTheme`] colors are combined with when the widget paints.

use crate::map::theme::{
    ColorMode::{Dark, Light},
    Theme::*,
};
use egui::ecolor::Color32;
use egui::{FontId, Stroke};
use std::ops::{Div, Mul};

/// A built-in, named color palette, in both a light and a dark variant.
///
/// Resolve it to actual colors with [`Theme::colors`]. Install one on a
/// [`Map`](super::Map) as its active [`MapTheme`] with
/// [`Map::set_theme`](super::Map::set_theme) -- `Theme` implements
/// [`MapTheme`] directly, so any variant can be passed straight in.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Theme {
    /// Muted blues over slate grays.
    SlateOcean,
    /// Violet and teal on a soft neutral backdrop. The default theme.
    #[default]
    NebulaViolet,
    /// Greens and blues reminiscent of a terminal color scheme.
    TerminalGreen,
    /// Warm oranges and pinks over charcoal/cream.
    EmberForge,
    /// Amber and teal on a warm neutral backdrop.
    SolarAmber,
    /// Cyan and gold over deep blue-gray.
    ArticCyan,
    /// Signal red and steel blue over near-black.
    CrimsonSignal,
    /// Indigo and teal on deep midnight blue.
    MidnightIndigo,
    /// Copper and teal over warm taupe.
    CopperRose,
    /// Lime green and violet over dark olive.
    LimeCircuit,
    /// Coral and ocean blue over sea-glass teal.
    CoralReef,
    /// Grayscale with a cool blue accent.
    GraphiteMono,
    /// Plum and jade over muted mauve.
    PlumStatic,
    /// Sand and clay over warm khaki.
    SandstoneTrail,
}

impl Theme {
    /// Resolves this theme to its actual [`ThemeColors`] for the given
    /// [`ColorMode`].
    pub const fn colors(self, mode: ColorMode) -> ThemeColors {
        match (self, mode) {
            (SlateOcean, Dark) => ThemeColors {
                node: Color32::from_rgb(0x6E, 0x93, 0xBF),
                segment: Color32::from_rgb(0x4A, 0x5A, 0x6E),
                selected: Color32::from_rgb(0x38, 0xBD, 0xF8),
                alert: Color32::from_rgb(0xFF, 0x8A, 0x4C),
                text: Color32::from_rgb(0xD7, 0xDE, 0xE6),
            },
            (SlateOcean, Light) => ThemeColors {
                node: Color32::from_rgb(0x2E, 0x4C, 0x6D),
                segment: Color32::from_rgb(0x8A, 0x99, 0xA8),
                selected: Color32::from_rgb(0x0E, 0xA5, 0xE9),
                alert: Color32::from_rgb(0xE0, 0x59, 0x2A),
                text: Color32::from_rgb(0x2B, 0x33, 0x3D),
            },
            (NebulaViolet, Light) => ThemeColors {
                node: Color32::from_rgb(0x5B, 0x3E, 0x96),
                segment: Color32::from_rgb(0xB3, 0xA4, 0xD6),
                selected: Color32::from_rgb(0x16, 0xB8, 0xA6),
                alert: Color32::from_rgb(0xE6, 0x33, 0x7A),
                text: Color32::from_rgb(0x37, 0x2F, 0x45),
            },
            (NebulaViolet, Dark) => ThemeColors {
                node: Color32::from_rgb(0xA7, 0x8B, 0xFA),
                segment: Color32::from_rgb(0x5C, 0x4A, 0x80),
                selected: Color32::from_rgb(0x2D, 0xD4, 0xBF),
                alert: Color32::from_rgb(0xFF, 0x5F, 0xA3),
                text: Color32::from_rgb(0xE4, 0xDC, 0xF2),
            },
            (TerminalGreen, Light) => ThemeColors {
                node: Color32::from_rgb(0x1F, 0x7A, 0x3D),
                segment: Color32::from_rgb(0x9B, 0xB8, 0x9E),
                selected: Color32::from_rgb(0x25, 0x63, 0xEB),
                alert: Color32::from_rgb(0xD6, 0xA4, 0x29),
                text: Color32::from_rgb(0x2A, 0x33, 0x2C),
            },
            (TerminalGreen, Dark) => ThemeColors {
                node: Color32::from_rgb(0x4A, 0xDE, 0x80),
                segment: Color32::from_rgb(0x3A, 0x52, 0x40),
                selected: Color32::from_rgb(0x60, 0xA5, 0xFA),
                alert: Color32::from_rgb(0xFF, 0xC9, 0x4D),
                text: Color32::from_rgb(0xD7, 0xE6, 0xDA),
            },
            (EmberForge, Light) => ThemeColors {
                node: Color32::from_rgb(0x8C, 0x4A, 0x1F),
                segment: Color32::from_rgb(0xC9, 0xA9, 0x8C),
                selected: Color32::from_rgb(0xC4, 0x25, 0x8C),
                alert: Color32::from_rgb(0x2E, 0x86, 0xAB),
                text: Color32::from_rgb(0x36, 0x2E, 0x28),
            },
            (EmberForge, Dark) => ThemeColors {
                node: Color32::from_rgb(0xD9, 0x7F, 0x3D),
                segment: Color32::from_rgb(0x5A, 0x46, 0x32),
                selected: Color32::from_rgb(0xF4, 0x72, 0xB6),
                alert: Color32::from_rgb(0x4F, 0xC3, 0xE8),
                text: Color32::from_rgb(0xED, 0xE0, 0xD3),
            },
            (SolarAmber, Dark) => ThemeColors {
                node: Color32::from_rgb(0x8A, 0x6D, 0x1E),
                segment: Color32::from_rgb(0xD8, 0xC4, 0x8F),
                selected: Color32::from_rgb(0x2D, 0x6E, 0x5E),
                alert: Color32::from_rgb(0xC1, 0x44, 0x2A),
                text: Color32::from_rgb(0x36, 0x2E, 0x1C),
            },
            (SolarAmber, Light) => ThemeColors {
                node: Color32::from_rgb(0xF0, 0xC2, 0x4C),
                segment: Color32::from_rgb(0x5A, 0x4E, 0x2E),
                selected: Color32::from_rgb(0x4F, 0xBF, 0x9E),
                alert: Color32::from_rgb(0xE8, 0x65, 0x4A),
                text: Color32::from_rgb(0xEF, 0xE4, 0xC4),
            },
            (ArticCyan, Dark) => ThemeColors {
                node: Color32::from_rgb(0x12, 0x70, 0x8A),
                segment: Color32::from_rgb(0x9A, 0xC6, 0xD1),
                selected: Color32::from_rgb(0xF5, 0xA5, 0x24),
                alert: Color32::from_rgb(0xE0, 0x52, 0x7A),
                text: Color32::from_rgb(0x1F, 0x2E, 0x30),
            },
            (ArticCyan, Light) => ThemeColors {
                node: Color32::from_rgb(0x4F, 0xE0, 0xFF),
                segment: Color32::from_rgb(0x37, 0x5E, 0x68),
                selected: Color32::from_rgb(0xFB, 0xBF, 0x24),
                alert: Color32::from_rgb(0xFF, 0x6B, 0x95),
                text: Color32::from_rgb(0xD3, 0xEA, 0xEF),
            },
            (CrimsonSignal, Dark) => ThemeColors {
                node: Color32::from_rgb(0xE3, 0x5B, 0x6B),
                segment: Color32::from_rgb(0x5C, 0x45, 0x48),
                selected: Color32::from_rgb(0x58, 0xA6, 0xFF),
                alert: Color32::from_rgb(0xFF, 0xC4, 0x59),
                text: Color32::from_rgb(0xE8, 0xD6, 0xD8),
            },
            (CrimsonSignal, Light) => ThemeColors {
                node: Color32::from_rgb(0x7A, 0x1F, 0x2B),
                segment: Color32::from_rgb(0xB9, 0xA8, 0xA8),
                selected: Color32::from_rgb(0x1F, 0x6F, 0xEB),
                alert: Color32::from_rgb(0xE8, 0xA6, 0x28),
                text: Color32::from_rgb(0x33, 0x26, 0x28),
            },

            (MidnightIndigo, Dark) => ThemeColors {
                node: Color32::from_rgb(0x7B, 0x82, 0xE0),
                segment: Color32::from_rgb(0x3A, 0x3D, 0x66),
                selected: Color32::from_rgb(0x2D, 0xD4, 0xC8),
                alert: Color32::from_rgb(0xFF, 0xD1, 0x66),
                text: Color32::from_rgb(0xD8, 0xDA, 0xF0),
            },
            (MidnightIndigo, Light) => ThemeColors {
                node: Color32::from_rgb(0x2B, 0x2F, 0x77),
                segment: Color32::from_rgb(0xA6, 0xA9, 0xC9),
                selected: Color32::from_rgb(0x00, 0xB8, 0xA9),
                alert: Color32::from_rgb(0xE0, 0xA4, 0x00),
                text: Color32::from_rgb(0x26, 0x29, 0x40),
            },

            (CopperRose, Dark) => ThemeColors {
                node: Color32::from_rgb(0xE0, 0x8B, 0x6F),
                segment: Color32::from_rgb(0x5E, 0x45, 0x3D),
                selected: Color32::from_rgb(0x4F, 0xC3, 0xAE),
                alert: Color32::from_rgb(0xFF, 0xC6, 0x5C),
                text: Color32::from_rgb(0xEF, 0xDA, 0xD0),
            },
            (CopperRose, Light) => ThemeColors {
                node: Color32::from_rgb(0x9C, 0x4A, 0x3C),
                segment: Color32::from_rgb(0xD9, 0xB8, 0xAE),
                selected: Color32::from_rgb(0x2F, 0x7A, 0x6B),
                alert: Color32::from_rgb(0xE0, 0xA2, 0x3C),
                text: Color32::from_rgb(0x3D, 0x2E, 0x29),
            },

            (LimeCircuit, Dark) => ThemeColors {
                node: Color32::from_rgb(0xA8, 0xE0, 0x5F),
                segment: Color32::from_rgb(0x44, 0x52, 0x30),
                selected: Color32::from_rgb(0xA7, 0x8B, 0xFA),
                alert: Color32::from_rgb(0xFF, 0x85, 0x52),
                text: Color32::from_rgb(0xDC, 0xEA, 0xC0),
            },
            (LimeCircuit, Light) => ThemeColors {
                node: Color32::from_rgb(0x4D, 0x7A, 0x1F),
                segment: Color32::from_rgb(0xB9, 0xC7, 0x9A),
                selected: Color32::from_rgb(0x7B, 0x3F, 0xE4),
                alert: Color32::from_rgb(0xE8, 0x5D, 0x2E),
                text: Color32::from_rgb(0x2E, 0x33, 0x20),
            },

            (CoralReef, Dark) => ThemeColors {
                node: Color32::from_rgb(0xFF, 0x8B, 0x73),
                segment: Color32::from_rgb(0x38, 0x65, 0x60),
                selected: Color32::from_rgb(0x5C, 0xA8, 0xE0),
                alert: Color32::from_rgb(0xFF, 0xC1, 0x5E),
                text: Color32::from_rgb(0xD6, 0xED, 0xE8),
            },
            (CoralReef, Light) => ThemeColors {
                node: Color32::from_rgb(0xD6, 0x5A, 0x45),
                segment: Color32::from_rgb(0xA8, 0xD4, 0xCE),
                selected: Color32::from_rgb(0x1D, 0x5C, 0x9E),
                alert: Color32::from_rgb(0xF2, 0xA9, 0x3C),
                text: Color32::from_rgb(0x33, 0x40, 0x3E),
            },

            (GraphiteMono, Dark) => ThemeColors {
                node: Color32::from_rgb(0xD6, 0xD6, 0xD2),
                segment: Color32::from_rgb(0x4A, 0x4A, 0x46),
                selected: Color32::from_rgb(0x4F, 0xB3, 0xF5),
                alert: Color32::from_rgb(0xFF, 0x6B, 0x5C),
                text: Color32::from_rgb(0xE8, 0xE8, 0xE4),
            },
            (GraphiteMono, Light) => ThemeColors {
                node: Color32::from_rgb(0x3A, 0x3A, 0x3A),
                segment: Color32::from_rgb(0xB8, 0xB8, 0xB4),
                selected: Color32::from_rgb(0x1F, 0x8F, 0xE0),
                alert: Color32::from_rgb(0xE0, 0x48, 0x3A),
                text: Color32::from_rgb(0x23, 0x23, 0x23),
            },

            (PlumStatic, Dark) => ThemeColors {
                node: Color32::from_rgb(0xC9, 0x94, 0xBB),
                segment: Color32::from_rgb(0x4A, 0x3A, 0x45),
                selected: Color32::from_rgb(0x52, 0xC9, 0x9A),
                alert: Color32::from_rgb(0xFF, 0xA0, 0x5C),
                text: Color32::from_rgb(0xEB, 0xD9, 0xE5),
            },
            (PlumStatic, Light) => ThemeColors {
                node: Color32::from_rgb(0x6B, 0x3B, 0x5E),
                segment: Color32::from_rgb(0xC7, 0xAE, 0xC0),
                selected: Color32::from_rgb(0x2E, 0x8B, 0x6E),
                alert: Color32::from_rgb(0xE0, 0x79, 0x3D),
                text: Color32::from_rgb(0x36, 0x2B, 0x33),
            },

            (SandstoneTrail, Dark) => ThemeColors {
                node: Color32::from_rgb(0xC9, 0xAD, 0x72),
                segment: Color32::from_rgb(0x4E, 0x45, 0x30),
                selected: Color32::from_rgb(0x4F, 0xA8, 0xCC),
                alert: Color32::from_rgb(0xF0, 0x70, 0x8A),
                text: Color32::from_rgb(0xE6, 0xD9, 0xB8),
            },
            (SandstoneTrail, Light) => ThemeColors {
                node: Color32::from_rgb(0x6B, 0x5A, 0x3A),
                segment: Color32::from_rgb(0xDC, 0xCB, 0xA0),
                selected: Color32::from_rgb(0x2A, 0x6E, 0x8C),
                alert: Color32::from_rgb(0xD1, 0x49, 0x5B),
                text: Color32::from_rgb(0x3A, 0x31, 0x21),
            },
        }
    }
}

/// A resolved color palette: the actual colors a [`Theme`] (or any other
/// [`MapTheme`] implementation) uses to paint the map under one
/// [`ColorMode`].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ThemeColors {
    /// Color used to fill node shapes.
    pub node: Color32,
    /// Color used for connection lines between nodes.
    pub segment: Color32,
    /// Color used for the selection highlight over the nearest node.
    pub selected: Color32,
    /// Color used for notification and alert animations.
    pub alert: Color32,
    /// Color used for node names and map labels.
    pub text: Color32,
}

/// Which of a theme's two color variants to use.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ColorMode {
    /// The light variant.
    Light,
    /// The dark variant.
    Dark,
}

/// Customization point for the color palette used to paint the map.
///
/// Implement this to install your own palette instead of one of the
/// built-in [`Theme`] variants -- install it with
/// [`Map::set_theme`](super::Map::set_theme). `Theme` itself implements
/// `MapTheme` by delegating to [`Theme::colors`], so switching between a
/// built-in palette and a custom one is just a different argument to
/// `set_theme`.
///
/// ```
/// use egui_map::map::theme::{ColorMode, MapTheme, ThemeColors};
/// use egui::Color32;
///
/// struct HighContrast;
///
/// impl MapTheme for HighContrast {
///     fn colors(&self, mode: ColorMode) -> ThemeColors {
///         match mode {
///             ColorMode::Light => ThemeColors {
///                 node: Color32::BLACK,
///                 segment: Color32::DARK_GRAY,
///                 selected: Color32::RED,
///                 alert: Color32::RED,
///                 text: Color32::BLACK,
///             },
///             ColorMode::Dark => ThemeColors {
///                 node: Color32::WHITE,
///                 segment: Color32::LIGHT_GRAY,
///                 selected: Color32::YELLOW,
///                 alert: Color32::YELLOW,
///                 text: Color32::WHITE,
///             },
///         }
///     }
/// }
///
/// let mut map = egui_map::map::Map::new();
/// map.set_theme(std::rc::Rc::new(HighContrast));
/// ```
pub trait MapTheme {
    /// Returns the color palette to use for the given [`ColorMode`].
    fn colors(&self, mode: ColorMode) -> ThemeColors;
}

impl MapTheme for Theme {
    fn colors(&self, mode: ColorMode) -> ThemeColors {
        Theme::colors(*self, mode)
    }
}

/// Visual style used to paint the map under a given theme.
///
/// Holds the non-palette visual configuration -- stroke widths, font,
/// background -- that combines with the active [`MapTheme`]'s
/// [`ThemeColors`] when the widget paints; the widget refreshes
/// [`fill_color`](Self::fill_color), [`alert_color`](Self::alert_color), the
/// [`line`](Self::line) color and [`text_color`](Self::text_color) from the
/// installed theme whenever the color mode changes, so a `Style` never needs
/// its own copy of those colors.
///
/// Multiplying or dividing a `Style` by a number scales the stroke widths
/// and the font size, leaving colors untouched; the widget uses this to scale
/// the active style with the current zoom factor. Fields that are `None` are
/// left untouched by those operators.
#[derive(Clone, Debug)]
pub struct Style {
    /// Stroke used for the widget border.
    pub border: Option<Stroke>,
    /// Stroke used for the connection lines between nodes.
    pub line: Option<Stroke>,
    /// Color used to fill node shapes.
    pub fill_color: Color32,
    /// Color used for text.
    pub text_color: Color32,
    /// Font used for map labels.
    pub font: Option<FontId>,
    /// Background color of the map canvas.
    pub background_color: Color32,
    /// Color used for notification pulse animations.
    pub alert_color: Color32,
}

impl Style {
    /// Creates a fully transparent style with no border, line or font.
    pub fn new() -> Self {
        Style {
            border: None,
            line: None,
            fill_color: Color32::TRANSPARENT,
            text_color: Color32::TRANSPARENT,
            font: None,
            background_color: Color32::TRANSPARENT,
            alert_color: Color32::TRANSPARENT,
        }
    }
}

impl Default for Style {
    fn default() -> Self {
        Style::new()
    }
}

impl Style {
    /// Returns a copy with the stroke widths and font size scaled by `factor`.
    /// Fields that are `None` are left untouched.
    fn scaled(mut self, factor: f32) -> Self {
        if let Some(border) = self.border.as_mut() {
            border.width *= factor;
        }
        if let Some(line) = self.line.as_mut() {
            line.width *= factor;
        }
        if let Some(font) = self.font.as_mut() {
            font.size *= factor;
        }
        self
    }
}

impl Mul<i64> for Style {
    type Output = Self;

    fn mul(self, rhs: i64) -> Self::Output {
        self.scaled(rhs as f32)
    }
}

impl Mul<i32> for Style {
    type Output = Self;

    fn mul(self, rhs: i32) -> Self::Output {
        self.scaled(rhs as f32)
    }
}

impl Mul<f32> for Style {
    type Output = Self;

    fn mul(self, rhs: f32) -> Self::Output {
        self.scaled(rhs)
    }
}

impl Mul<f64> for Style {
    type Output = Self;

    fn mul(self, rhs: f64) -> Self::Output {
        self.scaled(rhs as f32)
    }
}

impl Div<i64> for Style {
    type Output = Self;

    fn div(self, rhs: i64) -> Self::Output {
        self.scaled(1.0 / rhs as f32)
    }
}

impl Div<i32> for Style {
    type Output = Self;

    fn div(self, rhs: i32) -> Self::Output {
        self.scaled(1.0 / rhs as f32)
    }
}

impl Div<f32> for Style {
    type Output = Self;

    fn div(self, rhs: f32) -> Self::Output {
        self.scaled(1.0 / rhs)
    }
}

impl Div<f64> for Style {
    type Output = Self;

    fn div(self, rhs: f64) -> Self::Output {
        self.scaled(1.0 / rhs as f32)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    const ALL_THEMES: [Theme; 14] = [
        Theme::SlateOcean,
        Theme::NebulaViolet,
        Theme::TerminalGreen,
        Theme::EmberForge,
        Theme::SolarAmber,
        Theme::ArticCyan,
        Theme::CrimsonSignal,
        Theme::MidnightIndigo,
        Theme::CopperRose,
        Theme::LimeCircuit,
        Theme::CoralReef,
        Theme::GraphiteMono,
        Theme::PlumStatic,
        Theme::SandstoneTrail,
    ];

    #[test]
    fn every_theme_has_distinct_light_and_dark_palettes() {
        // Regression test for a typo (`Ligth` instead of `Light`) that once
        // made an unqualified identifier bind irrefutably in a match arm,
        // silently turning `(SolarAmber, Light)` into a catch-all -- it only
        // still looked right because `(SolarAmber, Dark)`, listed first,
        // matched exactly and won for that case, leaving the buggy arm to
        // fire (and return the *wrong*, `Dark`-shaped) colors for `Light`.
        for theme in ALL_THEMES {
            let light = theme.colors(ColorMode::Light);
            let dark = theme.colors(ColorMode::Dark);
            assert_ne!(
                light, dark,
                "{theme:?}'s Light and Dark palettes must not be identical"
            );
        }
    }

    #[test]
    fn solar_amber_light_matches_its_defined_palette() {
        // Pins the exact SolarAmber/Light values so a regression back to the
        // `Ligth` typo -- which made this arm silently reuse whatever
        // `(SolarAmber, Dark)` produced -- is caught even though `assert_ne`
        // alone only proves the two differ, not that `Light` is *this*
        // palette.
        assert_eq!(
            Theme::SolarAmber.colors(ColorMode::Light),
            ThemeColors {
                node: Color32::from_rgb(0xF0, 0xC2, 0x4C),
                segment: Color32::from_rgb(0x5A, 0x4E, 0x2E),
                selected: Color32::from_rgb(0x4F, 0xBF, 0x9E),
                alert: Color32::from_rgb(0xE8, 0x65, 0x4A),
                text: Color32::from_rgb(0xEF, 0xE4, 0xC4),
            }
        );
    }

    #[test]
    fn theme_implements_map_theme_by_delegating_to_colors() {
        let theme: &dyn MapTheme = &Theme::TerminalGreen;
        assert_eq!(
            theme.colors(ColorMode::Dark),
            Theme::TerminalGreen.colors(ColorMode::Dark)
        );
        assert_eq!(
            theme.colors(ColorMode::Light),
            Theme::TerminalGreen.colors(ColorMode::Light)
        );
    }
}