#![warn(clippy::all, rust_2018_idioms)]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
pub trait NewCC {
fn new(cc: &eframe::CreationContext<'_>) -> Self;
fn canvas_id() -> String {
"the_canvas_id".into()
}
}
#[cfg(not(target_arch = "wasm32"))]
pub fn native_setup<T: eframe::App + NewCC + 'static>(eapp: T) -> eframe::Result<()> {
env_logger::init();
let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([400.0, 300.0])
.with_min_inner_size([300.0, 220.0]),
..Default::default()
};
eframe::run_native(
"gold silver copper",
native_options,
Box::new(|cc| Box::new(T::new(cc))),
)
}
#[cfg(any(target_arch = "wasm32", doc))]
pub fn wasm_setup<T: eframe::App + NewCC + 'static>(eapp: T) {
eframe::WebLogger::init(log::LevelFilter::Debug).ok();
let web_options = eframe::WebOptions::default();
wasm_bindgen_futures::spawn_local(async move {
eframe::WebRunner::new()
.start(
&T::canvas_id(), web_options,
Box::new(|cc| Box::new(T::new(cc))),
)
.await
.expect("failed to start eframe");
});
}