pub struct WindowHandle<'a> { /* private fields */ }
Expand description

Handle to a window.

A WindowHandle can be used to interact with a window from within the global context thread. To interact with a window from another thread, you need a WindowProxy.

Implementations§

source§

impl<'a> WindowHandle<'a>

source

pub fn new( context_handle: ContextHandle<'a>, index: usize, destroy_flag: Option<&'a mut bool> ) -> Self

Create a new window handle from a context handle and a window ID.

source

pub fn id(&self) -> WindowId

Get the window ID.

source

pub fn proxy(&self) -> WindowProxy

Get a proxy object for the window to interact with it from a different thread.

You should not use proxy objects from withing the global context thread. The proxy objects often wait for the global context to perform some action. Doing so from within the global context thread would cause a deadlock.

source

pub fn release(self) -> ContextHandle<'a>

Release the window handle to get a ContextHandle.

This can be used inside a window event handler to gain access to the ContextHandle. If you do not need mutable access to the context, you can also use context_handle().

source

pub fn context_handle(&self) -> &ContextHandle<'a>

Get a reference to the context handle.

If you need mutable access to the context, use release() instead.

source

pub fn destroy(self) -> ContextHandle<'a>

Destroy the window.

Any subsequent operation on the window through an existing WindowProxy will return InvalidWindowId.

source

pub fn image_info(&self) -> Option<&ImageInfo>

Get the image info.

Returns None if no image is set for the window.

source

pub fn preserve_aspect_ratio(&self) -> bool

Check if the window will preserve the aspect ratio of images it displays.

source

pub fn set_preserve_aspect_ratio(&mut self, preserve_aspect_ratio: bool)

Set if the window will preserve the aspect ratio of images it displays.

source

pub fn background_color(&self) -> Color

Get the background color of the window.

source

pub fn set_background_color(&mut self, background_color: Color)

Set the background color of the window.

source

pub fn set_visible(&mut self, visible: bool)

Make the window visible or invisible.

source

pub fn set_outer_position(&self, position: impl Into<IVec2>)

Set the window position in pixels.

This will automatically un-maximize the window.

Some window managers or platforms may ignore this property.

source

pub fn inner_size(&self) -> UVec2

Get the inner size of the window in physical pixels.

This returns the size of the window contents, excluding borders, the title bar and other decorations.

source

pub fn outer_size(&self) -> UVec2

Get the outer size of the window in physical pixels.

This returns the size of the entire window, including borders, the title bar and other decorations.

source

pub fn set_inner_size(&mut self, size: impl Into<UVec2>)

Set the inner size of the window in pixels.

The size is excluding borders, the title bar and other decorations.

Some window managers may ignore this property.

source

pub fn set_resizable(&mut self, resizable: bool)

Set if the window should be resizable for the user.

Some window managers may ignore this property.

source

pub fn set_borderless(&mut self, borderless: bool)

Set if the window should be drawn without borders.

Some window managers may ignore this property.

source

pub fn set_fullscreen(&mut self, fullscreen: bool)

Set the window in fullscreen mode or back.

This will set the window to borderless fullscreen on the current monitor or back. Fullscreen is set if the argument is true, otherwise the window is returned to normal size.

Some window managers may ignore this property.

source

pub fn is_fullscreen(&self) -> bool

Check if the window is set to fullscreen mode.

Note that some window managers may ignore the request for fullscreen mode. In that case, this function may return true while the window is not displayed in fullscreen mode.

source

pub fn set_image(&mut self, name: impl Into<String>, image: &ImageView<'_>)

Set the image to display on the window.

source

pub fn set_overlay( &mut self, name: impl Into<String>, image: &ImageView<'_>, initially_visible: bool )

Add an overlay to the window.

Overlays are drawn on top of the image in the order that they are first added. If you wish to change the order of existing overlays, you must remove and re-add the overlays.

If the window already has an overlay with the same name, the overlay is overwritten and the initially_visible argument is ignored. If you want to change the visibility of the overlay, you can call set_overlay_visible(). If you do so before your function returns, it is guaranteed to have taken effect before the next redraw.

source

pub fn remove_overlay(&mut self, name: &impl AsRef<str>) -> bool

Remove an overlay from the window.

Returns true if there was an overlay to remove.

source

pub fn clear_overlays(&mut self)

Remove all overlays from the window.

source

pub fn is_overlay_visible( &mut self, name: impl AsRef<str> ) -> Result<bool, UnknownOverlay>

Check if an overlay is visible or not.

source

pub fn set_overlay_visible( &mut self, name: impl AsRef<str>, visible: bool ) -> Result<(), UnknownOverlay>

Make a specific overlay visible or invisible for this window.

The overlay is not removed, but it will not be rendered anymore untill you make it visible again.

source

pub fn toggle_overlay_visible( &mut self, name: impl AsRef<str> ) -> Result<(), UnknownOverlay>

Toggle an overlay between visible and invisible.

source

pub fn set_all_overlays_visible(&mut self, visible: bool)

Make all overlays visible or invisible for this window.

source

pub fn add_event_handler<F>(&mut self, handler: F)
where F: 'static + FnMut(WindowHandle<'_>, &mut WindowEvent, &mut EventHandlerControlFlow),

Add an event handler to the window.

source

pub fn transform(&self) -> Affine2

Get the image transformation.

The image transformation is applied to the image and all overlays in virtual window space.

Virtual window space goes from (0, 0) in the top left corner of the window to (1, 1) in the bottom right corner.

This transformation does not include scaling introduced by the Self::preserve_aspect_ratio() property. Use Self::effective_transform() if you need that.

source

pub fn effective_transform(&self) -> Affine2

Get the full effective transformation from image space to virtual window space.

This transformation maps the image coordinates to virtual window coordinates. Unlike Self::transform(), this function returns a transformation that include the scaling introduced by the Self::preserve_aspect_ratio() property. This is useful to transform between window coordinates and image coordinates.

If no image is set on the window yet, this returns the same transformation as Self::transform().

Virtual window space goes from (0, 0) in the top left corner of the window to (1, 1) in the bottom right corner.

Note that physical pixel locations must be transformed to virtual window coordinates first.

source

pub fn set_transform(&mut self, transform: Affine2)

Set the image transformation to a value.

The image transformation is applied to the image and all overlays in virtual window space.

Virtual window space goes from (0, 0) in the top left corner of the window to (1, 1) in the bottom right corner.

This transformation should not include any scaling related to the Self::preserve_aspect_ratio() property.

source

pub fn pre_apply_transform(&mut self, transform: Affine2)

Pre-apply a transformation to the existing image transformation.

This is equivalent to:

window.set_transform(transform * window.transform())

See Self::set_transform for more information about the image transformation.

source

pub fn post_apply_transform(&mut self, transform: Affine2)

Post-apply a transformation to the existing image transformation.

This is equivalent to:

window.set_transform(window.transform() * transform)

See Self::set_transform for more information about the image transformation.

Auto Trait Implementations§

§

impl<'a> Freeze for WindowHandle<'a>

§

impl<'a> !RefUnwindSafe for WindowHandle<'a>

§

impl<'a> !Send for WindowHandle<'a>

§

impl<'a> !Sync for WindowHandle<'a>

§

impl<'a> Unpin for WindowHandle<'a>

§

impl<'a> !UnwindSafe for WindowHandle<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where 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.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V