v2rmp 0.4.5

rmpca — Route Optimization TUI & Agent Engine
Documentation
#![warn(clippy::all, rust_2018_idioms)]
//! v2rmp Web UI — full egui graphical frontend for the v2rmp route optimization crate.
//!
//! Supports both native (eframe + rfd) and WASM (eframe + web-sys canvas).

use v2rmp::gui::GuiApp;

#[cfg(not(target_arch = "wasm32"))]
fn main() -> eframe::Result<()> {
    let native_options = eframe::NativeOptions {
        viewport: eframe::egui::ViewportBuilder::default()
            .with_inner_size([1200.0, 800.0])
            .with_title("rmpca - Route Optimizer"),
        ..Default::default()
    };
    eframe::run_native(
        "rmpca - Route Optimizer",
        native_options,
        Box::new(|cc| Ok(Box::new(GuiApp::new(cc)))),
    )
}

#[cfg(target_arch = "wasm32")]
fn main() {
    use wasm_bindgen::JsCast;

    eframe::WebLogger::init(log::LevelFilter::Debug).ok();

    let web_options = eframe::WebOptions::default();

    wasm_bindgen_futures::spawn_local(async {
        let document = web_sys::window()
            .expect("no global window exists")
            .document()
            .expect("should have a document on window");

        let canvas = document
            .get_element_by_id("the_canvas_id")
            .expect("failed to find canvas with id the_canvas_id")
            .dyn_into::<web_sys::HtmlCanvasElement>()
            .map_err(|_| ())
            .expect("element was not a canvas");

        let start_result = eframe::WebRunner::new()
            .start(
                canvas,
                web_options,
                Box::new(|cc| Ok(Box::new(GuiApp::new(cc)))),
            )
            .await;

        if let Err(e) = start_result {
            log::error!("Failed to start eframe: {:?}", e);
        }
    });
}