Struct show_image::WindowHandle
source · 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>
impl<'a> WindowHandle<'a>
sourcepub fn new(
context_handle: ContextHandle<'a>,
index: usize,
destroy_flag: Option<&'a mut bool>
) -> Self
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.
sourcepub fn proxy(&self) -> WindowProxy
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.
sourcepub fn release(self) -> ContextHandle<'a>
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()
.
sourcepub fn context_handle(&self) -> &ContextHandle<'a>
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.
sourcepub fn destroy(self) -> ContextHandle<'a>
pub fn destroy(self) -> ContextHandle<'a>
Destroy the window.
Any subsequent operation on the window through an existing WindowProxy
will return InvalidWindowId
.
sourcepub fn image_info(&self) -> Option<&ImageInfo>
pub fn image_info(&self) -> Option<&ImageInfo>
Get the image info.
Returns None
if no image is set for the window.
sourcepub fn preserve_aspect_ratio(&self) -> bool
pub fn preserve_aspect_ratio(&self) -> bool
Check if the window will preserve the aspect ratio of images it displays.
sourcepub fn set_preserve_aspect_ratio(&mut self, preserve_aspect_ratio: bool)
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.
sourcepub fn background_color(&self) -> Color
pub fn background_color(&self) -> Color
Get the background color of the window.
sourcepub fn set_background_color(&mut self, background_color: Color)
pub fn set_background_color(&mut self, background_color: Color)
Set the background color of the window.
sourcepub fn set_visible(&mut self, visible: bool)
pub fn set_visible(&mut self, visible: bool)
Make the window visible or invisible.
sourcepub fn set_outer_position(&self, position: impl Into<IVec2>)
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.
sourcepub fn inner_size(&self) -> UVec2
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.
sourcepub fn outer_size(&self) -> UVec2
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.
sourcepub fn set_inner_size(&mut self, size: impl Into<UVec2>)
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.
sourcepub fn set_resizable(&mut self, resizable: bool)
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.
sourcepub fn set_borderless(&mut self, borderless: bool)
pub fn set_borderless(&mut self, borderless: bool)
Set if the window should be drawn without borders.
Some window managers may ignore this property.
sourcepub fn set_fullscreen(&mut self, fullscreen: bool)
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.
sourcepub fn is_fullscreen(&self) -> bool
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.
sourcepub fn set_image(&mut self, name: impl Into<String>, image: &ImageView<'_>)
pub fn set_image(&mut self, name: impl Into<String>, image: &ImageView<'_>)
Set the image to display on the window.
sourcepub fn set_overlay(
&mut self,
name: impl Into<String>,
image: &ImageView<'_>,
initially_visible: bool
)
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.
sourcepub fn remove_overlay(&mut self, name: &impl AsRef<str>) -> bool
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.
sourcepub fn clear_overlays(&mut self)
pub fn clear_overlays(&mut self)
Remove all overlays from the window.
sourcepub fn is_overlay_visible(
&mut self,
name: impl AsRef<str>
) -> Result<bool, UnknownOverlay>
pub fn is_overlay_visible( &mut self, name: impl AsRef<str> ) -> Result<bool, UnknownOverlay>
Check if an overlay is visible or not.
sourcepub fn set_overlay_visible(
&mut self,
name: impl AsRef<str>,
visible: bool
) -> Result<(), UnknownOverlay>
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.
sourcepub fn toggle_overlay_visible(
&mut self,
name: impl AsRef<str>
) -> Result<(), UnknownOverlay>
pub fn toggle_overlay_visible( &mut self, name: impl AsRef<str> ) -> Result<(), UnknownOverlay>
Toggle an overlay between visible and invisible.
sourcepub fn set_all_overlays_visible(&mut self, visible: bool)
pub fn set_all_overlays_visible(&mut self, visible: bool)
Make all overlays visible or invisible for this window.
sourcepub fn add_event_handler<F>(&mut self, handler: F)
pub fn add_event_handler<F>(&mut self, handler: F)
Add an event handler to the window.
sourcepub fn transform(&self) -> Affine2
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.
sourcepub fn effective_transform(&self) -> Affine2
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.
sourcepub fn set_transform(&mut self, transform: Affine2)
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.
sourcepub fn pre_apply_transform(&mut self, transform: Affine2)
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.
sourcepub fn post_apply_transform(&mut self, transform: Affine2)
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.