pub struct PumpRunner<A: App> { /* private fields */ }Expand description
A windowed runner driven from outside: same [Shell] as Launcher::run
(input mapping, IME, clipboard, chrome, caret blink), but the host calls
pump on its own cadence instead of parking in run_app.
Typed by its app for app_mut and
route_events alone: every method hands the
shell on unsized, so the work is compiled once in kui rather than in
every crate that opens one (backlog C49).
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
are the pump rate over that second, which is what a driver’s
backoff promises and what frame_stats cannot say (backlog F62).
Which 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. It is what makes
next_deadline answer “now” after a pump,
counted (backlog F94). Monotonic, and never more than pumps.
Two readings a second apart with this one unmoved are a second the desktop left the window alone: whatever it drew was the app’s own doing — a tick, a caret blink, a transition, the audio poll. A moved one is the desktop or a person reaching in, which resets a driver’s backoff exactly as a regression would, so an idle-window test that sees it move re-measures instead of failing.
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 (backlog C21).
Returns false once the main window has closed.
Sourcepub fn next_deadline(&self) -> Option<Instant>
pub fn next_deadline(&self) -> Option<Instant>
When the shell next needs pumping, as the last pump
left it — None when nothing it knows about is due, which is
ControlFlow::Wait for a loop that owns itself.
A host driving from a foreign loop has to guess how long to leave between pumps, and the guess is what pays: a caret blink, a tick, a transition’s next frame, the audio poll and a window’s first-frame retry are all deadlines the shell has already worked out, and a driver on a fixed interval hits them a whole interval late. Ask after each pump and sleep to the answer instead.
What it does not say is whether an OS event is waiting — nothing short of pumping can — so a driver still needs a ceiling of its own. This only ever tells it 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.
pub fn app_mut(&mut self) -> &mut A
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
(Shell::route_events, ADR 0014 decision 6): an extension’s event
to the extension, and what it replies to to_app carrying its
origin. A host that drives the core directly — core_mut().press,
an access action, a drained take_pending_events — produces events
the loop never saw, and pushing those at the app would hand it a
plugin’s clicks and leave the plugin deaf to them.
to_app is lent the core of the window each event came from, as
the runner’s own loop lends it to App::on_event_with (ADR 0036).
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 (backlog AR12).
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 — through
core_mut().host_area(size), which is what the next frame lays out
against: the window less the devtools’ dock while the panel is
docked (docs/adr/0024), and the window itself otherwise.
Sourcepub fn request_redraw(&self)
pub fn request_redraw(&self)
Schedules a redraw of every window (call after changing what view
will produce). Under Launcher::deferred_events it is also what
ends a frame’s wait: the host calling this is the host saying its
view is current, so the frame that was waiting can be painted now —
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 hosts that call Core::play between
pumps and want 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.