Skip to content

Commit

Permalink
eframe: Add epi::NativeOptions::initial_window_pos
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 5, 2022
1 parent 7d41551 commit cbc53fb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
1 change: 1 addition & 0 deletions eframe/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).

Expand Down
47 changes: 33 additions & 14 deletions egui-winit/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions epi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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,
Expand Down

0 comments on commit cbc53fb

Please sign in to comment.