pub struct PumpRunner<A: App> { /* private fields */ }Expand description
A windowed runner driven from outside, from Launcher::open: the
same runner as Launcher::run (input mapping, IME, clipboard, chrome,
caret blink), but the host calls pump or
pump_until on its own cadence instead of parking
in the event loop.
Ask next_deadline after each pump for how long
to sleep, and request_redraw after changing
what view will produce. The runner ends when the main window closes;
dropping it earlier closes the windows and parks the loop for the next
open.
Implementations§
Source§impl<A: App> PumpRunner<A>
impl<A: App> PumpRunner<A>
Sourcepub fn pump(&mut self) -> bool
pub fn pump(&mut self) -> bool
Processes all pending OS events without blocking. Returns false once the main window has closed — and from that pump on the windows are gone and the loop is parked for the next runner; further pumps are no-ops.
Sourcepub fn pumps(&self) -> u64
pub fn pumps(&self) -> u64
How many turns this runner has taken, the one that opened the
window included: every pump and pump_until that ran, not the
no-ops after it retired. Monotonic, so two readings a second apart
give the pump rate over that second. How many of them something
outside the app caused is woken_pumps.
Sourcepub fn woken_pumps(&self) -> u64
pub fn woken_pumps(&self) -> u64
How many of those pumps found an OS event or a
wake in their batch: any window event but a redraw (a key, the
pointer crossing the window, a focus change, a resize, the window
moved or occluded), or anything that came through the loop’s proxy
(a Waker::wake, assistive technology asking, a file dialog’s
answer). Monotonic, and never more than pumps.
Unmoved over a second, the desktop left the window alone and whatever it drew was the app’s own doing; moved, the desktop or a person reached in, so an idle-window measurement should restart rather than fail.
Sourcepub fn pump_until(&mut self, deadline: Instant) -> bool
pub fn pump_until(&mut self, deadline: Instant) -> bool
pump, but parked until an OS event, a
Waker::wake or deadline, whichever comes first, so a host that
owns the loop blocks on all three instead of polling on a timer.
Returns false once the main window has closed.
Sourcepub fn next_deadline(&self) -> Option<Instant>
pub fn next_deadline(&self) -> Option<Instant>
When the runner next needs pumping, as the last pump
left it: a caret blink, a tick, a transition’s next frame, the audio
poll or a first-frame retry. None when nothing it knows about is
due. Ask after each pump and sleep until the answer rather than
pumping on a fixed interval.
It does not say whether an OS event is waiting, since nothing short of pumping can, so a driver still needs a ceiling of its own; this only ever says to come back sooner.
Sourcepub fn waker(&self) -> Waker
pub fn waker(&self) -> Waker
A Waker for this loop, to clone into the threads the host’s
data arrives on.
Sourcepub fn app_mut(&mut self) -> &mut A
pub fn app_mut(&mut self) -> &mut A
The app, for a host that reads or changes its state between pumps.
Sourcepub fn route_events(
&mut self,
events: impl IntoIterator<Item = UiEvent>,
to_app: impl FnMut(&mut A, UiEvent, &mut Core),
)
pub fn route_events( &mut self, events: impl IntoIterator<Item = UiEvent>, to_app: impl FnMut(&mut A, UiEvent, &mut Core), )
Delivers events the way this runner’s own loop does: an
extension’s event to the extension, and the rest, with whatever the
extension replied, to to_app. Use it for events the loop never
saw, such as those a host produced by driving the core directly
(core_mut().press, an access action, a drained
take_pending_events); pushing those straight at the app would
hand it an extension’s clicks and leave the extension deaf to them.
to_app is lent the core of the window each event came from, as
App::on_event_with is.
Sourcepub fn core_mut(&mut self) -> &mut Core
pub fn core_mut(&mut self) -> &mut Core
The main window’s core. Every window of the app shares its session,
so resources registered through it draw in all of them, and
Core::windows on it lists them.
Sourcepub fn core_mut_of(&mut self, id: WindowId) -> Option<&mut Core>
pub fn core_mut_of(&mut self, id: WindowId) -> Option<&mut Core>
The core of the window id names, if that window is open; the main
window’s for WindowId::MAIN. Everything that is one window’s
rather than the session’s (its focus, its editors’ text, its scroll
offsets, its tokens) is answered by this core and no other.
Sourcepub fn window_id(&mut self, name: &str) -> Option<WindowId>
pub fn window_id(&mut self, name: &str) -> Option<WindowId>
The id of the open window named name ("main" for the launcher’s),
or None while no window of that name is open — before its first
frame’s diff, or after the user closed it.
Sourcepub fn window_size(&self) -> (Size, f32)
pub fn window_size(&self) -> (Size, f32)
The main window’s inner size (logical px) and its scale factor.
Unlike core_mut().viewport() this is known before the first frame,
so a host can size its model at setup. core_mut().host_area(size)
is what the next frame lays out against: the window less the
devtools’ dock while the panel is docked, the window otherwise.
Sourcepub fn request_redraw(&self)
pub fn request_redraw(&self)
Schedules a redraw of every window; call it after changing what
view will produce. Under Launcher::deferred_events it also
ends a frame’s wait: the host is saying its view is current, so the
waiting frame is painted with the answer in it.
Sourcepub fn request_exit(&mut self)
pub fn request_exit(&mut self)
Asks the app to close; the next pump observes it and returns false.
Sourcepub fn flush_audio(&mut self)
pub fn flush_audio(&mut self)
Hands the core’s queued audio commands to the device now rather than
at the next pump, for a host that calls Core::play between pumps
and wants the sound to start at once.
Trait Implementations§
Auto Trait Implementations§
impl<A> !Freeze for PumpRunner<A>
impl<A> !RefUnwindSafe for PumpRunner<A>
impl<A> !Send for PumpRunner<A>
impl<A> !Sync for PumpRunner<A>
impl<A> !UnwindSafe for PumpRunner<A>
impl<A> Unpin for PumpRunner<A>
impl<A> UnsafeUnpin for PumpRunner<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.