mirror of https://github.com/emilk/egui.git
Emil Ernerfeldt
6 years ago
11 changed files with 223 additions and 124 deletions
Binary file not shown.
Binary file not shown.
@ -1,79 +1,7 @@ |
|||||
#![deny(warnings)] |
#![deny(warnings)] |
||||
|
|
||||
extern crate serde_json; |
|
||||
extern crate wasm_bindgen; |
extern crate wasm_bindgen; |
||||
|
|
||||
extern crate emigui; |
extern crate emigui; |
||||
|
|
||||
use emigui::{label, widgets::Label, Align, Emigui, RawInput}; |
pub mod webgl; |
||||
|
|
||||
use wasm_bindgen::prelude::*; |
|
||||
|
|
||||
mod app; |
|
||||
mod webgl; |
|
||||
|
|
||||
fn now_ms() -> f64 { |
|
||||
web_sys::window() |
|
||||
.expect("should have a Window") |
|
||||
.performance() |
|
||||
.expect("should have a Performance") |
|
||||
.now() |
|
||||
} |
|
||||
|
|
||||
#[wasm_bindgen] |
|
||||
pub struct State { |
|
||||
app: app::App, |
|
||||
emigui: Emigui, |
|
||||
webgl_painter: webgl::Painter, |
|
||||
everything_ms: f64, |
|
||||
} |
|
||||
|
|
||||
impl State { |
|
||||
fn new(canvas_id: &str, pixels_per_point: f32) -> Result<State, JsValue> { |
|
||||
Ok(State { |
|
||||
app: Default::default(), |
|
||||
emigui: Emigui::new(pixels_per_point), |
|
||||
webgl_painter: webgl::Painter::new(canvas_id)?, |
|
||||
everything_ms: 0.0, |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
fn run(&mut self, raw_input: RawInput) -> Result<(), JsValue> { |
|
||||
let everything_start = now_ms(); |
|
||||
|
|
||||
self.emigui.new_frame(raw_input); |
|
||||
|
|
||||
let mut region = self.emigui.whole_screen_region(); |
|
||||
let mut region = region.centered_column(region.width().min(480.0), Align::Min); |
|
||||
self.app.show_gui(&mut region); |
|
||||
self.emigui.example(&mut region); |
|
||||
|
|
||||
region.add(label!("WebGl painter info:")); |
|
||||
region.indent(|region| { |
|
||||
region.add(label!(self.webgl_painter.debug_info())); |
|
||||
}); |
|
||||
|
|
||||
region.add(label!("Everything: {:.1} ms", self.everything_ms)); |
|
||||
|
|
||||
let frame = self.emigui.paint(); |
|
||||
let result = |
|
||||
self.webgl_painter |
|
||||
.paint(&frame, self.emigui.texture(), raw_input.pixels_per_point); |
|
||||
|
|
||||
self.everything_ms = now_ms() - everything_start; |
|
||||
|
|
||||
result |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
#[wasm_bindgen] |
|
||||
pub fn new_webgl_gui(canvas_id: &str, pixels_per_point: f32) -> Result<State, JsValue> { |
|
||||
State::new(canvas_id, pixels_per_point) |
|
||||
} |
|
||||
|
|
||||
#[wasm_bindgen] |
|
||||
pub fn run_gui(state: &mut State, raw_input_json: &str) -> Result<(), JsValue> { |
|
||||
// TODO: nicer interface than JSON
|
|
||||
let raw_input: RawInput = serde_json::from_str(raw_input_json).unwrap(); |
|
||||
state.run(raw_input) |
|
||||
} |
|
||||
|
@ -0,0 +1,33 @@ |
|||||
|
[package] |
||||
|
name = "example" |
||||
|
version = "0.1.0" |
||||
|
authors = ["Emil Ernerfeldt <emilernerfeldt@gmail.com>"] |
||||
|
edition = "2018" |
||||
|
|
||||
|
[lib] |
||||
|
crate-type = ["cdylib", "rlib"] |
||||
|
|
||||
|
[dependencies] |
||||
|
js-sys = "0.3" |
||||
|
serde = "1" |
||||
|
serde_json = "1" |
||||
|
wasm-bindgen = "0.2" |
||||
|
|
||||
|
emigui = { path = "../emigui" } |
||||
|
emigui_wasm = { path = "../emigui_wasm" } |
||||
|
|
||||
|
[dependencies.web-sys] |
||||
|
version = "0.3" |
||||
|
features = [ |
||||
|
'Document', |
||||
|
'Element', |
||||
|
'HtmlCanvasElement', |
||||
|
'Performance', |
||||
|
'WebGlBuffer', |
||||
|
'WebGlProgram', |
||||
|
'WebGlRenderingContext', |
||||
|
'WebGlShader', |
||||
|
'WebGlTexture', |
||||
|
'WebGlUniformLocation', |
||||
|
'Window', |
||||
|
] |
@ -0,0 +1,79 @@ |
|||||
|
#![deny(warnings)] |
||||
|
|
||||
|
extern crate serde_json; |
||||
|
extern crate wasm_bindgen; |
||||
|
|
||||
|
extern crate emigui; |
||||
|
extern crate emigui_wasm; |
||||
|
|
||||
|
use emigui::{label, widgets::Label, Align, Emigui, RawInput}; |
||||
|
|
||||
|
use wasm_bindgen::prelude::*; |
||||
|
|
||||
|
mod app; |
||||
|
|
||||
|
fn now_ms() -> f64 { |
||||
|
web_sys::window() |
||||
|
.expect("should have a Window") |
||||
|
.performance() |
||||
|
.expect("should have a Performance") |
||||
|
.now() |
||||
|
} |
||||
|
|
||||
|
#[wasm_bindgen] |
||||
|
pub struct State { |
||||
|
app: app::App, |
||||
|
emigui: Emigui, |
||||
|
webgl_painter: emigui_wasm::webgl::Painter, |
||||
|
everything_ms: f64, |
||||
|
} |
||||
|
|
||||
|
impl State { |
||||
|
fn new(canvas_id: &str, pixels_per_point: f32) -> Result<State, JsValue> { |
||||
|
Ok(State { |
||||
|
app: Default::default(), |
||||
|
emigui: Emigui::new(pixels_per_point), |
||||
|
webgl_painter: emigui_wasm::webgl::Painter::new(canvas_id)?, |
||||
|
everything_ms: 0.0, |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
fn run(&mut self, raw_input: RawInput) -> Result<(), JsValue> { |
||||
|
let everything_start = now_ms(); |
||||
|
|
||||
|
self.emigui.new_frame(raw_input); |
||||
|
|
||||
|
let mut region = self.emigui.whole_screen_region(); |
||||
|
let mut region = region.centered_column(region.width().min(480.0), Align::Min); |
||||
|
self.app.show_gui(&mut region); |
||||
|
self.emigui.example(&mut region); |
||||
|
|
||||
|
region.add(label!("WebGl painter info:")); |
||||
|
region.indent(|region| { |
||||
|
region.add(label!(self.webgl_painter.debug_info())); |
||||
|
}); |
||||
|
|
||||
|
region.add(label!("Everything: {:.1} ms", self.everything_ms)); |
||||
|
|
||||
|
let frame = self.emigui.paint(); |
||||
|
let result = |
||||
|
self.webgl_painter |
||||
|
.paint(&frame, self.emigui.texture(), raw_input.pixels_per_point); |
||||
|
|
||||
|
self.everything_ms = now_ms() - everything_start; |
||||
|
|
||||
|
result |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#[wasm_bindgen] |
||||
|
pub fn new_webgl_gui(canvas_id: &str, pixels_per_point: f32) -> Result<State, JsValue> { |
||||
|
State::new(canvas_id, pixels_per_point) |
||||
|
} |
||||
|
|
||||
|
#[wasm_bindgen] |
||||
|
pub fn run_gui(state: &mut State, raw_input_json: &str) -> Result<(), JsValue> { |
||||
|
// TODO: nicer interface than JSON
|
||||
|
let raw_input: RawInput = serde_json::from_str(raw_input_json).unwrap(); |
||||
|
state.run(raw_input) |
||||
|
} |
Loading…
Reference in new issue