gled-ui 2.32.1

gled's egui interface, shared by the desktop app and the browser
Documentation
//! gled's look: its fonts, the dark theme and the image loaders, the same on
//! the desktop and in the browser.

use std::sync::Arc;

use egui::{Color32, Context, FontData, FontDefinitions, FontFamily, FontTweak, ThemePreference};

/// The license of the Oxanium font gled ships.
pub const OPEN_FONT_LICENSE: &str = include_str!("../assets/OFL.txt");

/// Sets gled's fonts, theme and image loaders on `ctx`.
pub fn apply(ctx: &Context) {
    let mut fonts = FontDefinitions::default();
    egui_phosphor_icons::add_fonts(&mut fonts);

    let oxanium_tweak = FontTweak {
        scale: 1.0,
        y_offset_factor: 0.15,
        y_offset: 0.0,
        ..Default::default()
    };
    fonts.font_data.insert(
        "Oxanium_Regular".to_owned(),
        Arc::from(
            FontData::from_static(include_bytes!("../assets/Oxanium-Regular.ttf"))
                .tweak(oxanium_tweak.clone()),
        ),
    );
    fonts.font_data.insert(
        "Oxanium_Semi_Bold".to_owned(),
        Arc::from(
            FontData::from_static(include_bytes!("../assets/Oxanium-SemiBold.ttf"))
                .tweak(oxanium_tweak),
        ),
    );
    if let Some(proportional) = fonts.families.get_mut(&FontFamily::Proportional) {
        proportional.insert(0, "Oxanium_Regular".to_owned());
    }
    fonts.families.insert(
        FontFamily::Name("Bold".into()),
        vec!["Oxanium_Semi_Bold".into()],
    );
    ctx.set_fonts(fonts);

    ctx.options_mut(|options| options.theme_preference = ThemePreference::Dark);
    ctx.global_style_mut(|style| {
        style.always_scroll_the_only_direction = true;
        style.visuals.panel_fill = Color32::from_gray(5);
    });
    egui_extras::install_image_loaders(ctx);
}