Browse Source

Merge pull request #70 from emilk/framework

Combine demo_glium and demo_web into one egui_demo crate
pull/77/head
Emil Ernerfeldt 4 years ago
committed by GitHub
parent
commit
58c025a7e3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .github/workflows/rust.yml
  2. 1
      .gitignore
  3. 33
      Cargo.lock
  4. 4
      Cargo.toml
  5. 4
      build_demo_native.sh
  6. 26
      build_demo_web.sh
  7. 26
      build_example_web.sh
  8. 4
      build_glium.sh
  9. 8
      check.sh
  10. 11
      demo_glium/Cargo.toml
  11. 50
      docs/egui_demo.js
  12. BIN
      docs/egui_demo_bg.wasm
  13. 4
      docs/index.html
  14. 12
      egui_demo/Cargo.toml
  15. 2
      egui_demo/src/lib.rs
  16. 1
      egui_demo/src/main.rs
  17. 2
      egui_web/README.md
  18. 3
      example_web/README.md
  19. 7
      setup_web.sh

6
.github/workflows/rust.yml

@ -20,8 +20,8 @@ jobs:
with:
command: check
check_demo_web:
name: Check demo_web
check_egui_demo_web:
name: Check egui_demo (web)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@ -34,7 +34,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check
args: -p demo_web --target wasm32-unknown-unknown
args: -p egui_demo --lib --target wasm32-unknown-unknown
test:
name: Test Suite

1
.gitignore

@ -1,3 +1,4 @@
**/target
/.*.json
/.vscode
/media/*

33
Cargo.lock

@ -521,27 +521,6 @@ dependencies = [
"byteorder",
]
[[package]]
name = "demo_glium"
version = "0.1.0"
dependencies = [
"egui",
"egui_glium",
"serde",
]
[[package]]
name = "demo_web"
version = "0.1.0"
dependencies = [
"egui",
"egui_web",
"js-sys",
"serde",
"serde_json",
"wasm-bindgen",
]
[[package]]
name = "derivative"
version = "2.1.1"
@ -607,6 +586,18 @@ dependencies = [
"serde_json",
]
[[package]]
name = "egui_demo"
version = "0.1.0"
dependencies = [
"egui",
"egui_glium",
"egui_web",
"js-sys",
"serde",
"wasm-bindgen",
]
[[package]]
name = "egui_glium"
version = "0.5.0"

4
Cargo.toml

@ -1,14 +1,12 @@
[workspace]
members = [
"demo_glium",
"demo_web",
"egui_demo",
"egui_glium",
"egui_web",
"egui",
"example_web",
]
[patch.crates-io]
egui = { path = 'egui' }
egui_glium = { path = 'egui_glium' }

4
build_demo_native.sh

@ -0,0 +1,4 @@
#!/bin/bash
set -eu
cargo run --bin egui_demo --release

26
build_demo_web.sh

@ -1,30 +1,22 @@
#!/bin/bash
set -eu
# Pre-requisites:
rustup target add wasm32-unknown-unknown
if ! wasm-bindgen --version; then
cargo clean
cargo install -f wasm-bindgen-cli
cargo update
fi
# BUILD=debug
BUILD=release
CRATE_NAME="egui_demo"
export RUSTFLAGS=--cfg=web_sys_unstable_apis # required for the clipboard API
# Clear output from old stuff:
rm -rf docs/demo_web.wasm
rm -rf docs/$CRATE_NAME.wasm
echo "Build rust:"
# cargo build -p demo_web --target wasm32-unknown-unknown
cargo build --release -p demo_web --target wasm32-unknown-unknown
echo "Building rust…"
BUILD=release
cargo build --release -p $CRATE_NAME --lib --target wasm32-unknown-unknown
echo "Generate JS bindings for wasm:"
FOLDER_NAME=${PWD##*/}
TARGET_NAME="demo_web.wasm"
echo "Generating JS bindings for wasm…"
TARGET_NAME="$CRATE_NAME.wasm"
wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
--out-dir docs --no-modules --no-typescript
echo "Finished: docs/$CRATE_NAME.wasm"
open http://localhost:8888/index.html

