1
0
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:
Emil Ernerfeldt
2020-05-02 11:37:12 +02:00
parent d52cccde7b
commit bfbb669d02
19 changed files with 154 additions and 60 deletions

View File

@@ -165,3 +165,32 @@ pub fn handle_output(
.gl_window()
.set_cursor(translate_cursor(output.cursor_icon));
}
// ----------------------------------------------------------------------------
pub fn read_memory(ctx: &Context, memory_json_path: impl AsRef<std::path::Path>) {
match std::fs::File::open(memory_json_path) {
Ok(file) => {
let reader = std::io::BufReader::new(file);
match serde_json::from_reader(reader) {
Ok(memory) => {
*ctx.memory() = memory;
}
Err(err) => {
eprintln!("ERROR: Failed to parse memory json: {}", err);
}
}
}
Err(err) => {
eprintln!("ERROR: Failed to read memory file: {}", err);
}
}
}
pub fn write_memory(
ctx: &Context,
memory_json_path: impl AsRef<std::path::Path>,
) -> Result<(), Box<dyn std::error::Error>> {
serde_json::to_writer(std::fs::File::create(memory_json_path)?, &*ctx.memory())?;
Ok(())
}