pub fn run_app<P, A>(
config: WindowConfig,
presenter: P,
app: A,
) -> Result<(), EventLoopError>Expand description
Drive an App from the windowed event loop.
This is the inverted driver: winit owns the event loop and calls back
into the app on each redraw, rather than the app owning a while loop.
Each frame builds a Frame with a wall-clock
dt measured via web_time::Instant: a plain std::time::Instant
re-export on native, backed by the browser’s Performance.now() on
wasm32 (where std::time::Instant itself is unavailable). Calls
App::update.
On Flow::Exit the event loop exits gracefully
(via [ActiveEventLoop::exit]) instead of force-exiting the process, so
the stack unwinds normally and Drop impls up the call chain (unflushed
writes, GPU/surface teardown, app-level RAII) run before the process
exits. This works the same on wasm: winit’s web backend implements
ActiveEventLoop::exit by stopping its requestAnimationFrame-driven
runner rather than leaving it a no-op.
See https://main.retroglyph.dev/book/explanation/architecture.html#presenting-is-automatic:
this driver presents automatically after each App::update
call, except on Flow::Idle.
§Resizing applies before update runs
This driver resizes the Terminal itself on every window resize, before the next
App::update call, so Terminal::size is never stale
from the app’s point of view even if it never reacts to input. It also pushes
Event::Resize with the new cell dimensions, for an app that wants to react to the change
itself (reflow a layout, regenerate a world) rather than just read the new size on its next
draw.
§Return contract differs on wasm32
On native this call blocks and only returns once the loop reaches
Flow::Exit. On wasm32 it returns Ok(()) immediately
after handing the app to the browser’s requestAnimationFrame-driven runner: the app keeps
running after this call returns, so code that follows it executes concurrently with a live
app rather than after it exits. retroglyph_core::app::run_on_with has no such split;
it always blocks until the app exits, on every target.
§Errors
Returns EventLoopError if the event loop cannot be
created or fails while running.