pub struct TerminalGrid { /* private fields */ }Expand description
A high-performance terminal grid renderer using instanced rendering.
TerminalGrid renders a grid of terminal cells using WebGL2 instanced drawing.
Each cell can display a character from a font atlas with customizable foreground
and background colors. The renderer uses a 2D texture array to efficiently
store glyph data and supports real-time updates of cell content.
Implementations§
Source§impl TerminalGrid
impl TerminalGrid
pub fn new( gl: &WebGl2RenderingContext, atlas: FontAtlas, screen_size: (i32, i32), ) -> Result<Self, Error>
Sourcepub fn terminal_size(&self) -> (u16, u16)
pub fn terminal_size(&self) -> (u16, u16)
Returns the size of the terminal grid in pixels.
Sourcepub fn cell_count(&self) -> usize
pub fn cell_count(&self) -> usize
Returns the total number of cells in the terminal grid.
Sourcepub fn update_cells<'a>(
&mut self,
gl: &WebGl2RenderingContext,
cells: impl Iterator<Item = CellData<'a>>,
) -> Result<(), Error>
pub fn update_cells<'a>( &mut self, gl: &WebGl2RenderingContext, cells: impl Iterator<Item = CellData<'a>>, ) -> Result<(), Error>
Updates the content of terminal cells with new data.
This method efficiently updates the dynamic instance buffer with new cell data. The iterator must provide exactly the same number of cells as the grid contains, in row-major order.
§Parameters
gl- WebGL2 rendering contextcells- Iterator providingCellDatafor each cell in the grid
§Returns
Ok(())- Successfully updated cell dataErr(Error)- Failed to update buffer or other WebGL error
Sourcepub fn resize(
&mut self,
gl: &WebGl2RenderingContext,
canvas_size: (i32, i32),
) -> Result<(), Error>
pub fn resize( &mut self, gl: &WebGl2RenderingContext, canvas_size: (i32, i32), ) -> Result<(), Error>
Resizes the terminal grid to fit the new canvas dimensions.
This method recalculates the terminal dimensions based on the canvas size and cell dimensions, then recreates the necessary GPU buffers if the grid size changed. Existing cell content is preserved where possible during resizing.
§Parameters
gl- WebGL2 rendering contextcanvas_size- New canvas dimensions in pixels as(width, height)
§Returns
Ok(())- Successfully resized the terminalErr(Error)- Failed to recreate buffers or other WebGL error