Struct TerminalGrid

Source
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

Source

pub fn new( gl: &WebGl2RenderingContext, atlas: FontAtlas, screen_size: (i32, i32), ) -> Result<Self, Error>

Source

pub fn cell_size(&self) -> (i32, i32)

Returns the unpadded cell dimensions in pixels.

Source

pub fn terminal_size(&self) -> (u16, u16)

Returns the size of the terminal grid in pixels.

Source

pub fn cell_count(&self) -> usize

Returns the total number of cells in the terminal grid.

Source

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 context
  • cells - Iterator providing CellData for each cell in the grid
§Returns
  • Ok(()) - Successfully updated cell data
  • Err(Error) - Failed to update buffer or other WebGL error
Source

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 context
  • canvas_size - New canvas dimensions in pixels as (width, height)
§Returns
  • Ok(()) - Successfully resized the terminal
  • Err(Error) - Failed to recreate buffers or other WebGL error

Trait Implementations§

Source§

impl Debug for TerminalGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.