logo
pub struct Window { /* private fields */ }
Expand description

An operating system window that can present content and receive user input.

To create a window, use a EventWriter<CreateWindow>.

Window Sizes

There are three sizes associated with a window. The physical size which is the height and width in physical pixels on the monitor. The logical size which is the physical size scaled by an operating system provided factor to account for monitors with differing pixel densities or user preference. And the requested size, measured in logical pixels, which is the value submitted to the API when creating the window, or requesting that it be resized.

The actual size, in logical pixels, of the window may not match the requested size due to operating system limits on the window size, or the quantization of the logical size when converting the physical size to the logical size through the scaling factor.

Accessing a Window from a system

To access a Window from a system, use [bevy_ecs::change_detection::ResMut]<crate::Windows>.

Example

fn access_window_system(mut windows: ResMut<Windows>){
    for mut window in windows.iter_mut() {
        window.set_title(String::from("Yay, I'm a window!"));
    }
}

Implementations

Creates a new Window.

Get the window’s WindowId.

The current logical width of the window’s client area.

The current logical height of the window’s client area.

The requested window client area width in logical pixels from window creation or the last call to set_resolution.

This may differ from the actual width depending on OS size limits and the scaling factor for high DPI monitors.

The requested window client area height in logical pixels from window creation or the last call to set_resolution.

This may differ from the actual width depending on OS size limits and the scaling factor for high DPI monitors.

The window’s client area width in physical pixels.

The window’s client area height in physical pixels.

The window’s client resize constraint in logical pixels.

The window’s client position in physical pixels.

Set whether or not the window is maximized.

Sets the window to minimized or back.

Platform-specific
  • iOS / Android / Web: Unsupported.
  • Wayland: Un-minimize is unsupported.

Modifies the position of the window in physical pixels.

Note that the top-left hand corner of the desktop is not necessarily the same as the screen. If the user uses a desktop with multiple monitors, the top-left hand corner of the desktop is the top-left hand corner of the monitor at the top-left of the desktop. This automatically un-maximizes the window if it’s maximized.

Platform-specific
  • iOS: Can only be called on the main thread. Sets the top left coordinates of the window in the screen space coordinate system.
  • Web: Sets the top-left coordinates relative to the viewport.
  • Android / Wayland: Unsupported.

Modifies the position of the window to be in the center of the current monitor

Platform-specific
  • iOS: Can only be called on the main thread.
  • Web / Android / Wayland: Unsupported.

Modifies the minimum and maximum window bounds for resizing in logical pixels.

Request the OS to resize the window such the client area matches the specified width and height.

Override the os-reported scaling factor.

The ratio of physical pixels to logical pixels

physical_pixels = logical_pixels * scale_factor

The window scale factor as reported by the window backend.

This value is unaffected by scale_factor_override.

The scale factor set with set_scale_factor_override.

This value may be different from the scale factor reported by the window backend.

Get the window’s title.

Set the window’s title.

Get the window’s PresentMode.

Set the window’s PresentMode.

Get whether or not the window is resizable.

Set whether or not the window is resizable.

Get whether or not decorations are enabled.

(Decorations are the minimize, maximize, and close buttons on desktop apps)

Platform-specific

iOS, Android, and the Web do not have decorations.

Set whether or not decorations are enabled.

(Decorations are the minimize, maximize, and close buttons on desktop apps)

Platform-specific

iOS, Android, and the Web do not have decorations.

Get whether or not the cursor is locked.

Platform-specific
  • macOS doesn’t support cursor lock, but most windowing plugins can emulate it. See issue #4875 for more information.
  • iOS/Android don’t have cursors.

Set whether or not the cursor is locked.

This doesn’t hide the cursor. For that, use set_cursor_visibility

Platform-specific
  • macOS doesn’t support cursor lock, but most windowing plugins can emulate it. See issue #4875 for more information.
  • iOS/Android don’t have cursors.

Get whether or not the cursor is visible.

Platform-specific
  • Windows, X11, and Wayland: The cursor is hidden only when inside the window. To stop the cursor from leaving the window, use set_cursor_lock_mode.
  • macOS: The cursor is hidden only when the window is focused.
  • iOS and Android do not have cursors

Set whether or not the cursor is visible.

Platform-specific
  • Windows, X11, and Wayland: The cursor is hidden only when inside the window. To stop the cursor from leaving the window, use set_cursor_lock_mode.
  • macOS: The cursor is hidden only when the window is focused.
  • iOS and Android do not have cursors

Get the current CursorIcon

Set the CursorIcon

The current mouse position, in physical pixels.

The current mouse position, in logical pixels, taking into account the screen scale factor.

Set the cursor’s position

Get the window’s WindowMode

Set the window’s WindowMode

Close the operating system window corresponding to this Window.

This will also lead to this Window being removed from the Windows resource.

If the default WindowPlugin is used, when no windows are open, the app will exit.
To disable this behaviour, set exit_on_all_closed on the WindowPlugin to false

Get whether or not the window has focus.

A window loses focus when the user switches to another window, and regains focus when the user uses the window again

Get the RawWindowHandleWrapper corresponding to this window

The “html canvas” element selector.

If set, this selector will be used to find a matching html canvas element, rather than creating a new one.
Uses the CSS selector format.

This value has no effect on non-web platforms.

Whether or not to fit the canvas element’s size to its parent element’s size.

Warning: this will not behave as expected for parents that set their size according to the size of their children. This creates a “feedback loop” that will result in the canvas growing on each resize. When using this feature, ensure the parent’s size is not affected by its children.

This value has no effect on non-web platforms.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more