Skip to main content

frame

Function frame 

Source
pub fn frame(
    backend: &mut impl Backend,
    state: &mut AppState,
    config: &RunConfig,
    events: &[Event],
    f: &mut impl FnMut(&mut Context),
) -> Result<bool>
Expand description

Process a single UI frame with a custom Backend.

This is the low-level entry point for custom backends. For standard terminal usage, prefer run() or run_with() which handle the event loop, terminal setup, and teardown automatically.

Returns Ok(true) to continue, Ok(false) when Context::quit() was called.

§Arguments

  • backend — Your Backend implementation
  • state — Persistent AppState (reuse across frames)
  • configRunConfig (theme, tick rate, etc.)
  • events — Input events for this frame (keyboard, mouse, resize)
  • f — Your UI closure, called once per frame

Build a fresh event slice each frame in your outer loop, then pass it here. frame() reads from that slice but does not own your event source. Reuse the same AppState for the lifetime of the session.

§Example

let keep_going = slt::frame(
    &mut my_backend,
    &mut state,
    &config,
    &events,
    &mut |ui| { ui.text("hello"); },
)?;