diff --git a/Cargo.lock b/Cargo.lock index b120706b..a81728d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,6 +806,7 @@ dependencies = [ "copypasta", "egui", "epi", + "instant", "serde", "tts", "webbrowser", diff --git a/egui-winit/CHANGELOG.md b/egui-winit/CHANGELOG.md index 4a8a3daa..e2eb6621 100644 --- a/egui-winit/CHANGELOG.md +++ b/egui-winit/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to the `egui-winit` integration will be noted in this file. ## Unreleased +* Replaced `std::time::Instant` with `instant::Instant` for WebAssembly compatability ([#1023](https://github.com/emilk/egui/pull/1023)) ## 0.16.0 - 2021-12-29 diff --git a/egui-winit/Cargo.toml b/egui-winit/Cargo.toml index 2825aeec..917a3ae5 100644 --- a/egui-winit/Cargo.toml +++ b/egui-winit/Cargo.toml @@ -23,6 +23,7 @@ all-features = true [dependencies] egui = { version = "0.16.0", path = "../egui", default-features = false, features = ["single_threaded"] } +instant = { version = "0.1", features = ["wasm-bindgen"] } winit = "0.26" epi = { version = "0.16.0", path = "../epi", optional = true } diff --git a/egui-winit/src/epi.rs b/egui-winit/src/epi.rs index bbd82d3d..badea97a 100644 --- a/egui-winit/src/epi.rs +++ b/egui-winit/src/epi.rs @@ -95,7 +95,7 @@ pub fn handle_app_output( /// For loading/saving app state and/or egui memory to disk. pub struct Persistence { storage: Option>, - last_auto_save: std::time::Instant, + last_auto_save: instant::Instant, } #[allow(clippy::unused_self)] @@ -116,7 +116,7 @@ impl Persistence { Self { storage: create_storage(app_name), - last_auto_save: std::time::Instant::now(), + last_auto_save: instant::Instant::now(), } } @@ -177,7 +177,7 @@ impl Persistence { egui_ctx: &egui::Context, window: &winit::window::Window, ) { - let now = std::time::Instant::now(); + let now = instant::Instant::now(); if now - self.last_auto_save > app.auto_save_interval() { self.save(app, egui_ctx, window); self.last_auto_save = now; @@ -278,7 +278,7 @@ impl EpiIntegration { epi::backend::TexAllocationData, Vec, ) { - let frame_start = std::time::Instant::now(); + let frame_start = instant::Instant::now(); let raw_input = self.egui_winit.take_egui_input(window); let (egui_output, shapes) = self.egui_ctx.run(raw_input, |egui_ctx| { @@ -294,7 +294,7 @@ impl EpiIntegration { let tex_allocation_data = crate::epi::handle_app_output(window, self.egui_ctx.pixels_per_point(), app_output); - let frame_time = (std::time::Instant::now() - frame_start).as_secs_f64() as f32; + let frame_time = (instant::Instant::now() - frame_start).as_secs_f64() as f32; self.frame.lock().info.cpu_usage = Some(frame_time); (needs_repaint, tex_allocation_data, shapes) diff --git a/egui-winit/src/lib.rs b/egui-winit/src/lib.rs index 473e2d17..a3288954 100644 --- a/egui-winit/src/lib.rs +++ b/egui-winit/src/lib.rs @@ -105,7 +105,7 @@ pub fn screen_size_in_pixels(window: &winit::window::Window) -> egui::Vec2 { /// Handles the integration between egui and winit. pub struct State { - start_time: std::time::Instant, + start_time: instant::Instant, egui_input: egui::RawInput, pointer_pos_in_points: Option, any_pointer_button_down: bool, @@ -137,7 +137,7 @@ impl State { /// Initialize with a given dpi scaling. pub fn from_pixels_per_point(pixels_per_point: f32) -> Self { Self { - start_time: std::time::Instant::now(), + start_time: instant::Instant::now(), egui_input: egui::RawInput { pixels_per_point: Some(pixels_per_point), ..Default::default()