Skip to main content

Canvas

Struct Canvas 

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

A framebuffer for one GPU’s screen; see the module docs.

Implementations§

Source§

impl Canvas

Source

pub fn new(gpu: Gpu) -> Result<Canvas>

A canvas the size of the GPU’s current resolution, at its deepest colour depth.

Source

pub fn with_size(gpu: Gpu, w: usize, h: usize) -> Canvas

A canvas of w x h cells, drawn from the screen’s top left corner. Makes no GPU calls until Canvas::present.

Source

pub fn width(&self) -> usize

Width in cells.

Source

pub fn height(&self) -> usize

Height in cells.

Source

pub fn gpu(&self) -> &Gpu

Source

pub fn double_buffered(&mut self, on: bool) -> Result<bool>

Composes each present in a GPU buffer and copies it to the screen in one bitblt, so the screen never shows a half-drawn frame. Returns false (and keeps drawing directly) if the GPU has no video memory to spare. double_buffered(false) frees the buffer.

Source

pub fn invalidate(&mut self)

Forgets what the screen shows, so the next present redraws every cell. Call it after anything else draws on the screen.

Source

pub fn get(&self, x: i64, y: i64) -> Option<(char, Rgb, Rgb)>

The character and colours of cell (x, y).

Source

pub fn set(&mut self, x: i64, y: i64, ch: char, fg: Rgb, bg: Rgb)

Sets one cell.

Source

pub fn clear(&mut self, bg: Rgb)

Every cell blank in bg.

Source

pub fn fill( &mut self, x: i64, y: i64, w: i64, h: i64, ch: char, fg: Rgb, bg: Rgb, )

Fills a rectangle of cells with ch.

Source

pub fn text(&mut self, x: i64, y: i64, text: &str, fg: Rgb, bg: Rgb)

Writes text from cell (x, y) rightwards, clipped at the edge.

Source

pub fn text_centered(&mut self, y: i64, text: &str, fg: Rgb, bg: Rgb)

text centred on row y.

Source

pub fn text_vertical(&mut self, x: i64, y: i64, text: &str, fg: Rgb, bg: Rgb)

Writes text from cell (x, y) downwards.

Source

pub fn pixels(&mut self) -> Pixels<'_>

The canvas as half-block pixels: width() x height() * 2.

Source

pub fn dots(&mut self) -> Dots<'_>

The canvas as braille dots: width() * 2 x height() * 4.

Source

pub fn present(&mut self) -> Result<usize>

Sends what changed since the last present to the screen. Returns the number of GPU calls it made.

Source

pub async fn present_async(&mut self) -> Result<usize>

Canvas::present without blocking: every call is queued at once (they run in order), and other tasks keep running. Requires the async feature; see crate::task.

Trait Implementations§

Source§

impl Drop for Canvas

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Forget for Canvas

§

impl Freeze for Canvas

§

impl Move for Canvas

§

impl RefUnwindSafe for Canvas

§

impl Send for Canvas

§

impl Sync for Canvas

§

impl Unpin for Canvas

§

impl UnsafeUnpin for Canvas

§

impl UnwindSafe for Canvas

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.