From 6612dd83bd22e17a814c737910e575f039fe44a6 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 27 Sep 2023 08:31:55 +0200 Subject: [PATCH 1/3] Move `App::persist_window` to `NativeOptions` --- crates/eframe/src/epi/mod.rs | 12 ++++++------ crates/eframe/src/native/epi_integration.rs | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/eframe/src/epi/mod.rs b/crates/eframe/src/epi/mod.rs index 3e5c9caf541..8f07f4e8f8a 100644 --- a/crates/eframe/src/epi/mod.rs +++ b/crates/eframe/src/epi/mod.rs @@ -208,12 +208,6 @@ pub trait App { // _visuals.window_fill() would also be a natural choice } - /// Controls whether or not the native window position and size will be - /// persisted (only if the "persistence" feature is enabled). - fn persist_native_window(&self) -> bool { - true - } - /// Controls whether or not the egui memory (window positions etc) will be /// persisted (only if the "persistence" feature is enabled). fn persist_egui_memory(&self) -> bool { @@ -455,6 +449,10 @@ pub struct NativeOptions { /// } /// ``` pub app_id: Option, + + /// Controls whether or not the native window position and size will be + /// persisted (only if the "persistence" feature is enabled). + pub persist_window: bool, } #[cfg(not(target_arch = "wasm32"))] @@ -529,6 +527,8 @@ impl Default for NativeOptions { wgpu_options: egui_wgpu::WgpuConfiguration::default(), app_id: None, + + persist_window: true, } } } diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 3912410d8bf..4d4653faa98 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -354,6 +354,7 @@ pub struct EpiIntegration { can_drag_window: bool, window_state: WindowState, follow_system_theme: bool, + persist_window: bool, app_icon_setter: super::app_icon::AppTitleIconSetter, } @@ -422,6 +423,7 @@ impl EpiIntegration { can_drag_window: false, window_state, follow_system_theme: native_options.follow_system_theme, + persist_window: native_options.persist_window, app_icon_setter, } } @@ -593,7 +595,7 @@ impl EpiIntegration { crate::profile_function!(); if let Some(window) = _window { - if _app.persist_native_window() { + if self.persist_window { crate::profile_scope!("native_window"); epi::set_value( storage, From cb6b7118a7f930502de299f1ee1eb490986a62a2 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 27 Sep 2023 08:33:44 +0200 Subject: [PATCH 2/3] Move `App::max_size_points` to `WebOptions` --- crates/eframe/src/epi/mod.rs | 14 +++++++------- crates/eframe/src/web/app_runner.rs | 4 +++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/eframe/src/epi/mod.rs b/crates/eframe/src/epi/mod.rs index 8f07f4e8f8a..96c7ab2b353 100644 --- a/crates/eframe/src/epi/mod.rs +++ b/crates/eframe/src/epi/mod.rs @@ -182,13 +182,6 @@ pub trait App { std::time::Duration::from_secs(30) } - /// The size limit of the web app canvas. - /// - /// By default the max size is [`egui::Vec2::INFINITY`], i.e. unlimited. - fn max_size_points(&self) -> egui::Vec2 { - egui::Vec2::INFINITY - } - /// Background color values for the app, e.g. what is sent to `gl.clearColor`. /// /// This is the background of your windows if you don't set a central panel. @@ -566,6 +559,11 @@ pub struct WebOptions { /// Configures wgpu instance/device/adapter/surface creation and renderloop. #[cfg(feature = "wgpu")] pub wgpu_options: egui_wgpu::WgpuConfiguration, + + /// The size limit of the web app canvas. + /// + /// By default the max size is [`egui::Vec2::INFINITY`], i.e. unlimited. + pub max_size_points: egui::Vec2, } #[cfg(target_arch = "wasm32")] @@ -581,6 +579,8 @@ impl Default for WebOptions { #[cfg(feature = "wgpu")] wgpu_options: egui_wgpu::WgpuConfiguration::default(), + + max_size_points: egui::Vec2::INFINITY, } } } diff --git a/crates/eframe/src/web/app_runner.rs b/crates/eframe/src/web/app_runner.rs index 6f4579b66ff..6dea4394c90 100644 --- a/crates/eframe/src/web/app_runner.rs +++ b/crates/eframe/src/web/app_runner.rs @@ -6,6 +6,7 @@ use crate::{epi, App}; use super::{now_sec, web_painter::WebPainter, NeedRepaint}; pub struct AppRunner { + web_options: WebOptions, pub(crate) frame: epi::Frame, egui_ctx: egui::Context, painter: super::ActiveWebPainter, @@ -98,6 +99,7 @@ impl AppRunner { } let mut runner = Self { + web_options, frame, egui_ctx, painter, @@ -174,7 +176,7 @@ impl AppRunner { pub fn logic(&mut self) -> (std::time::Duration, Vec) { let frame_start = now_sec(); - super::resize_canvas_to_screen_size(self.canvas_id(), self.app.max_size_points()); + super::resize_canvas_to_screen_size(self.canvas_id(), self.web_options.max_size_points); let canvas_size = super::canvas_size_in_points(self.canvas_id()); let raw_input = self.input.new_frame(canvas_size); From a44c1bb3b0e4f331047d06eefedd66b9aa4b6342 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 27 Sep 2023 08:37:14 +0200 Subject: [PATCH 3/3] Build fixes --- crates/eframe/src/native/epi_integration.rs | 2 ++ crates/eframe/src/web/app_runner.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 4d4653faa98..737d46bf2cd 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -354,6 +354,7 @@ pub struct EpiIntegration { can_drag_window: bool, window_state: WindowState, follow_system_theme: bool, + #[cfg(feature = "persistence")] persist_window: bool, app_icon_setter: super::app_icon::AppTitleIconSetter, } @@ -423,6 +424,7 @@ impl EpiIntegration { can_drag_window: false, window_state, follow_system_theme: native_options.follow_system_theme, + #[cfg(feature = "persistence")] persist_window: native_options.persist_window, app_icon_setter, } diff --git a/crates/eframe/src/web/app_runner.rs b/crates/eframe/src/web/app_runner.rs index 6dea4394c90..d8646df2bd5 100644 --- a/crates/eframe/src/web/app_runner.rs +++ b/crates/eframe/src/web/app_runner.rs @@ -6,7 +6,7 @@ use crate::{epi, App}; use super::{now_sec, web_painter::WebPainter, NeedRepaint}; pub struct AppRunner { - web_options: WebOptions, + web_options: crate::WebOptions, pub(crate) frame: epi::Frame, egui_ctx: egui::Context, painter: super::ActiveWebPainter,