File tree 5 files changed +42
-15
lines changed
5 files changed +42
-15
lines changed Original file line number Diff line number Diff line change 8
8
9
9
#[ cfg( target_arch = "wasm32" ) ]
10
10
use std:: any:: Any ;
11
+ use std:: path:: PathBuf ;
11
12
12
13
#[ cfg( not( target_arch = "wasm32" ) ) ]
13
14
#[ cfg( any( feature = "glow" , feature = "wgpu" ) ) ]
@@ -362,6 +363,8 @@ pub struct NativeOptions {
362
363
/// Controls whether or not the native window position and size will be
363
364
/// persisted (only if the "persistence" feature is enabled).
364
365
pub persist_window : bool ,
366
+
367
+ pub persistence_path : Option < std:: path:: PathBuf > ,
365
368
}
366
369
367
370
#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -379,6 +382,9 @@ impl Clone for NativeOptions {
379
382
#[ cfg( feature = "wgpu" ) ]
380
383
wgpu_options : self . wgpu_options . clone ( ) ,
381
384
385
+ #[ cfg( feature = "persistence" ) ]
386
+ persistence_path : self . persistence_path . clone ( ) ,
387
+
382
388
..* self
383
389
}
384
390
}
@@ -418,6 +424,9 @@ impl Default for NativeOptions {
418
424
wgpu_options : egui_wgpu:: WgpuConfiguration :: default ( ) ,
419
425
420
426
persist_window : true ,
427
+
428
+ #[ cfg( feature = "persistence" ) ]
429
+ persistence_path : None ,
421
430
}
422
431
}
423
432
}
Original file line number Diff line number Diff line change 1
1
//! Common tools used by [`super::glow_integration`] and [`super::wgpu_integration`].
2
2
3
3
use web_time:: Instant ;
4
+
5
+ use std:: path:: PathBuf ;
4
6
use winit:: event_loop:: EventLoopWindowTarget ;
5
7
6
8
use raw_window_handle:: { HasDisplayHandle as _, HasWindowHandle as _} ;
@@ -129,6 +131,14 @@ pub fn create_storage(_app_name: &str) -> Option<Box<dyn epi::Storage>> {
129
131
None
130
132
}
131
133
134
+ pub fn create_storage_with_file ( file : impl Into < PathBuf > ) -> Option < Box < dyn epi:: Storage > > {
135
+ #[ cfg( feature = "persistence" ) ]
136
+ return Some ( Box :: new (
137
+ super :: file_storage:: FileStorage :: from_ron_filepath ( file) ,
138
+ ) ) ;
139
+ None
140
+ }
141
+
132
142
// ----------------------------------------------------------------------------
133
143
134
144
/// Everything needed to make a winit-based integration for [`epi`].
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ impl Drop for FileStorage {
41
41
42
42
impl FileStorage {
43
43
/// Store the state in this .ron file.
44
- fn from_ron_filepath ( ron_filepath : impl Into < PathBuf > ) -> Self {
44
+ pub ( crate ) fn from_ron_filepath ( ron_filepath : impl Into < PathBuf > ) -> Self {
45
45
crate :: profile_function!( ) ;
46
46
let ron_filepath: PathBuf = ron_filepath. into ( ) ;
47
47
log:: debug!( "Loading app state from {:?}…" , ron_filepath) ;
Original file line number Diff line number Diff line change @@ -195,13 +195,17 @@ impl GlowWinitApp {
195
195
) -> Result < & mut GlowWinitRunning > {
196
196
crate :: profile_function!( ) ;
197
197
198
- let storage = epi_integration:: create_storage (
199
- self . native_options
200
- . viewport
201
- . app_id
202
- . as_ref ( )
203
- . unwrap_or ( & self . app_name ) ,
204
- ) ;
198
+ let storage = if let Some ( file) = & self . native_options . persistence_path {
199
+ epi_integration:: create_storage_with_file ( file)
200
+ } else {
201
+ epi_integration:: create_storage (
202
+ self . native_options
203
+ . viewport
204
+ . app_id
205
+ . as_ref ( )
206
+ . unwrap_or ( & self . app_name ) ,
207
+ )
208
+ } ;
205
209
206
210
let egui_ctx = create_egui_context ( storage. as_deref ( ) ) ;
207
211
Original file line number Diff line number Diff line change @@ -420,13 +420,17 @@ impl WinitApp for WgpuWinitApp {
420
420
self . recreate_window ( event_loop, running) ;
421
421
running
422
422
} else {
423
- let storage = epi_integration:: create_storage (
424
- self . native_options
425
- . viewport
426
- . app_id
427
- . as_ref ( )
428
- . unwrap_or ( & self . app_name ) ,
429
- ) ;
423
+ let storage = if let Some ( file) = & self . native_options . persistence_path {
424
+ epi_integration:: create_storage_with_file ( file)
425
+ } else {
426
+ epi_integration:: create_storage (
427
+ self . native_options
428
+ . viewport
429
+ . app_id
430
+ . as_ref ( )
431
+ . unwrap_or ( & self . app_name ) ,
432
+ )
433
+ } ;
430
434
let egui_ctx = winit_integration:: create_egui_context ( storage. as_deref ( ) ) ;
431
435
let ( window, builder) = create_window (
432
436
& egui_ctx,
You can’t perform that action at this time.
0 commit comments