alma 0.1.0

A Bevy-native modal text editor with Vim-style navigation.
Documentation
//! Font catalog and font resolution for bundled editor fonts.

use bevy::prelude::{AssetServer, Font, FontWeight, Handle, TextFont, default};
use std::path::Path;

/// Font size for editor buffer text in logical pixels.
pub const EDITOR_FONT_SIZE: f32 = 32.0;

/// Bundled regular editor font asset path.
const EDITOR_FONT_ASSET: &str = "fonts/FiraCodeNerdFontMono-Regular.ttf";

/// Builds the mono editor font.
pub fn editor_font(asset_server: &AssetServer, font_size: f32) -> TextFont {
    TextFont {
        font: font_handle(asset_server, EDITOR_FONT_ASSET),
        font_size,
        weight: FontWeight(400),
        ..default()
    }
}

/// Loads a native font asset when present, otherwise uses Bevy's built-in default font.
fn font_handle(asset_server: &AssetServer, asset_path: &str) -> Handle<Font> {
    let filesystem_path = Path::new("assets").join(asset_path);

    if filesystem_path.is_file() {
        asset_server.load(asset_path.to_owned())
    } else {
        Handle::default()
    }
}