Browse Source

eframe: Add `epi::NativeOptions::initial_window_pos`

pull/1214/head
Emil Ernerfeldt 3 years ago
parent
commit
cbc53fbe2e
  1. 1
      eframe/CHANGELOG.md
  2. 47
      egui-winit/src/epi.rs
  3. 10
      epi/src/lib.rs

1
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)).

47
egui-winit/src/epi.rs

@ -12,32 +12,51 @@ pub fn window_builder(
native_options: &epi::NativeOptions,
window_settings: &Option<crate::WindowSettings>,
) -> 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

10
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<IconData>,
/// 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<egui::Pos2>,
/// The initial inner size of the native window in points (logical pixels).
pub initial_window_size: Option<egui::Vec2>,
/// The minimum window size
/// The minimum inner window size
pub min_window_size: Option<egui::Vec2>,
/// The maximum window size
/// The maximum inner window size
pub max_window_size: Option<egui::Vec2>,
/// 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,

Loading…
Cancel
Save