From b3e19f5b7d65818ce2c3bc5f101e90fc9936b049 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 27 Sep 2023 08:48:48 +0200 Subject: [PATCH] Move `App::persist_window` to `NativeOptions` and `App::max_size_points` to `WebOptions` (#3397) * Move `App::persist_window` to `NativeOptions` * Move `App::max_size_points` to `WebOptions` * Build fixes --- crates/eframe/src/epi/mod.rs | 26 ++++++++++----------- crates/eframe/src/native/epi_integration.rs | 6 ++++- crates/eframe/src/web/app_runner.rs | 4 +++- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/crates/eframe/src/epi/mod.rs b/crates/eframe/src/epi/mod.rs index 3e5c9caf..96c7ab2b 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. @@ -208,12 +201,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 +442,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 +520,8 @@ impl Default for NativeOptions { wgpu_options: egui_wgpu::WgpuConfiguration::default(), app_id: None, + + persist_window: true, } } } @@ -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/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 3912410d..737d46bf 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -354,6 +354,8 @@ 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, } @@ -422,6 +424,8 @@ 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, } } @@ -593,7 +597,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, diff --git a/crates/eframe/src/web/app_runner.rs b/crates/eframe/src/web/app_runner.rs index 6f4579b6..d8646df2 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: crate::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);