min and max window size (#1171)
This commit is contained in:
parent
869d556335
commit
270c08a030
2 changed files with 26 additions and 4 deletions
|
@ -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(
|
pub fn window_builder(
|
||||||
native_options: &epi::NativeOptions,
|
native_options: &epi::NativeOptions,
|
||||||
window_settings: &Option<crate::WindowSettings>,
|
window_settings: &Option<crate::WindowSettings>,
|
||||||
|
@ -12,6 +22,13 @@ pub fn window_builder(
|
||||||
.with_transparent(native_options.transparent)
|
.with_transparent(native_options.transparent)
|
||||||
.with_window_icon(window_icon);
|
.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 =
|
||||||
window_builder_drag_and_drop(window_builder, native_options.drag_and_drop_support);
|
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 {
|
if let Some(window_settings) = window_settings {
|
||||||
window_builder = window_settings.initialize_window(window_builder);
|
window_builder = window_settings.initialize_window(window_builder);
|
||||||
} else if let Some(initial_size_points) = initial_size_points {
|
} else if let Some(initial_size_points) = initial_size_points {
|
||||||
window_builder = window_builder.with_inner_size(winit::dpi::LogicalSize {
|
window_builder = window_builder.with_inner_size(points_to_size(initial_size_points));
|
||||||
width: initial_size_points.x as f64,
|
|
||||||
height: initial_size_points.y as f64,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window_builder
|
window_builder
|
||||||
|
|
|
@ -233,6 +233,12 @@ pub struct NativeOptions {
|
||||||
/// The initial size of the native window in points (logical pixels).
|
/// The initial size of the native window in points (logical pixels).
|
||||||
pub initial_window_size: Option<egui::Vec2>,
|
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?
|
/// Should the app window be resizable?
|
||||||
pub resizable: bool,
|
pub resizable: bool,
|
||||||
|
|
||||||
|
@ -251,6 +257,8 @@ impl Default for NativeOptions {
|
||||||
drag_and_drop_support: false,
|
drag_and_drop_support: false,
|
||||||
icon_data: None,
|
icon_data: None,
|
||||||
initial_window_size: None,
|
initial_window_size: None,
|
||||||
|
min_window_size: None,
|
||||||
|
max_window_size: None,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
transparent: false,
|
transparent: false,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue