Struct show_image::WindowProxy
source · pub struct WindowProxy { /* private fields */ }
Expand description
Proxy object to interact with a window from a user thread.
The proxy object only exposes a small subset of the functionality of a window.
However, you can use run_function()
to get access to the underlying WindowHandle
from the context thread.
With run_function_wait()
you can also get the return value of the function back:
let inner_size = window_proxy.run_function_wait(|window| window.inner_size())?;
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.
Implementations§
source§impl WindowProxy
impl WindowProxy
sourcepub fn new(window_id: WindowId, context_proxy: ContextProxy) -> Self
pub fn new(window_id: WindowId, context_proxy: ContextProxy) -> Self
Create a new window proxy from a context proxy and a window ID.
sourcepub fn context_proxy(&self) -> &ContextProxy
pub fn context_proxy(&self) -> &ContextProxy
Get the context proxy of the window proxy.
sourcepub fn set_image(
&self,
name: impl Into<String>,
image: impl Into<Image>
) -> Result<(), SetImageError>
pub fn set_image( &self, name: impl Into<String>, image: impl Into<Image> ) -> Result<(), SetImageError>
Set the displayed image of the window.
The real work is done in the context thread. This function blocks until the context thread has performed the action.
Note that you can not change the overlays with this function.
To modify those, you can use Self::run_function
or Self::run_function_wait
to get access to the WindowHandle
.
§Panics
This function will panic if called from within the context thread.
sourcepub fn add_event_handler<F>(&self, handler: F) -> Result<(), InvalidWindowId>
pub fn add_event_handler<F>(&self, handler: F) -> Result<(), InvalidWindowId>
Add an event handler for the window.
Events that are already queued with the event loop will not be passed to the handler.
This function uses ContextProxy::run_function_wait
internally, so it blocks until the event handler is added.
To avoid blocking, you can use ContextProxy::run_function
to post a lambda that adds an event handler instead.
§Panics
This function will panic if called from within the context thread.
sourcepub fn event_channel(&self) -> Result<Receiver<WindowEvent>, InvalidWindowId>
pub fn event_channel(&self) -> Result<Receiver<WindowEvent>, InvalidWindowId>
Create a channel that receives events from the window.
To close the channel, simply drop de receiver. The channel is closed automatically when the window is destroyed.
Warning: The created channel blocks when you request an event until one is available. You should never use the receiver from within an event handler or a function posted to the global context thread. Doing so would cause a deadlock.
§Panics
This function will panic if called from within the context thread.
sourcepub fn wait_until_destroyed(&self) -> Result<(), InvalidWindowId>
pub fn wait_until_destroyed(&self) -> Result<(), InvalidWindowId>
Wait for the window to be destroyed.
This can happen if the application code destroys the window or if the user closes the window.
Warning: This function blocks until the window is closed. You should never use this function from within an event handler or a function posted to the global context thread. Doing so would cause a deadlock.
§Panics
This function will panic if called from within the context thread.
sourcepub fn run_function<F>(&self, function: F)
pub fn run_function<F>(&self, function: F)
Post a function for execution in the context thread without waiting for it to execute.
This function returns immediately, without waiting for the posted function to start or complete.
If you want to get a return value back from the function, use Self::run_function_wait
instead.
Note:
You should not use this to post functions that block for a long time.
Doing so will block the event loop and will make the windows unresponsive until the event loop can continue.
Consider using self.context_proxy().run_background_task(...)
for long blocking tasks instead.
§Panics
This function will panic if called from within the context thread.
sourcepub fn run_function_wait<F, T>(&self, function: F) -> Result<T, InvalidWindowId>
pub fn run_function_wait<F, T>(&self, function: F) -> Result<T, InvalidWindowId>
Post a function for execution in the context thread and wait for the return value.
If you do not need a return value from the posted function,
you can use Self::run_function
to avoid blocking the calling thread until it completes.
Note:
You should not use this to post functions that block for a long time.
Doing so will block the event loop and will make the windows unresponsive until the event loop can continue.
Consider using self.context_proxy().run_background_task(...)
for long blocking tasks instead.
§Panics
This function will panic if called from within the context thread.
Trait Implementations§
source§impl Clone for WindowProxy
impl Clone for WindowProxy
source§fn clone(&self) -> WindowProxy
fn clone(&self) -> WindowProxy
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more