Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/korp-map

crates/sverigekartan/src/main.rs

//! `sverigekartan` — the window. All behaviour is in the library ([`sverigekartan::App`]);
//! this reads the command line and runs eframe on wgpu (Vulkan / Metal / DX12, no GL).

use std::sync::Arc;

use sverigekartan::{App, Cli, parse_args};

fn main() -> std::process::ExitCode {
    let opts = match parse_args(std::env::args().skip(1)) {
        Ok(Cli::Run(o)) => o,
        Ok(Cli::Print(text)) => {
            println!("{text}");
            return std::process::ExitCode::SUCCESS;
        }
        Err(e) => {
            eprintln!("sverigekartan: {e}");
            return std::process::ExitCode::from(2);
        }
    };
    let native = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default()
            .with_inner_size([1280.0, 860.0])
            .with_min_inner_size([640.0, 480.0])
            .with_title("Sverigekartan")
            .with_app_id("sverigekartan"),
        renderer: eframe::Renderer::Wgpu,
        wgpu_options: facett_core::render::gpu::facett_wgpu_options(),
        ..Default::default()
    };
    let run = eframe::run_native(
        "sverigekartan",
        native,
        Box::new(move |cc| {
            facett_core::LookTheme::from_os(cc.egui_ctx.os()).apply(&cc.egui_ctx);
            facett_core::fonts::install(&cc.egui_ctx);
            if let Some(rs) = cc.wgpu_render_state.as_ref() {
                sverigekartan::install_gpu(rs);
            }
            let ctx = cc.egui_ctx.clone();
            Ok(Box::new(Window(App::new(
                opts,
                Some(Arc::new(move || ctx.request_repaint())),
            ))))
        }),
    );
    match run {
        Ok(()) => std::process::ExitCode::SUCCESS,
        Err(e) => {
            eprintln!("sverigekartan: {e}");
            std::process::ExitCode::FAILURE
        }
    }
}

struct Window(App);

impl eframe::App for Window {
    fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
        self.0.ui(ui);
    }
}