mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
Store/restore emigui memory state (window positions, sizes etc)
This commit is contained in:
@@ -37,3 +37,30 @@ pub fn local_storage_set(key: &str, value: &str) {
|
||||
pub fn local_storage_remove(key: &str) {
|
||||
local_storage().map(|storage| storage.remove_item(key));
|
||||
}
|
||||
|
||||
pub fn load_memory(ctx: &emigui::Context) {
|
||||
if let Some(memory_string) = local_storage_get("emigui_memory_json") {
|
||||
match serde_json::from_str(&memory_string) {
|
||||
Ok(memory) => {
|
||||
*ctx.memory() = memory;
|
||||
}
|
||||
Err(err) => {
|
||||
console_log(format!("ERROR: Failed to parse memory json: {}", err));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_memory(ctx: &emigui::Context) {
|
||||
match serde_json::to_string(&*ctx.memory()) {
|
||||
Ok(json) => {
|
||||
local_storage_set("emigui_memory_json", &json);
|
||||
}
|
||||
Err(err) => {
|
||||
console_log(format!(
|
||||
"ERROR: Failed to seriealize memory as json: {}",
|
||||
err
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user