pub struct UiRunner<T> { /* private fields */ }Expand description
Run code on the UI thread from another thread.
Allows you to mix non-blocking threaded code, with code that reads and updates your widget in the UI thread.
This can be copied and passed around.
Implementations§
Source§impl<T> UiRunner<T>where
T: 'static,
impl<T> UiRunner<T>where
T: 'static,
Sourcepub fn new(key: usize) -> UiRunner<T>
pub fn new(key: usize) -> UiRunner<T>
Create a new UiRunner that dispatches functions as global actions but
differentiates them by the provided key.
If used in a widget, prefer using your_widget.ui_runner().
If used in your app main, prefer using your_app_main.ui_runner().
Sourcepub fn handle(
self,
cx: &mut Cx,
event: &Event,
scope: &mut Scope<'_, '_>,
target: &mut T,
)
pub fn handle( self, cx: &mut Cx, event: &Event, scope: &mut Scope<'_, '_>, target: &mut T, )
Handle all functions scheduled with the key of this UiRunner.
You should call this once from your handle_event method, like:
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
// ... handle other stuff ...
self.ui_runner().handle(cx, event, scope, self);
}Once a function has been handled, it will never run again.
Sourcepub fn defer(self, f: impl DeferCallback<T>)
pub fn defer(self, f: impl DeferCallback<T>)
Schedule the provided closure to run on the UI thread.
Sourcepub fn block_on<R>(
self,
f: impl FnOnce(&mut T, &mut Cx, &mut Scope<'_, '_>) -> R + Send + 'static,
) -> Rwhere
R: Send + 'static,
pub fn block_on<R>(
self,
f: impl FnOnce(&mut T, &mut Cx, &mut Scope<'_, '_>) -> R + Send + 'static,
) -> Rwhere
R: Send + 'static,
Like defer, but blocks the current thread until the UI awakes, processes
the closure, and returns the result.
Generally, you should prefer to use defer if you don’t need to communicate
a value back. This method may wait a long time if the UI thread is busy so you
should not use it in tight loops.
Trait Implementations§
Source§impl<W: Widget + 'static> DeferWithRedraw<W> for UiRunner<W>
impl<W: Widget + 'static> DeferWithRedraw<W> for UiRunner<W>
Source§fn defer_with_redraw(self, f: impl DeferCallback<W>)
fn defer_with_redraw(self, f: impl DeferCallback<W>)
defer but calls redraw on the widget after the closure is run.