//! Editor text and icon font registration for the primary egui context.

use bevy::prelude::*;
use bevy_egui::{EguiContext, PrimaryEguiContext};

pub struct EditorFontsPlugin;

impl Plugin for EditorFontsPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Update, configure_editor_fonts);
    }
}

fn configure_editor_fonts(mut contexts: Query<&mut EguiContext, Added<PrimaryEguiContext>>) {
    let Some(mut ctx) = contexts.iter_mut().next() else {
        return;
    };
    ctx.get_mut().set_fonts(editor_font_definitions());
}

pub(crate) fn editor_font_definitions() -> bevy_egui::egui::FontDefinitions {
    editor_ui::fonts::font_definitions()
}
