min and max window size (#1171)

This commit is contained in:
Unknown 2022-02-02 16:47:27 +01:00 committed by GitHub
parent 869d556335
commit 270c08a030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View file

@ -1,3 +1,13 @@
use egui::Vec2;
use winit::dpi::LogicalSize;
pub fn points_to_size(points: Vec2) -> LogicalSize<f64> {
winit::dpi::LogicalSize {
width: points.x as f64,
height: points.y as f64,
}
}
pub fn window_builder(
native_options: &epi::NativeOptions,
window_settings: &Option<crate::WindowSettings>,
@ -12,6 +22,13 @@ pub fn window_builder(
.with_transparent(native_options.transparent)
.with_window_icon(window_icon);
if let Some(min_size) = native_options.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 {
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);
@ -20,10 +37,7 @@ pub fn window_builder(
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(winit::dpi::LogicalSize {
width: initial_size_points.x as f64,
height: initial_size_points.y as f64,
});
window_builder = window_builder.with_inner_size(points_to_size(initial_size_points));
}
window_builder

View file

@ -233,6 +233,12 @@ pub struct NativeOptions {
/// The initial size of the native window in points (logical pixels).
pub initial_window_size: Option<egui::Vec2>,
/// The minimum window size
pub min_window_size: Option<egui::Vec2>,
/// The maximum window size
pub max_window_size: Option<egui::Vec2>,
/// Should the app window be resizable?
pub resizable: bool,
@ -251,6 +257,8 @@ impl Default for NativeOptions {
drag_and_drop_support: false,
icon_data: None,
initial_window_size: None,
min_window_size: None,
max_window_size: None,
resizable: true,
transparent: false,
}