pub trait Backend {
// Required methods
fn draw<'a, I>(&mut self, content: I)
where I: Iterator<Item = (Pos, &'a Tile)>;
fn flush(&mut self);
fn size(&self) -> Size;
fn clear(&mut self);
fn poll_event(&mut self, timeout: Duration) -> Option<Event>;
fn set_cursor_visible(&mut self, visible: bool);
fn set_cursor_position(&mut self, position: Pos);
// Provided methods
fn draw_layers<'a, I>(&mut self, content: I)
where I: Iterator<Item = (u8, Pos, &'a Tile)> { ... }
fn needs_full_frame(&self) -> bool { ... }
fn resize(&mut self, size: Size) { ... }
fn is_connected(&self) -> bool { ... }
fn push_event(&mut self, _event: Event) { ... }
}Expand description
A rendering backend that presents grid content to a display and provides input events.
Required Methods§
Sourcefn poll_event(&mut self, timeout: Duration) -> Option<Event>
fn poll_event(&mut self, timeout: Duration) -> Option<Event>
Poll for an input event, waiting up to timeout.
Sourcefn set_cursor_visible(&mut self, visible: bool)
fn set_cursor_visible(&mut self, visible: bool)
Show or hide the cursor.
Sourcefn set_cursor_position(&mut self, position: Pos)
fn set_cursor_position(&mut self, position: Pos)
Move the cursor to a position.
Provided Methods§
Sourcefn draw_layers<'a, I>(&mut self, content: I)
fn draw_layers<'a, I>(&mut self, content: I)
Draw changed cells across all layers.
The default implementation forwards layer-0 tiles to draw
and ignores higher layers. Override this to support multi-layer
compositing, sub-cell offsets, or transparency.
When needs_full_frame returns true, this
receives all cells from every allocated layer, and the backend
should clear its output surface before drawing.
Sourcefn needs_full_frame(&self) -> bool
fn needs_full_frame(&self) -> bool
Returns true if the backend needs the entire frame (all cells on
all layers) on every call to draw_layers, rather
than just the changed cells.
Pixel-based backends (e.g. SoftwareRenderer) need this because
sub-cell offsets can spill glyph pixels into adjacent cells — without
a full redraw, orphaned pixels from the previous frame linger.
The default implementation returns false.
Sourcefn resize(&mut self, size: Size)
fn resize(&mut self, size: Size)
Notify the backend of a terminal resize.
Called automatically by crate::Terminal::resize after both grids are resized.
Backends that maintain internal state tied to terminal dimensions (such as
Headless) should override this to update that state. The default
implementation is a no-op.
Sourcefn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Returns false if the backend has been disconnected from its
output (e.g. the window was closed). The game loop should
terminate when this returns false.
The default implementation always returns true. Override for
backends that can detect disconnect.
Sourcefn push_event(&mut self, _event: Event)
fn push_event(&mut self, _event: Event)
Push an event into the backend’s event buffer.
Backends that receive events externally (e.g., from a window event
loop or a test harness) override this to queue events for
poll_event. The default is a no-op.
- Windowed backends: called by
ApplicationHandleron each event. - Headless: called by tests to inject synthetic events.
- Crossterm: reads from its own event stream; no-op here.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.