Browse Source

[refactor] rename 'example' to 'demo', and add simple example_glium

pull/9/head
Emil Ernerfeldt 4 years ago
parent
commit
61cdec8fca
  1. 79
      Cargo.lock
  2. 11
      Cargo.toml
  3. 2
      build_glium.sh
  4. 4
      build_web.sh
  5. 11
      demo_glium/Cargo.toml
  6. 70
      demo_glium/src/main.rs
  7. 7
      demo_web/Cargo.toml
  8. 4
      demo_web/src/lib.rs
  9. 48
      docs/demo_web.js
  10. BIN
      docs/demo_web_bg.wasm
  11. 4
      docs/index.html
  12. 6
      egui/benches/benchmark.rs
  13. 2
      egui/src/demos.rs
  14. 53
      egui/src/demos/app.rs
  15. 0
      egui/src/demos/fractal_clock.rs
  16. 4
      egui/src/input.rs
  17. 4
      egui/src/lib.rs
  18. 2
      egui_glium/src/lib.rs
  19. 6
      example_glium/Cargo.toml
  20. 64
      example_glium/src/main.rs

79
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)" = "<none>"
"checksum egui_glium 0.1.0 (git+https://github.com/emilk/emigui)" = "<none>"
"checksum egui_web 0.1.0 (git+https://github.com/emilk/emigui)" = "<none>"
"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"

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

2
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

4
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

11
demo_glium/Cargo.toml

@ -0,0 +1,11 @@
[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 = { git = "https://github.com/emilk/emigui", features = ["with_serde"] }
egui_glium = { git = "https://github.com/emilk/emigui" }
serde = { version = "1", features = ["derive"] }

70
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);
}

7
example_wasm/Cargo.toml → demo_web/Cargo.toml

@ -1,5 +1,5 @@
[package]
name = "example_wasm"
name = "demo_web"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
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" }

4
example_wasm/src/lib.rs → 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);
}
}

48
docs/example_wasm.js → 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);
};

BIN
docs/example_wasm_bg.wasm → docs/demo_web_bg.wasm

Binary file not shown.

4
docs/index.html

