Skip to content

Commit cb69c02

Browse files
committed
Created efx-playground
1 parent 9e2cdf1 commit cb69c02

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

efx-playground/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "efx-playground"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
eframe = "0.33.0"
8+
egui = "0.33.0"
9+
efx = "0.6.1"
10+
11+
[target.'cfg(target_arch = "wasm32")'.dependencies]
12+
wasm-bindgen = "0.2"
13+
14+
[profile.release]
15+
lto = "fat"
16+
codegen-units = 1
17+
opt-level = "z"
18+
panic = "abort"

efx-playground/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta name="viewport" content="width=device-width,initial-scale=1"/>
6+
<title>EFx Playground</title>
7+
</head>
8+
<body style="margin:0">
9+
<canvas id="efx-canvas" style="width:100vw;height:100vh;display:block"></canvas>
10+
</body>
11+
</html>

efx-playground/src/main.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
struct App {
3+
clicks: i32,
4+
}
5+
6+
impl App {
7+
fn new(_: &eframe::CreationContext<'_>) -> Self {
8+
Self { clicks: 0 }
9+
}
10+
}
11+
12+
impl eframe::App for App {
13+
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
14+
egui::CentralPanel::default().show(ctx, |ui| {
15+
let clicks = self.clicks;
16+
efx!(ui, r#"
17+
<Column gap="8" align="center">
18+
<Heading>EFx Playground</Heading>
19+
<Label color="green">Clicks: {clicks}</Label>
20+
<Button onClick=increment>Click me</Button>
21+
</Column>
22+
"#);
23+
});
24+
}
25+
}
26+
27+
impl App {
28+
fn increment(&mut self) { self.clicks += 1; }
29+
}
30+
31+
#[cfg(not(target_arch = "wasm32"))]
32+
fn main() -> eframe::Result<()> {
33+
let opts = eframe::NativeOptions::default();
34+
eframe::run_native("EFx Playground", opts, Box::new(|cc| Box::new(App::new(cc))))
35+
}
36+
37+
#[cfg(target_arch = "wasm32")]
38+
use wasm_bindgen::prelude::*;
39+
40+
#[cfg(target_arch = "wasm32")]
41+
#[wasm_bindgen(start)]
42+
pub async fn start() -> Result<(), wasm_bindgen::JsValue> {
43+
eframe::WebLogger::init(log::LevelFilter::Info).ok();
44+
let web_options = eframe::WebOptions::default();
45+
eframe::WebRunner::new()
46+
.start("efx-canvas", web_options, Box::new(|cc| Box::new(App::new(cc))))
47+
.await
48+
}

0 commit comments

Comments
 (0)