Skip to content

Commit

Permalink
Update to Egui 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 26, 2020
1 parent fee20e6 commit e0cfa81
Show file tree
Hide file tree
Showing 8 changed files with 1,681 additions and 46 deletions.
1,609 changes: 1,609 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ edition = "2018"
crate-type = ["cdylib", "rlib"]

[dependencies]
egui = "0.5"
egui = "0.6"

# Gives us persistence. Remove if you do like.
serde = { version = "1", features = ["derive"] }

# For compiling natively:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui_glium = "0.5"
egui_glium = "0.6"

# For compiling to web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
egui_web = "0.5"
egui_web = "0.6"
js-sys = "0.3"
wasm-bindgen = "0.2"

[patch.crates-io]
egui = { git = "https://github.com/emilk/egui", rev = "58c025a7e3d509e93e8f525aa747af1c9bd3dcb1" } # 2020-12-19
egui_glium = { git = "https://github.com/emilk/egui", rev = "58c025a7e3d509e93e8f525aa747af1c9bd3dcb1" } # 2020-12-19
egui_web = { git = "https://github.com/emilk/egui", rev = "58c025a7e3d509e93e8f525aa747af1c9bd3dcb1" } # 2020-12-19
# [patch.crates-io]
# egui = { git = "https://github.com/emilk/egui", rev = "db3fdbe6d3c1b2baf9cb71445f8dbbf8aded0e29" } # 2020-12-26
# egui_glium = { git = "https://github.com/emilk/egui", rev = "db3fdbe6d3c1b2baf9cb71445f8dbbf8aded0e29" } # 2020-12-26
# egui_web = { git = "https://github.com/emilk/egui", rev = "db3fdbe6d3c1b2baf9cb71445f8dbbf8aded0e29" } # 2020-12-26

[profile.release]
opt-level = 2 # fast and small wasm
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Egui Template