@ -45,13 +45,13 @@
</script>
<!-- this is the JS generated by the `wasm-bindgen` CLI tool -->
<script src="example_wasm.js"></script>
<script src="demo_web.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("./example_wasm_bg.wasm")
wasm_bindgen("./demo_web_bg.wasm")
.then(on_wasm_loaded)["catch"](console.error);
function on_wasm_loaded() {

6
egui/benches/benchmark.rs

@ -1,7 +1,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
pub fn criterion_benchmark(c: &mut Criterion) {
let mut example_app = egui::examples::ExampleApp::default();
let mut demo_app = egui::demos::DemoApp::default();
let mut ctx = egui::Context::new();
let raw_input = egui::RawInput {
@ -9,10 +9,10 @@ pub fn criterion_benchmark(c: &mut Criterion) {
..Default::default()
};
c.bench_function("example_app", |b| {
c.bench_function("demo_app", |b| {
b.iter(|| {
let mut ui = ctx.begin_frame(raw_input.clone());
example_app.ui(&mut ui, "");
demo_app.ui(&mut ui, "");
ctx.end_frame()
})
});

2
egui/src/examples.rs → egui/src/demos.rs

@ -2,6 +2,6 @@ mod app;
mod fractal_clock;
pub use {
app::{ExampleApp, ExampleWindow},
app::{DemoApp, DemoWindow},
fractal_clock::FractalClock,
};

53
egui/src/examples/app.rs → egui/src/demos/app.rs

@ -1,22 +1,20 @@
use std::sync::Arc;
use crate::{color::*, containers::*, examples::FractalClock, widgets::*, *};
use crate::{color::*, containers::*, demos::FractalClock, widgets::*, *};
// ----------------------------------------------------------------------------
#[derive(Default)]
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "with_serde", serde(default))]
pub struct ExampleApp {
pub struct DemoApp {
previous_web_location_hash: String,
open_windows: OpenWindows,
// TODO: group the following together as ExampleWindows
example_window: ExampleWindow,
demo_window: DemoWindow,
fractal_clock: FractalClock,
}
impl ExampleApp {
impl DemoApp {
/// `web_location_hash`: for web demo only. e.g. "#fragmet".
pub fn ui(&mut self, ui: &mut Ui, web_location_hash: &str) {
if self.previous_web_location_hash != web_location_hash {
@ -36,17 +34,17 @@ impl ExampleApp {
}
pub fn windows(&mut self, ctx: &Arc<Context>) {
let ExampleApp {
let DemoApp {
open_windows,
example_window,
demo_window,
fractal_clock,
..
} = self;
Window::new("Examples")
.open(&mut open_windows.examples)
Window::new("Demo")
.open(&mut open_windows.demo)
.show(ctx, |ui| {
example_window.ui(ui);
demo_window.ui(ui);
});
Window::new("Settings")
@ -76,8 +74,7 @@ impl ExampleApp {
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
struct OpenWindows {
// examples:
examples: bool,
demo: bool,
fractal_clock: bool,
// egui stuff:
@ -89,7 +86,7 @@ struct OpenWindows {
impl Default for OpenWindows {
fn default() -> Self {
Self {
examples: true,
demo: true,
..OpenWindows::none()
}
}
@ -98,7 +95,7 @@ impl Default for OpenWindows {
impl OpenWindows {
fn none() -> Self {
Self {
examples: false,
demo: false,
fractal_clock: false,
settings: false,
@ -116,7 +113,7 @@ fn show_menu_bar(ui: &mut Ui, windows: &mut OpenWindows) {
}
});
menu::menu(ui, "Windows", |ui| {
ui.add(Checkbox::new(&mut windows.examples, "Examples"));
ui.add(Checkbox::new(&mut windows.demo, "Demo"));
ui.add(Checkbox::new(&mut windows.fractal_clock, "Fractal Clock"));
ui.add(Separator::new());
ui.add(Checkbox::new(&mut windows.settings, "Settings"));
@ -152,31 +149,31 @@ fn show_menu_bar(ui: &mut Ui, windows: &mut OpenWindows) {
/// Showcase some ui code
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
pub struct ExampleWindow {
pub struct DemoWindow {
num_columns: usize,
widgets: Widgets,
layout: LayoutExample,
layout: LayoutDemo,
tree: Tree,
box_painting: BoxPainting,
painting: Painting,
}
impl Default for ExampleWindow {
fn default() -> ExampleWindow {
ExampleWindow {
impl Default for DemoWindow {
fn default() -> DemoWindow {
DemoWindow {
num_columns: 2,
widgets: Default::default(),
layout: Default::default(),
tree: Tree::example(),
tree: Tree::demo(),
box_painting: Default::default(),
painting: Default::default(),
}
}
}
impl ExampleWindow {
impl DemoWindow {
pub fn ui(&mut self, ui: &mut Ui) {
ui.collapsing("About Egui", |ui| {
ui.add(label!(
@ -238,7 +235,7 @@ impl ExampleWindow {
});
});
ui.collapsing("Name clash example", |ui| {
ui.collapsing("Name clash demo", |ui| {
ui.label("\
Widgets that store state require unique identifiers so we can track their state between frames. \
Identifiers are normally derived from the titles of the widget.");
@ -466,13 +463,13 @@ use crate::layout::*;
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "with_serde", serde(default))]
struct LayoutExample {
struct LayoutDemo {
dir: Direction,
align: Option<Align>, // None == jusitifed
reversed: bool,
}
impl Default for LayoutExample {
impl Default for LayoutDemo {
fn default() -> Self {
Self {
dir: Direction::Vertical,
@ -482,7 +479,7 @@ impl Default for LayoutExample {
}
}
impl LayoutExample {
impl LayoutDemo {
pub fn ui(&mut self, ui: &mut Ui) {
Resize::default()
.default_size([200.0, 100.0])
@ -555,7 +552,7 @@ enum Action {
struct Tree(Vec<Tree>);
impl Tree {
pub fn example() -> Self {
pub fn demo() -> Self {
Self(vec![
Tree(vec![Tree::default(); 4]),
Tree(vec![Tree(vec![Tree::default(); 2]); 3]),

0
egui/src/examples/fractal_clock.rs → egui/src/demos/fractal_clock.rs

4
egui/src/input.rs

@ -28,7 +28,7 @@ pub struct RawInput {
/// Time in seconds. Relative to whatever. Used for animation.
pub time: f64,
/// Local time. Only used for the clock in the example app.
/// Local time. Only used for the clock in the demo app.
pub seconds_since_midnight: Option<f64>,
/// In-order events received this frame
@ -78,7 +78,7 @@ pub struct InputState {
/// Can be used to fast-forward to next frame for instance feedback. hacky.
pub predicted_dt: f32,
/// Local time. Only used for the clock in the example app.
/// Local time. Only used for the clock in the demo app.
pub seconds_since_midnight: Option<f64>,
/// In-order events received this frame

4
egui/src/lib.rs

@ -24,7 +24,7 @@
pub mod containers;
mod context;
pub mod examples;
pub mod demos;
mod id;
mod input;
mod introspection;
@ -42,7 +42,7 @@ pub mod widgets;
pub use {
containers::*,
context::Context,
examples::ExampleApp,
demos::DemoApp,
id::Id,
input::*,
layers::*,

2
egui_glium/src/lib.rs

@ -216,7 +216,7 @@ pub fn init_clipboard() -> Option<ClipboardContext> {
// ----------------------------------------------------------------------------
/// Time of day as seconds since midnight. Used for clock in example app.
/// Time of day as seconds since midnight. Used for clock in demo app.
pub fn local_time_of_day() -> f64 {
use chrono::Timelike;
let time = chrono::Local::now().time();

6
example_glium/Cargo.toml

@ -6,8 +6,6 @@ license = "MIT OR Apache-2.0"
edition = "2018"
[dependencies]
egui = { path = "../egui", features = ["with_serde"] }
egui_glium = { path = "../egui_glium" }
glium = "0.27"
egui = { git = "https://github.com/emilk/emigui" }
egui_glium = { git = "https://github.com/emilk/emigui" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

64
example_glium/src/main.rs

@ -1,70 +1,34 @@
#![deny(warnings)]
#![warn(clippy::all)]
use egui_glium::{persistence::Persistence, RunMode, Runner};
const APP_KEY: &str = "app";
/// We dervive Deserialize/Serialize so we can persist app state on shutdown.
#[derive(Default, serde::Deserialize, serde::Serialize)]
struct MyApp {
egui_example_app: egui::ExampleApp,
frames_painted: u64,
counter: u64,
}
impl egui_glium::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, runner: &mut Runner) {
self.egui_example_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;
/// This function will be called whenever the Ui needs to be shown,
/// which may be many times per second.
fn ui(&mut self, ui: &mut egui::Ui, _: &mut Runner) {
if ui.button("Increment").clicked {
self.counter += 1;
}
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");
if ui.button("Reset").clicked {
self.counter = 0;
}
self.frames_painted += 1;
ui.label(format!("Total frames painted: {}", self.frames_painted));
ui.label(format!("Counter: {}", self.counter));
}
fn on_exit(&mut self, persistence: &mut Persistence) {
persistence.set_value(APP_KEY, self);
persistence.set_value(APP_KEY, self); // Save app state
}
}
fn main() {
let title = "Egui glium example";
let persistence = Persistence::from_path(".egui_example_glium.json".into());
let app: MyApp = persistence.get_value(APP_KEY).unwrap_or_default();
let title = "My Egui Window";
let persistence = Persistence::from_path(".egui_example_glium.json".into()); // Where to persist app state
let app: MyApp = persistence.get_value(APP_KEY).unwrap_or_default(); // Restore `MyApp` from file, or create new `MyApp`.
egui_glium::run(title, RunMode::Reactive, persistence, app);
}

Loading…
Cancel
Save