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>
This commit is contained in:
parent
b1fd6a44e8
commit
01015ac94c
5 changed files with 10 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -806,6 +806,7 @@ dependencies = [
|
||||||
"copypasta",
|
"copypasta",
|
||||||
"egui",
|
"egui",
|
||||||
"epi",
|
"epi",
|
||||||
|
"instant",
|
||||||
"serde",
|
"serde",
|
||||||
"tts",
|
"tts",
|
||||||
"webbrowser",
|
"webbrowser",
|
||||||
|
|
|
@ -4,6 +4,7 @@ All notable changes to the `egui-winit` integration will be noted in this file.
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## 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
|
## 0.16.0 - 2021-12-29
|
||||||
|
|
|
@ -23,6 +23,7 @@ all-features = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.16.0", path = "../egui", default-features = false, features = ["single_threaded"] }
|
egui = { version = "0.16.0", path = "../egui", default-features = false, features = ["single_threaded"] }
|
||||||
|
instant = { version = "0.1", features = ["wasm-bindgen"] }
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
|
|
||||||
epi = { version = "0.16.0", path = "../epi", optional = true }
|
epi = { version = "0.16.0", path = "../epi", optional = true }
|
||||||
|
|
|
@ -95,7 +95,7 @@ pub fn handle_app_output(
|
||||||
/// For loading/saving app state and/or egui memory to disk.
|
/// For loading/saving app state and/or egui memory to disk.
|
||||||
pub struct Persistence {
|
pub struct Persistence {
|
||||||
storage: Option<Box<dyn epi::Storage>>,
|
storage: Option<Box<dyn epi::Storage>>,
|
||||||
last_auto_save: std::time::Instant,
|
last_auto_save: instant::Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::unused_self)]
|
#[allow(clippy::unused_self)]
|
||||||
|
@ -116,7 +116,7 @@ impl Persistence {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
storage: create_storage(app_name),
|
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,
|
egui_ctx: &egui::Context,
|
||||||
window: &winit::window::Window,
|
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() {
|
if now - self.last_auto_save > app.auto_save_interval() {
|
||||||
self.save(app, egui_ctx, window);
|
self.save(app, egui_ctx, window);
|
||||||
self.last_auto_save = now;
|
self.last_auto_save = now;
|
||||||
|
@ -278,7 +278,7 @@ impl EpiIntegration {
|
||||||
epi::backend::TexAllocationData,
|
epi::backend::TexAllocationData,
|
||||||
Vec<egui::epaint::ClippedShape>,
|
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 raw_input = self.egui_winit.take_egui_input(window);
|
||||||
let (egui_output, shapes) = self.egui_ctx.run(raw_input, |egui_ctx| {
|
let (egui_output, shapes) = self.egui_ctx.run(raw_input, |egui_ctx| {
|
||||||
|
@ -294,7 +294,7 @@ impl EpiIntegration {
|
||||||
let tex_allocation_data =
|
let tex_allocation_data =
|
||||||
crate::epi::handle_app_output(window, self.egui_ctx.pixels_per_point(), app_output);
|
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);
|
self.frame.lock().info.cpu_usage = Some(frame_time);
|
||||||
|
|
||||||
(needs_repaint, tex_allocation_data, shapes)
|
(needs_repaint, tex_allocation_data, shapes)
|
||||||
|
|
|
@ -105,7 +105,7 @@ pub fn screen_size_in_pixels(window: &winit::window::Window) -> egui::Vec2 {
|
||||||
|
|
||||||
/// Handles the integration between egui and winit.
|
/// Handles the integration between egui and winit.
|
||||||
pub struct State {
|
pub struct State {
|
||||||
start_time: std::time::Instant,
|
start_time: instant::Instant,
|
||||||
egui_input: egui::RawInput,
|
egui_input: egui::RawInput,
|
||||||
pointer_pos_in_points: Option<egui::Pos2>,
|
pointer_pos_in_points: Option<egui::Pos2>,
|
||||||
any_pointer_button_down: bool,
|
any_pointer_button_down: bool,
|
||||||
|
@ -137,7 +137,7 @@ impl State {
|
||||||
/// Initialize with a given dpi scaling.
|
/// Initialize with a given dpi scaling.
|
||||||
pub fn from_pixels_per_point(pixels_per_point: f32) -> Self {
|
pub fn from_pixels_per_point(pixels_per_point: f32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
start_time: std::time::Instant::now(),
|
start_time: instant::Instant::now(),
|
||||||
egui_input: egui::RawInput {
|
egui_input: egui::RawInput {
|
||||||
pixels_per_point: Some(pixels_per_point),
|
pixels_per_point: Some(pixels_per_point),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
Loading…
Reference in a new issue