Browse Source

Use `instant` crate in egui-winit for WebAssembly support (#1023)

* Replace `std::time::Instant` with wasm-compatible `instant::Instant`

* Change version requirement for instant to be compatible to winit

* Enable wasm-bindgen feature for instant

* Update lockfile

* Update changelog

* sort dependencies

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
pull/1043/head
Niklas Korz 3 years ago
committed by GitHub
parent
commit
01015ac94c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Cargo.lock
  2. 1
      egui-winit/CHANGELOG.md
  3. 1
      egui-winit/Cargo.toml
  4. 10
      egui-winit/src/epi.rs
  5. 4
      egui-winit/src/lib.rs

1
Cargo.lock

@ -806,6 +806,7 @@ dependencies = [
"copypasta",
"egui",
"epi",
"instant",
"serde",
"tts",
"webbrowser",

1
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

1
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 }

10
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<Box<dyn epi::Storage>>,
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<egui::epaint::ClippedShape>,
) {
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)

4
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<egui::Pos2>,
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()

Loading…
Cancel
Save