Struct glutin::Window

source ·
pub struct Window { /* private fields */ }
Expand description

Represents a window.

Example

use winit::{Event, EventsLoop, Window, WindowEvent, ControlFlow};

let mut events_loop = EventsLoop::new();
let window = Window::new(&events_loop).unwrap();

events_loop.run_forever(|event| {
    match event {
        Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
            ControlFlow::Break
        },
        _ => ControlFlow::Continue,
    }
});

Implementations§

source§

impl Window

source

pub fn new(events_loop: &EventsLoop) -> Result<Window, CreationError>

Creates a new Window for platforms where this is appropriate.

This function is equivalent to WindowBuilder::new().build(events_loop).

Error should be very rare and only occur in case of permission denied, incompatible system, out of memory, etc.

source

pub fn set_title(&self, title: &str)

Modifies the title of the window.

This is a no-op if the window has already been closed.

source

pub fn show(&self)

Shows the window if it was hidden.

Platform-specific
  • Has no effect on Android
source

pub fn hide(&self)

Hides the window if it was visible.

Platform-specific
  • Has no effect on Android
source

pub fn get_position(&self) -> Option<LogicalPosition>

Returns the position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.

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.

The coordinates can be negative if the top-left hand corner of the window is outside of the visible screen region.

Returns None if the window no longer exists.

source

pub fn get_inner_position(&self) -> Option<LogicalPosition>

Returns the position of the top-left hand corner of the window’s client area relative to the top-left hand corner of the desktop.

The same conditions that apply to get_position apply to this method.

source

pub fn set_position(&self, position: LogicalPosition)

Modifies the position of the window.

See get_position for more information about the coordinates.

This is a no-op if the window has already been closed.

source

pub fn get_inner_size(&self) -> Option<LogicalSize>

Returns the logical size of the window’s client area.

The client area is the content of the window, excluding the title bar and borders.

Converting the returned LogicalSize to PhysicalSize produces the size your framebuffer should be.

Returns None if the window no longer exists.

source

pub fn get_outer_size(&self) -> Option<LogicalSize>

Returns the logical size of the entire window.

These dimensions include the title bar and borders. If you don’t want that (and you usually don’t), use get_inner_size instead.

Returns None if the window no longer exists.

source

pub fn set_inner_size(&self, size: LogicalSize)

Modifies the inner size of the window.

See get_inner_size for more information about the values.

This is a no-op if the window has already been closed.

source

pub fn set_min_dimensions(&self, dimensions: Option<LogicalSize>)

Sets a minimum dimension size for the window.

source

pub fn set_max_dimensions(&self, dimensions: Option<LogicalSize>)

Sets a maximum dimension size for the window.

source

pub fn set_resizable(&self, resizable: bool)

Sets whether the window is resizable or not.

Note that making the window unresizable doesn’t exempt you from handling Resized, as that event can still be triggered by DPI scaling, entering fullscreen mode, etc.

Platform-specific

This only has an effect on desktop platforms.

Due to a bug in XFCE, this has no effect on Xfwm.

source

pub fn get_hidpi_factor(&self) -> f64

Returns the DPI factor that can be used to map logical pixels to physical pixels, and vice versa.

See the dpi module for more information.

Note that this value can change depending on user action (for example if the window is moved to another screen); as such, tracking WindowEvent::HiDpiFactorChanged events is the most robust way to track the DPI you need to use to draw.

Platform-specific
  • X11: Can be overridden using the WINIT_HIDPI_FACTOR environment variable.
  • Android: Always returns 1.0.
source

pub fn set_cursor(&self, cursor: MouseCursor)

Modifies the mouse cursor of the window. Has no effect on Android.

source

pub fn set_cursor_position( &self, position: LogicalPosition ) -> Result<(), String>

Changes the position of the cursor in window coordinates.

source

pub fn grab_cursor(&self, grab: bool) -> Result<(), String>

Grabs the cursor, preventing it from leaving the window.

Platform-specific

On macOS, this presently merely locks the cursor in a fixed location, which looks visually awkward.

This has no effect on Android or iOS.

source

pub fn hide_cursor(&self, hide: bool)

Hides the cursor, making it invisible but still usable.

Platform-specific

On Windows and X11, the cursor is only hidden within the confines of the window.

On macOS, the cursor is hidden as long as the window has input focus, even if the cursor is outside of the window.

This has no effect on Android or iOS.

source

pub fn set_maximized(&self, maximized: bool)

Sets the window to maximized or back

source

pub fn set_fullscreen(&self, monitor: Option<MonitorId>)

Sets the window to fullscreen or back

source

pub fn set_decorations(&self, decorations: bool)

Turn window decorations on or off.

source

pub fn set_always_on_top(&self, always_on_top: bool)

Change whether or not the window will always be on top of other windows.

source

pub fn set_window_icon(&self, window_icon: Option<Icon>)

Sets the window icon. On Windows and X11, this is typically the small icon in the top-left corner of the titlebar.

For more usage notes, see WindowBuilder::with_window_icon.

Platform-specific

This only has an effect on Windows and X11.

source

pub fn set_ime_spot(&self, position: LogicalPosition)

Sets location of IME candidate box in client area coordinates relative to the top left.

source

pub fn get_current_monitor(&self) -> MonitorId

Returns the monitor on which the window currently resides

source

pub fn get_available_monitors(&self) -> AvailableMonitorsIter

Returns the list of all the monitors available on the system.

This is the same as EventsLoop::get_available_monitors, and is provided for convenience.

source

pub fn get_primary_monitor(&self) -> MonitorId

Returns the primary monitor of the system.

This is the same as EventsLoop::get_primary_monitor, and is provided for convenience.

source

pub fn id(&self) -> WindowId

Trait Implementations§

source§

impl WindowExt for Window

source§

fn get_xlib_window(&self) -> Option<u64>

Returns the ID of the Window xlib object that is used by this window. Read more
source§

fn get_xlib_display(&self) -> Option<*mut c_void>

Returns a pointer to the Display object of xlib that is used by this window. Read more
source§

fn get_xlib_screen_id(&self) -> Option<i32>

source§

fn get_xcb_connection(&self) -> Option<*mut c_void>

This function returns the underlying xcb_connection_t of an xlib Display. Read more
source§

fn set_urgent(&self, is_urgent: bool)

Set window urgency hint (XUrgencyHint). Only relevant on X.
source§

fn get_wayland_surface(&self) -> Option<*mut c_void>

Returns a pointer to the wl_surface object of wayland that is used by this window. Read more
source§

fn get_wayland_display(&self) -> Option<*mut c_void>

Returns a pointer to the wl_display object of wayland that is used by this window. Read more
source§

fn is_ready(&self) -> bool

👎Deprecated
Check if the window is ready for drawing Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Window

§

impl Send for Window

§

impl Sync for Window

§

impl Unpin for Window

§

impl !UnwindSafe for Window

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>

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.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

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

fn as_any(&self) -> &(dyn Any + 'static)

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

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

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

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> SetParameter for T

§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Resultwhere T: Parameter<Self>,

Sets value as a parameter of self.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Erased for T