Improve window::Position API

This commit is contained in:
Héctor Ramón Jiménez 2021-07-21 18:59:24 +07:00
parent 6793a7e00d
commit 72b3bf95de
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
7 changed files with 121 additions and 16 deletions

View file

@ -9,7 +9,7 @@ mod platform;
pub use platform::PlatformSpecific;
use crate::conversion;
use crate::Mode;
use crate::{Mode, Position};
use winit::monitor::MonitorHandle;
use winit::window::WindowBuilder;
@ -36,7 +36,7 @@ pub struct Window {
pub size: (u32, u32),
/// The position of the window.
pub position: (i32, i32),
pub position: Position,
/// The minimum size of the window.
pub min_size: Option<(u32, u32)>,
@ -78,15 +78,21 @@ impl Window {
window_builder = window_builder
.with_title(title)
.with_inner_size(winit::dpi::LogicalSize { width, height })
.with_position(winit::dpi::LogicalPosition { x: self.position.0, y: self.position.1 })
.with_resizable(self.resizable)
.with_decorations(self.decorations)
.with_transparent(self.transparent)
.with_window_icon(self.icon)
.with_always_on_top(self.always_on_top)
.with_fullscreen(conversion::fullscreen(primary_monitor, mode))
.with_visible(conversion::visible(mode));
if let Some(position) = conversion::position(
primary_monitor.as_ref(),
self.size,
self.position,
) {
window_builder = window_builder.with_position(position);
}
if let Some((width, height)) = self.min_size {
window_builder = window_builder
.with_min_inner_size(winit::dpi::LogicalSize { width, height });
@ -108,6 +114,9 @@ impl Window {
.with_drag_and_drop(self.platform_specific.drag_and_drop);
}
window_builder = window_builder
.with_fullscreen(conversion::fullscreen(primary_monitor, mode));
window_builder
}
}
@ -116,7 +125,7 @@ impl Default for Window {
fn default() -> Window {
Window {
size: (1024, 768),
position: (100, 100),
position: Position::default(),
min_size: None,
max_size: None,
resizable: true,