|
| 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