Skip to main content

MapTheme

Trait MapTheme 

Source
pub trait MapTheme {
    // Required method
    fn colors(&self, mode: ColorMode) -> ThemeColors;
}
Expand description

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. 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));

Required Methods§

Source

fn colors(&self, mode: ColorMode) -> ThemeColors

Returns the color palette to use for the given ColorMode.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§