26
build_example_web.sh

@ -1,30 +1,22 @@
#!/bin/bash
set -eu
# Pre-requisites:
rustup target add wasm32-unknown-unknown
if ! wasm-bindgen --version; then
cargo clean
cargo install -f wasm-bindgen-cli
cargo update
fi
# BUILD=debug
BUILD=release
CRATE_NAME="example_web"
export RUSTFLAGS=--cfg=web_sys_unstable_apis # required for the clipboard API
# Clear output from old stuff:
rm -rf docs/example_web.wasm
rm -rf docs/$CRATE_NAME.wasm
echo "Build rust:"
# cargo build -p example_web --target wasm32-unknown-unknown
cargo build --release -p example_web --target wasm32-unknown-unknown
echo "Building rust…"
BUILD=release
cargo build --release -p $CRATE_NAME --lib --target wasm32-unknown-unknown
echo "Generate JS bindings for wasm:"
FOLDER_NAME=${PWD##*/}
TARGET_NAME="example_web.wasm"
echo "Generating JS bindings for wasm…"
TARGET_NAME="$CRATE_NAME.wasm"
wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
--out-dir docs --no-modules --no-typescript
echo "Finished: docs/$CRATE_NAME.wasm"
open http://localhost:8888/example.html

4
build_glium.sh

@ -1,4 +0,0 @@
#!/bin/bash
set -eu
cargo run --bin demo_glium --release

8
check.sh

@ -9,10 +9,10 @@ CARGO_INCREMENTAL=0 cargo clippy --workspace --all-targets --all-features -- -D
cargo test --workspace --all-targets --all-features
cargo test --workspace --doc
cargo check -p egui --target wasm32-unknown-unknown
cargo check -p egui_web --target wasm32-unknown-unknown
cargo check -p demo_web --target wasm32-unknown-unknown
cargo check -p example_web --target wasm32-unknown-unknown
cargo check -p egui --lib --target wasm32-unknown-unknown
cargo check -p egui_web --lib --target wasm32-unknown-unknown
cargo check -p egui_demo --lib --target wasm32-unknown-unknown
cargo check -p example_web --lib --target wasm32-unknown-unknown
# For finding bloat:
# cargo bloat --release --bin demo_glium -n 200 | rg egui

11
demo_glium/Cargo.toml

@ -1,11 +0,0 @@
[package]
name = "demo_glium"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2018"
[dependencies]
egui = { path = "../egui", features = ["serde", "serde_json"] }
egui_glium = { path = "../egui_glium" }
serde = { version = "1", features = ["derive"] }

50
docs/demo_web.js → docs/egui_demo.js

@ -213,35 +213,35 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_24(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf85506f45f4e8b16(arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h81f03ee2d784e177(arg0, arg1);
}
function __wbg_adapter_27(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_30(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_33(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_36(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf802d845e8b4a07b(arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hcb627f1d4e0d7728(arg0, arg1);
}
function __wbg_adapter_39(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_42(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}
function __wbg_adapter_45(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf01ebeadb2908509(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h49f53e48165122c2(arg0, arg1, addHeapObject(arg2));
}
/**
@ -604,8 +604,8 @@ async function init(input) {
imports.wbg.__wbg_viewport_54305c74f5668b33 = function(arg0, arg1, arg2, arg3, arg4) {
getObject(arg0).viewport(arg1, arg2, arg3, arg4);
};
imports.wbg.__wbg_log_f2e13ca55da8bad3 = function(arg0) {
console.log(getObject(arg0));
imports.wbg.__wbg_error_e325755affc8634b = function(arg0) {
console.error(getObject(arg0));
};
imports.wbg.__wbg_warn_9e92ccdc67085e1b = function(arg0) {
console.warn(getObject(arg0));
@ -795,35 +795,35 @@ async function init(input) {
var ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper434 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_24);
imports.wbg.__wbindgen_closure_wrapper308 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_24);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper435 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_27);
imports.wbg.__wbindgen_closure_wrapper309 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_27);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper438 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_30);
imports.wbg.__wbindgen_closure_wrapper311 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_30);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper440 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_33);
imports.wbg.__wbindgen_closure_wrapper313 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_33);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper442 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_36);
imports.wbg.__wbindgen_closure_wrapper315 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_36);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper444 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_39);
imports.wbg.__wbindgen_closure_wrapper317 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_39);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper446 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_42);
imports.wbg.__wbindgen_closure_wrapper320 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_42);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper521 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper499 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 128, __wbg_adapter_45);
return addHeapObject(ret);
};

BIN
docs/demo_web_bg.wasm → docs/egui_demo_bg.wasm

Binary file not shown.

4
docs/index.html

@ -56,13 +56,13 @@
</script>
<!-- this is the JS generated by the `wasm-bindgen` CLI tool -->
<script src="demo_web.js"></script>
<script src="egui_demo.js"></script>
<script>
// We'll defer our execution until the wasm is ready to go.
// Here we tell bindgen the path to the wasm file so it can start
// initialization and return to us a promise when it's done.
wasm_bindgen("./demo_web_bg.wasm")
wasm_bindgen("./egui_demo_bg.wasm")
.then(on_wasm_loaded)["catch"](console.error);
function on_wasm_loaded() {

12
demo_web/Cargo.toml → egui_demo/Cargo.toml

@ -1,5 +1,5 @@
[package]
name = "demo_web"
name = "egui_demo"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
@ -10,8 +10,14 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
egui = { path = "../egui", features = ["serde", "serde_json"] }
serde = { version = "1", features = ["derive"] }
# For compiling natively:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui_glium = { path = "../egui_glium" }
# For compiling to web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
egui_web = { path = "../egui_web" }
js-sys = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
wasm-bindgen = "0.2"

2
demo_web/src/lib.rs → egui_demo/src/lib.rs

@ -2,12 +2,14 @@
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
#![warn(clippy::all)]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
/// This is the entry-point for all the web-assembly.
/// This is called once from the HTML.
/// It loads the app, installs some callbacks, then returns.
/// You can add more callbacks like this if you want to call in to your code.
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
let app = egui::DemoApp::default();

1
demo_glium/src/main.rs → egui_demo/src/main.rs

@ -2,6 +2,7 @@
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
#![warn(clippy::all)]
// When compiling natively:
fn main() {
let app = egui::DemoApp::default();
egui_glium::run(Box::new(app));

2
egui_web/README.md

@ -7,6 +7,6 @@
This crates allows you to compile GUI code written with [Egui](https://crates.io/crates/egui) to [WASM](https://en.wikipedia.org/wiki/WebAssembly) to run on a web page.
Check out [docs/index.html](https://github.com/emilk/egui/blob/master/docs/index.html), [demo_web](https://github.com/emilk/egui/tree/master/demo_web) and [build_web.sh](https://github.com/emilk/egui/blob/master/build_web.sh) for examples of how to set it up.
Check out [docs/index.html](https://github.com/emilk/egui/blob/master/docs/index.html), [egui_demo](https://github.com/emilk/egui/tree/master/egui_demo) and [build_web.sh](https://github.com/emilk/egui/blob/master/build_web.sh) for examples of how to set it up.
To use `egui_web`, you need to set the `RUSTFLAGS=--cfg=web_sys_unstable_apis` flag.

3
example_web/README.md

@ -0,0 +1,3 @@
# egui_web fetch example
This is an example of how to write a web-app which use the fetch API.

7
setup_web.sh

@ -0,0 +1,7 @@
#!/bin/bash
set -eu
# Pre-requisites:
rustup target add wasm32-unknown-unknown
cargo install -f wasm-bindgen-cli
cargo update
Loading…
Cancel
Save