Build for web
This commit is contained in:
parent
619f9594cf
commit
ff60439dd5
|
@ -2467,6 +2467,8 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"plate-tool-lib",
|
"plate-tool-lib",
|
||||||
"serde",
|
"serde",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
/dist
|
|
@ -13,5 +13,17 @@ eframe = { version = "0.30", default-features = false, features = [
|
||||||
]}
|
]}
|
||||||
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = "0.11"
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
env_logger = "0.11"
|
||||||
|
|
||||||
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
|
wasm-bindgen-futures = "0.4"
|
||||||
|
web-sys = "0.3"
|
||||||
|
|
||||||
|
#[profile.release]
|
||||||
|
#opt-level = 2
|
||||||
|
|
||||||
|
#[profile.dev.package."*"]
|
||||||
|
#opt-level = 2
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
[build]
|
||||||
|
target = "index.html"
|
||||||
|
release = true
|
|
@ -0,0 +1,53 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link data-trunk rel="rust" data-bin="plate-tool-eframe" />
|
||||||
|
<title>Plate Tool</title>
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
/* Remove touch delay: */
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
/* Light mode background color for what is not covered by the egui canvas,
|
||||||
|
or where the egui canvas is translucent. */
|
||||||
|
background: #909090;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
body {
|
||||||
|
/* Dark mode background color for what is not covered by the egui canvas,
|
||||||
|
or where the egui canvas is translucent. */
|
||||||
|
background: #404040;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allow canvas to fill entire web page: */
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make canvas fill entire document: */
|
||||||
|
canvas {
|
||||||
|
margin-right: auto;
|
||||||
|
margin-left: auto;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="main_canvas"></canvas>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,18 +1,48 @@
|
||||||
use eframe::*;
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
use eframe::*;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
fn main() -> eframe::Result {
|
fn main() -> eframe::Result {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
log::info!("Shrimp!");
|
log::info!("Shrimp!");
|
||||||
|
|
||||||
let native_options = eframe::NativeOptions {
|
let native_options = eframe::NativeOptions {
|
||||||
viewport: egui::ViewportBuilder::default()
|
viewport: egui::ViewportBuilder::default().with_title("Shrimp"),
|
||||||
.with_title("Shrimp"),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"PlateToolEframe",
|
"PlateToolEframe",
|
||||||
native_options,
|
native_options,
|
||||||
Box::new(|cc| Ok(Box::new(plate_tool_eframe::PlateToolEframe::new(cc))))
|
Box::new(|cc| Ok(Box::new(plate_tool_eframe::PlateToolEframe::new(cc)))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
fn main() {
|
||||||
|
use eframe::wasm_bindgen::JsCast as _;
|
||||||
|
|
||||||
|
eframe::WebLogger::init(log::LevelFilter::Info).ok();
|
||||||
|
|
||||||
|
let web_options = eframe::WebOptions::default();
|
||||||
|
|
||||||
|
wasm_bindgen_futures::spawn_local(async {
|
||||||
|
let document = web_sys::window()
|
||||||
|
.expect("No window")
|
||||||
|
.document()
|
||||||
|
.expect("No document");
|
||||||
|
|
||||||
|
let canvas = document
|
||||||
|
.get_element_by_id("main_canvas")
|
||||||
|
.expect("Canvas id not found")
|
||||||
|
.dyn_into::<web_sys::HtmlCanvasElement>()
|
||||||
|
.expect("Canvas was not a HtmlCanvasElement");
|
||||||
|
|
||||||
|
let start_result = eframe::WebRunner::new()
|
||||||
|
.start(
|
||||||
|
canvas,
|
||||||
|
web_options,
|
||||||
|
Box::new(|cc| Ok(Box::new(plate_tool_eframe::PlateToolEframe::new(cc)))),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue