mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Add separate serialize feature and better persitence control (#753)
* Rename epaint feature "persistence" to "serialize" * Add separate "serialize" feature to egui * egui_demo_lib: separate serialize and persistence features * Add App::persist_native_window and App::persist_egui_memory Controls what gets persisted
This commit is contained in:
@@ -361,12 +361,16 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: &epi::NativeOptions) {
|
||||
if let Some(storage) = &mut storage {
|
||||
let now = Instant::now();
|
||||
if now - last_auto_save > app.auto_save_interval() {
|
||||
epi::set_value(
|
||||
storage.as_mut(),
|
||||
WINDOW_KEY,
|
||||
&WindowSettings::from_display(&display),
|
||||
);
|
||||
epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*egui.ctx().memory());
|
||||
if app.persist_native_window() {
|
||||
epi::set_value(
|
||||
storage.as_mut(),
|
||||
WINDOW_KEY,
|
||||
&WindowSettings::from_display(&display),
|
||||
);
|
||||
}
|
||||
if app.persist_egui_memory() {
|
||||
epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*egui.ctx().memory());
|
||||
}
|
||||
app.save(storage.as_mut());
|
||||
storage.flush();
|
||||
last_auto_save = now;
|
||||
@@ -379,12 +383,16 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: &epi::NativeOptions) {
|
||||
|
||||
#[cfg(feature = "persistence")]
|
||||
if let Some(storage) = &mut storage {
|
||||
epi::set_value(
|
||||
storage.as_mut(),
|
||||
WINDOW_KEY,
|
||||
&WindowSettings::from_display(&display),
|
||||
);
|
||||
epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*egui.ctx().memory());
|
||||
if app.persist_native_window() {
|
||||
epi::set_value(
|
||||
storage.as_mut(),
|
||||
WINDOW_KEY,
|
||||
&WindowSettings::from_display(&display),
|
||||
);
|
||||
}
|
||||
if app.persist_egui_memory() {
|
||||
epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*egui.ctx().memory());
|
||||
}
|
||||
app.save(storage.as_mut());
|
||||
storage.flush();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user