mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 21:00:03 -04:00
Add some helpful wrapper around web_sys
This commit is contained in:
@@ -8,26 +8,9 @@ edition = "2018"
|
||||
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',
|
||||
]
|
||||
|
||||
@@ -6,20 +6,15 @@ extern crate wasm_bindgen;
|
||||
extern crate emigui;
|
||||
extern crate emigui_wasm;
|
||||
|
||||
use emigui::{label, widgets::Label, Align, Emigui, RawInput};
|
||||
use {
|
||||
emigui::{label, widgets::Label, Align, Emigui, RawInput},
|
||||
emigui_wasm::now_sec,
|
||||
};
|
||||
|
||||
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,
|
||||
@@ -39,7 +34,7 @@ impl State {
|
||||
}
|
||||
|
||||
fn run(&mut self, raw_input: RawInput) -> Result<(), JsValue> {
|
||||
let everything_start = now_ms();
|
||||
let everything_start = now_sec();
|
||||
|
||||
self.emigui.new_frame(raw_input);
|
||||
|
||||
@@ -60,7 +55,7 @@ impl State {
|
||||
self.webgl_painter
|
||||
.paint(&frame, self.emigui.texture(), raw_input.pixels_per_point);
|
||||
|
||||
self.everything_ms = now_ms() - everything_start;
|
||||
self.everything_ms = 1000.0 * (now_sec() - everything_start);
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user