[![dependency status](https://deps.rs/repo/github/emilk/egui_template/status.svg)](https://deps.rs/repo/github/emilk/egui_template)
[![Build Status](https://github.com/emilk/egui_template/workflows/CI/badge.svg)](https://github.com/emilk/egui_template/actions?workflow=CI)

This is a template repo for [Egui](https://github.com/emilk/egui/).

The goal is for this to be the simplest way to get started writing a GUI app in Rust.
Expand Down Expand Up @@ -39,6 +42,8 @@ The finished we app is found in the `docs/` folder (this is so that you can easi
* `your_crate_bg.wasm`: What the Rust code compiles to.
* `your_crate.js`: Auto-generated binding between Rust and JS.

You can test the template app at <https://emilk.github.io/egui_template/>.

## Updating Egui

As of 2020, Egui is in active development with frequent releases with breaking changes. When updating Egui, update the version string in `Cargo.toml` of `egui`, `egui_glium` and `egui_web` (they should match). You can also check out the [egui_template](https://github.com/emilk/egui_template/) repository to see what changes has happened to it.
13 changes: 8 additions & 5 deletions build_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ set -eu
FOLDER_NAME=${PWD##*/}
CRATE_NAME=$FOLDER_NAME # assume crate name is the same as the folder name

export RUSTFLAGS=--cfg=web_sys_unstable_apis # required for the clipboard API
# This is required to enable the web_sys clipboard API
# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
export RUSTFLAGS=--cfg=web_sys_unstable_apis

# Clear output from old stuff:
rm -rf docs/$CRATE_NAME.wasm
rm -f docs/${CRATE_NAME}_bg.wasm

echo "Building rust…"
BUILD=release
cargo build --release -p $CRATE_NAME --lib --target wasm32-unknown-unknown
cargo build --release -p ${CRATE_NAME} --lib --target wasm32-unknown-unknown

echo "Generating JS bindings for wasm…"
TARGET_NAME="$CRATE_NAME.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"
echo "Finished: docs/${CRATE_NAME}.wasm"
16 changes: 16 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# This scripts runs various CI-like checks in a convenient way.
set -eu

# This is required to enable the web_sys clipboard API
# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
export RUSTFLAGS=--cfg=web_sys_unstable_apis

cargo check --workspace --all-targets --all-features --release
cargo fmt --all -- --check
CARGO_INCREMENTAL=0 cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::all
cargo test --workspace --all-targets --all-features
cargo test --workspace --doc

cargo check --lib --target wasm32-unknown-unknown
52 changes: 26 additions & 26 deletions docs/egui_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__h3ffe8afa46a512ea(arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h988072f39a58fed1(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__h61a9738176591bc0(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4df5c9cb8ec7a36b(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__h61a9738176591bc0(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4df5c9cb8ec7a36b(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__h61a9738176591bc0(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4df5c9cb8ec7a36b(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_36(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h61a9738176591bc0(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__hffbede504231339c(arg0, arg1);
}

function __wbg_adapter_39(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h21a8ad866b381ebb(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__h4df5c9cb8ec7a36b(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__h61a9738176591bc0(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4df5c9cb8ec7a36b(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__h49f53e48165122c2(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h744b8682ee5edacd(arg0, arg1, addHeapObject(arg2));
}

/**
Expand Down Expand Up @@ -795,36 +795,36 @@ async function init(input) {
var ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper411 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 85, __wbg_adapter_24);
imports.wbg.__wbindgen_closure_wrapper426 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 86, __wbg_adapter_24);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper412 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 85, __wbg_adapter_27);
imports.wbg.__wbindgen_closure_wrapper427 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 86, __wbg_adapter_27);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper414 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 85, __wbg_adapter_30);
imports.wbg.__wbindgen_closure_wrapper430 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 86, __wbg_adapter_30);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper416 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 85, __wbg_adapter_33);
imports.wbg.__wbindgen_closure_wrapper432 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 86, __wbg_adapter_33);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper418 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 85, __wbg_adapter_36);
imports.wbg.__wbindgen_closure_wrapper434 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 86, __wbg_adapter_36);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper420 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 85, __wbg_adapter_39);
imports.wbg.__wbindgen_closure_wrapper436 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 86, __wbg_adapter_39);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper423 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 85, __wbg_adapter_42);
imports.wbg.__wbindgen_closure_wrapper438 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 86, __wbg_adapter_42);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper602 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 152, __wbg_adapter_45);
imports.wbg.__wbindgen_closure_wrapper603 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 153, __wbg_adapter_45);
return addHeapObject(ret);
};

Expand Down
Binary file modified docs/egui_template_bg.wasm
Binary file not shown.
18 changes: 10 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl egui::app::App for EguiApp {
painting,
} = self;

// Examples of how to create differens panels and windows.
// Examples of how to create different panels and windows.
// Pick whichever suits you.
// Tip: a good default choice is to just keep the `CentralPanel`.
// For inspiration and more examples, go to https://emilk.github.io/egui
Expand Down Expand Up @@ -133,21 +133,21 @@ impl Default for Painting {
}

impl Painting {
pub fn ui_control(&mut self, ui: &mut egui::Ui) {
pub fn ui_control(&mut self, ui: &mut egui::Ui) -> egui::Response {
ui.horizontal(|ui| {
self.stroke.ui(ui, "Stroke");
ui.separator();
if ui.button("Clear Painting").clicked {
self.lines.clear();
}
});
})
.1
}

pub fn ui_content(&mut self, ui: &mut egui::Ui) {
let painter = ui.allocate_painter(ui.available_size_before_wrap_finite());
let rect = painter.clip_rect();
let id = ui.make_position_id();
let response = ui.interact(rect, id, egui::Sense::drag());
pub fn ui_content(&mut self, ui: &mut egui::Ui) -> egui::Response {
let (response, painter) =
ui.allocate_painter(ui.available_size_before_wrap_finite(), egui::Sense::drag());
let rect = response.rect;

if self.lines.is_empty() {
self.lines.push(vec![]);
Expand All @@ -172,5 +172,7 @@ impl Painting {
painter.add(egui::PaintCmd::line(points, self.stroke));
}
}

response
}
}

0 comments on commit e0cfa81

Please sign in to comment.