diff --git a/eframe/CHANGELOG.md b/eframe/CHANGELOG.md index ebe4c607f..5b64eafaa 100644 --- a/eframe/CHANGELOG.md +++ b/eframe/CHANGELOG.md @@ -11,6 +11,7 @@ NOTE: [`egui_web`](../egui_web/CHANGELOG.md), [`egui-winit`](../egui-winit/CHANG * Automatically detect and apply dark or light mode from system ([#1045](https://github.com/emilk/egui/pull/1045)). * Fix horizontal scrolling direction on Linux. * Added `App::on_exit_event` ([#1038](https://github.com/emilk/egui/pull/1038)) +* Added `NativeOptions::initial_window_pos`. * Shift-scroll will now result in horizontal scrolling on all platforms ([#1136](https://github.com/emilk/egui/pull/1136)). * Log using the `tracing` crate. Log to stdout by adding `tracing_subscriber::fmt::init();` to your `main` ([#1192](https://github.com/emilk/egui/pull/1192)). diff --git a/egui-winit/src/epi.rs b/egui-winit/src/epi.rs index b4762be5d..70d13d32c 100644 --- a/egui-winit/src/epi.rs +++ b/egui-winit/src/epi.rs @@ -12,32 +12,51 @@ pub fn window_builder( native_options: &epi::NativeOptions, window_settings: &Option, ) -> winit::window::WindowBuilder { - let window_icon = native_options.icon_data.clone().and_then(load_icon); + let epi::NativeOptions { + always_on_top, + maximized, + decorated, + drag_and_drop_support, + icon_data, + initial_window_pos, + initial_window_size, + min_window_size, + max_window_size, + resizable, + transparent, + } = native_options; + + let window_icon = icon_data.clone().and_then(load_icon); let mut window_builder = winit::window::WindowBuilder::new() - .with_always_on_top(native_options.always_on_top) - .with_maximized(native_options.maximized) - .with_decorations(native_options.decorated) - .with_resizable(native_options.resizable) - .with_transparent(native_options.transparent) + .with_always_on_top(*always_on_top) + .with_maximized(*maximized) + .with_decorations(*decorated) + .with_resizable(*resizable) + .with_transparent(*transparent) .with_window_icon(window_icon); - if let Some(min_size) = native_options.min_window_size { + if let Some(min_size) = *min_window_size { window_builder = window_builder.with_min_inner_size(points_to_size(min_size)); } - if let Some(max_size) = native_options.max_window_size { + if let Some(max_size) = *max_window_size { window_builder = window_builder.with_max_inner_size(points_to_size(max_size)); } - window_builder = - window_builder_drag_and_drop(window_builder, native_options.drag_and_drop_support); - - let initial_size_points = native_options.initial_window_size; + window_builder = window_builder_drag_and_drop(window_builder, *drag_and_drop_support); if let Some(window_settings) = window_settings { window_builder = window_settings.initialize_window(window_builder); - } else if let Some(initial_size_points) = initial_size_points { - window_builder = window_builder.with_inner_size(points_to_size(initial_size_points)); + } else { + if let Some(pos) = *initial_window_pos { + window_builder = window_builder.with_position(winit::dpi::PhysicalPosition { + x: pos.x as f64, + y: pos.y as f64, + }); + } + if let Some(initial_window_size) = *initial_window_size { + window_builder = window_builder.with_inner_size(points_to_size(initial_window_size)); + } } window_builder diff --git a/epi/src/lib.rs b/epi/src/lib.rs index f66b8fcf8..7d646cfd7 100644 --- a/epi/src/lib.rs +++ b/epi/src/lib.rs @@ -230,13 +230,16 @@ pub struct NativeOptions { /// The application icon, e.g. in the Windows task bar etc. pub icon_data: Option, - /// The initial size of the native window in points (logical pixels). + /// The initial (inner) position of the native window in points (logical pixels). + pub initial_window_pos: Option, + + /// The initial inner size of the native window in points (logical pixels). pub initial_window_size: Option, - /// The minimum window size + /// The minimum inner window size pub min_window_size: Option, - /// The maximum window size + /// The maximum inner window size pub max_window_size: Option, /// Should the app window be resizable? @@ -256,6 +259,7 @@ impl Default for NativeOptions { decorated: true, drag_and_drop_support: false, icon_data: None, + initial_window_pos: None, initial_window_size: None, min_window_size: None, max_window_size: None,