diff --git a/Cargo.lock b/Cargo.lock index adb8bc136..334adc4b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -375,6 +375,27 @@ dependencies = [ "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "demo_glium" +version = "0.1.0" +dependencies = [ + "egui 0.1.2 (git+https://github.com/emilk/emigui)", + "egui_glium 0.1.0 (git+https://github.com/emilk/emigui)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "demo_web" +version = "0.1.0" +dependencies = [ + "egui 0.1.2 (git+https://github.com/emilk/emigui)", + "egui_web 0.1.0 (git+https://github.com/emilk/emigui)", + "js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "derivative" version = "2.1.1" @@ -403,6 +424,17 @@ name = "downcast-rs" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "egui" +version = "0.1.2" +source = "git+https://github.com/emilk/emigui#3552f7f82861fb10ae646c61f3c283256e79940e" +dependencies = [ + "ahash 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rusttype 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "egui" version = "0.1.2" @@ -414,6 +446,20 @@ dependencies = [ "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "egui_glium" +version = "0.1.0" +source = "git+https://github.com/emilk/emigui#3552f7f82861fb10ae646c61f3c283256e79940e" +dependencies = [ + "chrono 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", + "clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "egui 0.1.2 (git+https://github.com/emilk/emigui)", + "glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", + "webbrowser 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "egui_glium" version = "0.1.0" @@ -430,8 +476,9 @@ dependencies = [ [[package]] name = "egui_web" version = "0.1.0" +source = "git+https://github.com/emilk/emigui#3552f7f82861fb10ae646c61f3c283256e79940e" dependencies = [ - "egui 0.1.2", + "egui 0.1.2 (git+https://github.com/emilk/emigui)", "js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", @@ -441,31 +488,30 @@ dependencies = [ ] [[package]] -name = "either" -version = "1.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "example_glium" +name = "egui_web" version = "0.1.0" dependencies = [ "egui 0.1.2", - "egui_glium 0.1.0", - "glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "example_wasm" +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "example_glium" version = "0.1.0" dependencies = [ - "egui 0.1.2", - "egui_web 0.1.0", - "js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)", + "egui 0.1.2 (git+https://github.com/emilk/emigui)", + "egui_glium 0.1.0 (git+https://github.com/emilk/emigui)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1681,6 +1727,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum dispatch 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" "checksum dlib 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b11f15d1e3268f140f68d390637d5e76d849782d971ae7063e0da69fe9709a76" "checksum downcast-rs 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +"checksum egui 0.1.2 (git+https://github.com/emilk/emigui)" = "" +"checksum egui_glium 0.1.0 (git+https://github.com/emilk/emigui)" = "" +"checksum egui_web 0.1.0 (git+https://github.com/emilk/emigui)" = "" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" diff --git a/Cargo.toml b/Cargo.toml index 42aeabf7b..94c392594 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,19 @@ [workspace] members = [ - "egui", + "demo_glium", "egui_glium", "egui_web", + "egui", "example_glium", - "example_wasm", + "demo_web", ] + +[patch.crates-io] +egui = { path = 'egui' } +egui_glium = { path = 'egui_glium' } +egui_web = { path = 'egui_web' } + [profile.release] # lto = true # VERY slightly smaller wasm # opt-level = 's' # 10-20% smaller wasm compared to `opt-level = 3` diff --git a/build_glium.sh b/build_glium.sh index b7a3eec2d..0277473bd 100755 --- a/build_glium.sh +++ b/build_glium.sh @@ -5,4 +5,4 @@ cargo fmt --all -- --check cargo check --all-features cargo clippy -cargo run --bin example_glium --release +cargo run --bin demo_glium --release diff --git a/build_web.sh b/build_web.sh index 36f8b39cc..fedacef2d 100755 --- a/build_web.sh +++ b/build_web.sh @@ -16,11 +16,11 @@ BUILD=release rm -rf docs/*.wasm echo "Build rust:" -cargo build --release -p example_wasm --target wasm32-unknown-unknown +cargo build --release -p demo_web --target wasm32-unknown-unknown echo "Generate JS bindings for wasm:" FOLDER_NAME=${PWD##*/} -TARGET_NAME="example_wasm.wasm" +TARGET_NAME="demo_web.wasm" wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \ --out-dir docs --no-modules --no-typescript diff --git a/demo_glium/Cargo.toml b/demo_glium/Cargo.toml new file mode 100644 index 000000000..31aafecc7 --- /dev/null +++ b/demo_glium/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "demo_glium" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2018" + +[dependencies] +egui = { git = "https://github.com/emilk/emigui", features = ["with_serde"] } +egui_glium = { git = "https://github.com/emilk/emigui" } +serde = { version = "1", features = ["derive"] } diff --git a/demo_glium/src/main.rs b/demo_glium/src/main.rs new file mode 100644 index 000000000..843a41dd7 --- /dev/null +++ b/demo_glium/src/main.rs @@ -0,0 +1,70 @@ +#![deny(warnings)] +#![warn(clippy::all)] + +use egui_glium::{persistence::Persistence, RunMode, Runner}; + +const APP_KEY: &str = "app"; + +#[derive(Default, serde::Deserialize, serde::Serialize)] +struct MyApp { + egui_demo_app: egui::DemoApp, + frames_painted: u64, +} + +impl egui_glium::App for MyApp { + fn ui(&mut self, ui: &mut egui::Ui, runner: &mut Runner) { + self.egui_demo_app.ui(ui, ""); + + use egui::*; + let mut ui = ui.centered_column(ui.available().width().min(480.0)); + ui.set_layout(Layout::vertical(Align::Min)); + ui.add(label!("Egui inside of Glium").text_style(TextStyle::Heading)); + if ui.add(Button::new("Quit")).clicked { + runner.quit(); + return; + } + + ui.add( + label!( + "CPU usage: {:.2} ms / frame (excludes painting)", + 1e3 * runner.cpu_time() + ) + .text_style(TextStyle::Monospace), + ); + + ui.separator(); + + ui.horizontal(|ui| { + let mut run_mode = runner.run_mode(); + ui.label("Run mode:"); + ui.radio_value("Continuous", &mut run_mode, RunMode::Continuous) + .tooltip_text("Repaint everything each frame"); + ui.radio_value("Reactive", &mut run_mode, RunMode::Reactive) + .tooltip_text("Repaint when there are animations or input (e.g. mouse movement)"); + runner.set_run_mode(run_mode); + }); + + if runner.run_mode() == RunMode::Continuous { + ui.add( + label!("Repainting the UI each frame. FPS: {:.1}", runner.fps()) + .text_style(TextStyle::Monospace), + ); + } else { + ui.label("Only running UI code when there are animations or input"); + } + + self.frames_painted += 1; + ui.label(format!("Total frames painted: {}", self.frames_painted)); + } + + fn on_exit(&mut self, persistence: &mut Persistence) { + persistence.set_value(APP_KEY, self); + } +} + +fn main() { + let title = "Egui glium demo"; + let persistence = Persistence::from_path(".egui_demo_glium.json".into()); + let app: MyApp = persistence.get_value(APP_KEY).unwrap_or_default(); + egui_glium::run(title, RunMode::Reactive, persistence, app); +} diff --git a/example_wasm/Cargo.toml b/demo_web/Cargo.toml similarity index 65% rename from example_wasm/Cargo.toml rename to demo_web/Cargo.toml index 8d892d1be..bb2c739d0 100644 --- a/example_wasm/Cargo.toml +++ b/demo_web/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "example_wasm" +name = "demo_web" version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" @@ -9,10 +9,9 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] +egui = { git = "https://github.com/emilk/emigui", features = ["with_serde"] } +egui_web = { git = "https://github.com/emilk/emigui" } js-sys = "0.3" serde = { version = "1", features = ["derive"] } serde_json = "1" wasm-bindgen = "0.2" - -egui = { path = "../egui" } -egui_web = { path = "../egui_web" } diff --git a/example_wasm/src/lib.rs b/demo_web/src/lib.rs similarity index 96% rename from example_wasm/src/lib.rs rename to demo_web/src/lib.rs index 79f98baa9..bf070136a 100644 --- a/example_wasm/src/lib.rs +++ b/demo_web/src/lib.rs @@ -21,7 +21,7 @@ pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { #[derive(Default)] pub struct MyApp { - example_app: egui::examples::ExampleApp, + demo_app: egui::demos::DemoApp, frames_painted: u64, } @@ -81,6 +81,6 @@ impl egui_web::App for MyApp { self.window_ui(ui, backend); }); - self.example_app.ui(ui, &info.web_location_hash); + self.demo_app.ui(ui, &info.web_location_hash); } } diff --git a/docs/example_wasm.js b/docs/demo_web.js similarity index 95% rename from docs/example_wasm.js rename to docs/demo_web.js index 9a7e50768..406a442d6 100644 --- a/docs/example_wasm.js +++ b/docs/demo_web.js @@ -207,26 +207,26 @@ function makeMutClosure(arg0, arg1, dtor, f) { real.original = state; return real; } -function __wbg_adapter_26(arg0, arg1) { - wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h84da5f062b972f09(arg0, arg1); -} - -function __wbg_adapter_29(arg0, arg1, arg2) { +function __wbg_adapter_26(arg0, arg1, arg2) { wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h22fd33d9f501a695(arg0, arg1, addHeapObject(arg2)); } -function __wbg_adapter_32(arg0, arg1, arg2) { +function __wbg_adapter_29(arg0, arg1, arg2) { wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h22fd33d9f501a695(arg0, arg1, addHeapObject(arg2)); } -function __wbg_adapter_35(arg0, arg1) { +function __wbg_adapter_32(arg0, arg1) { wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5402719cc6dde927(arg0, arg1); } -function __wbg_adapter_38(arg0, arg1, arg2) { +function __wbg_adapter_35(arg0, arg1, arg2) { wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h22fd33d9f501a695(arg0, arg1, addHeapObject(arg2)); } +function __wbg_adapter_38(arg0, arg1) { + wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h84da5f062b972f09(arg0, arg1); +} + function __wbg_adapter_41(arg0, arg1, arg2) { wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h22fd33d9f501a695(arg0, arg1, addHeapObject(arg2)); } @@ -423,14 +423,6 @@ async function init(input) { var ret = getObject(arg0) instanceof WebGLRenderingContext; return ret; }; - imports.wbg.__wbg_drawingBufferWidth_d15574dca0dbf918 = function(arg0) { - var ret = getObject(arg0).drawingBufferWidth; - return ret; - }; - imports.wbg.__wbg_drawingBufferHeight_64716b9e5a2d23f9 = function(arg0) { - var ret = getObject(arg0).drawingBufferHeight; - return ret; - }; imports.wbg.__wbg_bufferData_7c335d1d31ac7268 = function(arg0, arg1, arg2, arg3) { getObject(arg0).bufferData(arg1 >>> 0, getObject(arg2), arg3 >>> 0); }; @@ -725,28 +717,28 @@ async function init(input) { var ret = wasm.memory; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper381 = function(arg0, arg1, arg2) { - var ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_35); + imports.wbg.__wbindgen_closure_wrapper380 = function(arg0, arg1, arg2) { + var ret = makeMutClosure(arg0, arg1, 68, __wbg_adapter_26); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper385 = function(arg0, arg1, arg2) { - var ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_38); + imports.wbg.__wbindgen_closure_wrapper370 = function(arg0, arg1, arg2) { + var ret = makeMutClosure(arg0, arg1, 68, __wbg_adapter_32); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper382 = function(arg0, arg1, arg2) { - var ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_41); + imports.wbg.__wbindgen_closure_wrapper378 = function(arg0, arg1, arg2) { + var ret = makeMutClosure(arg0, arg1, 68, __wbg_adapter_41); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper387 = function(arg0, arg1, arg2) { - var ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_26); + imports.wbg.__wbindgen_closure_wrapper376 = function(arg0, arg1, arg2) { + var ret = makeMutClosure(arg0, arg1, 68, __wbg_adapter_38); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper389 = function(arg0, arg1, arg2) { - var ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_29); + imports.wbg.__wbindgen_closure_wrapper374 = function(arg0, arg1, arg2) { + var ret = makeMutClosure(arg0, arg1, 68, __wbg_adapter_35); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper391 = function(arg0, arg1, arg2) { - var ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_32); + imports.wbg.__wbindgen_closure_wrapper371 = function(arg0, arg1, arg2) { + var ret = makeMutClosure(arg0, arg1, 68, __wbg_adapter_29); return addHeapObject(ret); }; diff --git a/docs/example_wasm_bg.wasm b/docs/demo_web_bg.wasm similarity index 54% rename from docs/example_wasm_bg.wasm rename to docs/demo_web_bg.wasm index 9b3082a90..7faf71a0d 100644 Binary files a/docs/example_wasm_bg.wasm and b/docs/demo_web_bg.wasm differ diff --git a/docs/index.html b/docs/index.html index a57b4b962..d44c8e6ab 100644 --- a/docs/index.html +++ b/docs/index.html @@ -45,13 +45,13 @@ - +