Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move App::persist_window to NativeOptions and App::max_size_points to WebOptions #3397

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions crates/eframe/src/epi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -455,6 +442,10 @@ pub struct NativeOptions {
/// }
/// ```
pub app_id: Option<String>,

/// 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"))]
Expand Down Expand Up @@ -529,6 +520,8 @@ impl Default for NativeOptions {
wgpu_options: egui_wgpu::WgpuConfiguration::default(),

app_id: None,

persist_window: true,
}
}
}
Expand Down Expand Up @@ -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")]
Expand All @@ -581,6 +579,8 @@ impl Default for WebOptions {

#[cfg(feature = "wgpu")]
wgpu_options: egui_wgpu::WgpuConfiguration::default(),

max_size_points: egui::Vec2::INFINITY,
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -98,6 +99,7 @@ impl AppRunner {
}

let mut runner = Self {
web_options,
frame,
egui_ctx,
painter,
Expand Down Expand Up @@ -174,7 +176,7 @@ impl AppRunner {
pub fn logic(&mut self) -> (std::time::Duration, Vec<egui::ClippedPrimitive>) {
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);

Expand Down
Loading