Add WindowBuilder::with_outer_position (#1866)

This commit is contained in:
Michal Srb 2021-03-25 21:18:51 +03:00 committed by GitHub
parent 86748fbc68
commit 0d634a0061
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 16 deletions

View file

@ -116,6 +116,31 @@ pub struct WindowAttributes {
/// The default is `None`.
pub max_inner_size: Option<Size>,
/// The desired position of the window. If this is `None`, some platform-specific position
/// will be chosen.
///
/// The default is `None`.
///
/// ## Platform-specific
///
/// - **macOS**: The top left corner position of the window content, the window's "inner"
/// position. The window title bar will be placed above it.
/// The window will be positioned such that it fits on screen, maintaining
/// set `inner_size` if any.
/// If you need to precisely position the top left corner of the whole window you have to
/// use [`Window::set_outer_position`] after creating the window.
/// - **Windows**: The top left corner position of the window title bar, the window's "outer"
/// position.
/// There may be a small gap between this position and the window due to the specifics of the
/// Window Manager.
/// - **X11**: The top left corner of the window, the window's "outer" position.
/// - **Others**: Ignored.
///
/// See [`Window::set_outer_position`].
///
/// [`Window::set_outer_position`]: crate::window::Window::set_outer_position
pub position: Option<Position>,
/// Whether the window is resizable or not.
///
/// The default is `true`.
@ -170,6 +195,7 @@ impl Default for WindowAttributes {
inner_size: None,
min_inner_size: None,
max_inner_size: None,
position: None,
resizable: true,
title: "winit window".to_owned(),
maximized: false,
@ -223,6 +249,17 @@ impl WindowBuilder {
self
}
/// Sets a desired initial position for the window.
///
/// See [`WindowAttributes::position`] for details.
///
/// [`WindowAttributes::position`]: crate::window::WindowAttributes::position
#[inline]
pub fn with_position<P: Into<Position>>(mut self, position: P) -> Self {
self.window.position = Some(position.into());
self
}
/// Sets whether the window is resizable or not.
///
/// See [`Window::set_resizable`] for details.