diff --git a/egui_glium/src/backend.rs b/egui_glium/src/backend.rs index dcf177c7..a9732dcc 100644 --- a/egui_glium/src/backend.rs +++ b/egui_glium/src/backend.rs @@ -57,6 +57,7 @@ impl epi::RepaintSignal for GliumRepaintSignal { fn create_display( title: &str, + initial_size_points: Option, window_settings: Option, is_resizable: bool, event_loop: &glutin::event_loop::EventLoop, @@ -69,6 +70,11 @@ fn create_display( if let Some(window_settings) = &window_settings { window_builder = window_settings.initialize_size(window_builder); + } else if let Some(initial_size_points) = initial_size_points { + window_builder = window_builder.with_inner_size(glutin::dpi::LogicalSize { + width: initial_size_points.x as f64, + height: initial_size_points.y as f64, + }); } let context_builder = glutin::ContextBuilder::new() @@ -135,7 +141,13 @@ pub fn run(mut app: Box) -> ! { let window_settings = deserialize_window_settings(&storage); let event_loop = glutin::event_loop::EventLoop::with_user_event(); - let display = create_display(app.name(), window_settings, app.is_resizable(), &event_loop); + let display = create_display( + app.name(), + app.initial_window_size(), + window_settings, + app.is_resizable(), + &event_loop, + ); let repaint_signal = std::sync::Arc::new(GliumRepaintSignal(std::sync::Mutex::new( event_loop.create_proxy(), diff --git a/egui_glium/src/persistence.rs b/egui_glium/src/persistence.rs index 2c3ac2ff..f426a30d 100644 --- a/egui_glium/src/persistence.rs +++ b/egui_glium/src/persistence.rs @@ -38,6 +38,7 @@ impl epi::Storage for FileStorage { fn flush(&mut self) { if self.dirty { + // eprintln!("Persisted to {}", self.path.display()); serde_json::to_writer(std::fs::File::create(&self.path).unwrap(), &self.kv).unwrap(); self.dirty = false; } @@ -46,11 +47,11 @@ impl epi::Storage for FileStorage { // ---------------------------------------------------------------------------- -pub fn read_json(memory_json_path: impl AsRef) -> Option +pub fn read_json(json_path: impl AsRef) -> Option where T: serde::de::DeserializeOwned, { - match std::fs::File::open(memory_json_path) { + match std::fs::File::open(json_path) { Ok(file) => { let reader = std::io::BufReader::new(file); match serde_json::from_reader(reader) { diff --git a/epi/CHANGELOG.md b/epi/CHANGELOG.md index ecbe9413..c0b66b5e 100644 --- a/epi/CHANGELOG.md +++ b/epi/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +* You can control the initial size of the native window with `App::initial_window_size`. * You can control the maximum egui web canvas size with `App::max_size_points`. diff --git a/epi/src/lib.rs b/epi/src/lib.rs index 7e348a1a..b14baf40 100644 --- a/epi/src/lib.rs +++ b/epi/src/lib.rs @@ -87,6 +87,11 @@ pub trait App { /// The name of your App. fn name(&self) -> &str; + /// The initial size of the native window in points (logical pixels). + fn initial_window_size(&self) -> Option { + None + } + /// Time between automatic calls to `save()` fn auto_save_interval(&self) -> std::time::Duration { std::time::Duration::from_secs(30)