Skip to main content

App

Trait App 

Source
pub trait App<B: Backend> {
    // Required method
    fn update(&mut self, term: &mut Terminal<B>, frame: &Frame) -> Flow;
}
Expand description

The per-frame update contract for a game.

Implement this once, generically over the backend, to run everywhere:

use retroglyph_core::app::{App, Flow, Frame};
use retroglyph_core::backend::Backend;
use retroglyph_core::color::Style;
use retroglyph_core::terminal::Terminal;

struct MyGame;
impl<B: Backend> App<B> for MyGame {
    fn update(&mut self, term: &mut Terminal<B>, _frame: &Frame) -> Flow {
        term.surface().put((0, 0), '@', Style::default());
        Flow::Exit
    }
}

Required Methods§

Source

fn update(&mut self, term: &mut Terminal<B>, frame: &Frame) -> Flow

Advance and render one frame.

Draw into term, read input via term, and return Flow::Exit to stop the loop.

Draw via term.surface() or term.draw() (though draw presents itself, which usually conflicts with the driver’s own automatic present below; prefer surface() inside update). Every driver (run_blocking and retroglyph-window’s windowed drivers) presents the frame automatically right after this method returns, unless it returned Flow::Idle, in which case the driver skips present entirely. Calling present yourself inside update remains fine (the driver detects it already ran via present_count and skips its own call) but is never required. run_blocking and run_blocking_with link back here rather than restating this contract.

Implementors§