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

Handle to the global context.

You can interact with the global context through a ContextHandle only from the global context thread. To interact with the context from a different thread, use a ContextProxy.

Implementations§

source§

impl<'a> ContextHandle<'a>

source

pub fn proxy(&self) -> ContextProxy

Get a proxy for the context 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 set_exit_with_last_window(&mut self, exit_with_last_window: bool)

Exit the program when the last window closes.

source

pub fn window( &mut self, window_id: WindowId ) -> Result<WindowHandle<'_>, InvalidWindowId>

Get a window handle for the given window ID.

source

pub fn create_window( &mut self, title: impl Into<String>, options: WindowOptions ) -> Result<WindowHandle<'_>, CreateWindowError>

Create a new window.

source

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

Add a global event handler.

source

pub fn run_background_task<F>(&mut self, task: F)
where F: FnOnce() + Send + 'static,

Run a task in a background thread and register it with the context.

The task will be executed in a different thread than the context. Currently, each task is spawned in a separate thread. In the future, tasks may be run in a dedicated thread pool.

The background task will be joined before the process is terminated when you use Self::exit() or one of the other exit functions of this crate.

source

pub fn exit(&mut self, code: i32) -> !

Join all background tasks and then exit the process.

If you use std::process::exit, running background tasks may be killed. To ensure no data loss occurs, you should use this function instead.

Background tasks are spawned when an image is saved through the built-in Ctrl+S or Ctrl+Shift+S shortcut, or by user code.

Auto Trait Implementations§

§

impl<'a> Freeze for ContextHandle<'a>

§

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

§

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

§

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

§

impl<'a> Unpin for ContextHandle<'a>

§

impl<'a> !UnwindSafe for ContextHandle<'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