Rename Window::set_inner_size to Window::request_inner_size

Some systems could resize the window immediately and we'd rather
inform the users right away if that was the case, so they could
create e.g. EGLSurface without waiting for resize, which is really
important for Wayland.

Fixes #2868.
This commit is contained in:
Kirill Chibisov 2023-07-10 04:02:26 +00:00 committed by GitHub
parent 42e492cde8
commit ff0ce9d065
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 65 additions and 41 deletions

View file

@ -188,7 +188,7 @@ impl WindowBuilder {
///
/// If this is not set, some platform-specific dimensions will be used.
///
/// See [`Window::set_inner_size`] for details.
/// See [`Window::request_inner_size`] for details.
#[inline]
pub fn with_inner_size<S: Into<Size>>(mut self, size: S) -> Self {
self.window.inner_size = Some(size.into());
@ -652,10 +652,21 @@ impl Window {
self.window.inner_size()
}
/// Modifies the inner size of the window.
/// Request the new size for the window.
///
/// On platforms where the size is entirely controlled by the user the
/// applied size will be returned immediately, resize event in such case
/// may not be generated.
///
/// On platforms where resizing is disallowed by the windowing system, the current
/// inner size is returned immidiatelly, and the user one is ignored.
///
/// When `None` is returned, it means that the request went to the display system,
/// and the actual size will be delivered later with the [`WindowEvent::Resized`].
///
/// See [`Window::inner_size`] for more information about the values.
/// This automatically un-maximizes the window if it's maximized.
///
/// The request could automatically un-maximize the window if it's maximized.
///
/// ```no_run
/// # use winit::dpi::{LogicalSize, PhysicalSize};
@ -664,19 +675,21 @@ impl Window {
/// # let mut event_loop = EventLoop::new();
/// # let window = Window::new(&event_loop).unwrap();
/// // Specify the size in logical dimensions like this:
/// window.set_inner_size(LogicalSize::new(400.0, 200.0));
/// let _ = window.request_inner_size(LogicalSize::new(400.0, 200.0));
///
/// // Or specify the size in physical dimensions like this:
/// window.set_inner_size(PhysicalSize::new(400, 200));
/// let _ = window.request_inner_size(PhysicalSize::new(400, 200));
/// ```
///
/// ## Platform-specific
///
/// - **iOS / Android:** Unsupported.
/// - **Web:** Sets the size of the canvas element.
///
/// [`WindowEvent::Resized`]: crate::event::WindowEvent::Resized.
#[inline]
pub fn set_inner_size<S: Into<Size>>(&self, size: S) {
self.window.set_inner_size(size.into())
#[must_use]
pub fn request_inner_size<S: Into<Size>>(&self, size: S) -> Option<PhysicalSize<u32>> {
self.window.request_inner_size(size.into())
}
/// Returns the physical size of the entire window.
@ -827,7 +840,7 @@ impl Window {
///
/// Note that making the window unresizable doesn't exempt you from handling [`WindowEvent::Resized`], as that
/// event can still be triggered by DPI scaling, entering fullscreen mode, etc. Also, the
/// window could still be resized by calling [`Window::set_inner_size`].
/// window could still be resized by calling [`Window::request_inner_size`].
///
/// ## Platform-specific
///