Skip to main content

Renderer

Struct Renderer 

Source
pub struct Renderer { /* private fields */ }
Expand description

High-level WebGL2 renderer for terminal-style applications.

The Renderer manages the WebGL2 rendering context, canvas, and provides a simplified interface for rendering drawable objects. It handles frame management, viewport setup, and coordinate system transformations.

Implementations§

Source§

impl Renderer

Source

pub fn create( canvas_id: &str, auto_resize_canvas_css: bool, ) -> Result<Self, Error>

Creates a new renderer by querying for a canvas element with the given ID.

Source

pub fn canvas_padding_color(self, color: u32) -> Self

Sets the background color for the canvas area outside the terminal grid.

Source

pub fn create_with_canvas( canvas: HtmlCanvasElement, auto_resize_canvas_css: bool, ) -> Result<Self, Error>

Creates a new renderer from an existing HTML canvas element.

Source

pub fn resize(&mut self, width: i32, height: i32)

Resizes the canvas and updates the viewport.

Source

pub fn clear(&mut self, r: f32, g: f32, b: f32)

Clears the framebuffer with the specified color.

Source

pub fn begin_frame(&mut self)

Begins a new rendering frame.

Source

pub fn render(&mut self, drawable: &impl Drawable) -> Result<(), Error>

Renders a drawable object.

Source

pub fn end_frame(&mut self)

Ends the current rendering frame.

Source

pub fn gl(&self) -> &Context

Returns a reference to the glow rendering context.

Source

pub fn canvas(&self) -> &HtmlCanvasElement

Returns a reference to the HTML canvas element.

Source

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

Returns the current canvas dimensions as a tuple.

Source

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

Returns the logical size of the canvas in pixels.

Source

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

Returns the physical size of the canvas in pixels, taking into account the device pixel ratio.

Source

pub fn is_context_lost(&self) -> bool

Checks if the WebGL context has been lost.

Source

pub fn restore_context(&mut self) -> Result<(), Error>

Restores the WebGL context after a context loss event.

Trait Implementations§

Source§

impl Debug for Renderer

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.