Skip to main content

Canvas

Trait Canvas 

Source
pub trait Canvas {
Show 14 methods // Required methods fn pixel(&mut self, x: usize, y: usize, color: CanvasColor); fn glyph_at(&self, col: usize, row: usize) -> char; fn color_at(&self, col: usize, row: usize) -> CanvasColor; fn char_width(&self) -> usize; fn char_height(&self) -> usize; fn pixel_width(&self) -> usize; fn pixel_height(&self) -> usize; fn transform(&self) -> &Transform2D; fn transform_mut(&mut self) -> &mut Transform2D; // Provided methods fn point(&mut self, x: f64, y: f64, color: CanvasColor) { ... } fn points(&mut self, xs: &[f64], ys: &[f64], color: CanvasColor) { ... } fn line(&mut self, x1: f64, y1: f64, x2: f64, y2: f64, color: CanvasColor) { ... } fn lines(&mut self, xs: &[f64], ys: &[f64], color: CanvasColor) { ... } fn row_cells( &self, row: usize, ) -> impl Iterator<Item = (char, CanvasColor)> + '_ { ... }
}
Expand description

A drawable pixel grid that maps data-space coordinates to Unicode characters.

Each canvas type maps characters to a grid of sub-character pixels (e.g., braille uses 2x4 pixels per character) and composites colors additively via CanvasColor.

Required Methods§

Source

fn pixel(&mut self, x: usize, y: usize, color: CanvasColor)

Sets a single pixel at the given pixel coordinates.

Source

fn glyph_at(&self, col: usize, row: usize) -> char

Returns the Unicode glyph for the character cell at (col, row).

Source

fn color_at(&self, col: usize, row: usize) -> CanvasColor

Returns the composited color for the character cell at (col, row).

Source

fn char_width(&self) -> usize

The number of character columns in this canvas.

Source

fn char_height(&self) -> usize

The number of character rows in this canvas.

Source

fn pixel_width(&self) -> usize

The total pixel width (character columns times pixels per character).

Source

fn pixel_height(&self) -> usize

The total pixel height (character rows times pixels per character).

Source

fn transform(&self) -> &Transform2D

Returns a reference to this canvas’s coordinate transform.

Source

fn transform_mut(&mut self) -> &mut Transform2D

Returns a mutable reference to this canvas’s coordinate transform.

Provided Methods§

Source

fn point(&mut self, x: f64, y: f64, color: CanvasColor)

Plots a single data-space point, transforming it to pixel coordinates.

Source

fn points(&mut self, xs: &[f64], ys: &[f64], color: CanvasColor)

Plots multiple data-space points. Silently ignores mismatched lengths.

Source

fn line(&mut self, x1: f64, y1: f64, x2: f64, y2: f64, color: CanvasColor)

Draws a line between two data-space points using DDA rasterization.

Source

fn lines(&mut self, xs: &[f64], ys: &[f64], color: CanvasColor)

Draws connected line segments through consecutive point pairs.

Source

fn row_cells( &self, row: usize, ) -> impl Iterator<Item = (char, CanvasColor)> + '_

Iterates over (glyph, color) pairs for all cells in a character row.

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.

Implementors§