Skip to main content

DrawContext

Struct DrawContext 

Source
pub struct DrawContext<'a> { /* private fields */ }
Expand description

A context for drawing on a canvas (character-based)

Implementations§

Source§

impl<'a> DrawContext<'a>

Source

pub fn new(buffer: &'a mut Buffer, area: Rect) -> Self

Create a new draw context

Source

pub fn width(&self) -> u16

Get canvas width

Source

pub fn height(&self) -> u16

Get canvas height

Source

pub fn area(&self) -> Rect

Get canvas area

Source

pub fn set(&mut self, x: u16, y: u16, ch: char)

Set a character at position

Source

pub fn set_styled( &mut self, x: u16, y: u16, ch: char, fg: Option<Color>, bg: Option<Color>, )

Set a character with style at position

Source

pub fn set_cell(&mut self, x: u16, y: u16, cell: Cell)

Set a cell at position

Source

pub fn hline( &mut self, x: u16, y: u16, length: u16, ch: char, fg: Option<Color>, )

Draw a horizontal line

Source

pub fn vline( &mut self, x: u16, y: u16, length: u16, ch: char, fg: Option<Color>, )

Draw a vertical line

Source

pub fn rect( &mut self, x: u16, y: u16, width: u16, height: u16, fg: Option<Color>, )

Draw a rectangle outline

Source

pub fn fill_rect( &mut self, rect: Rect, ch: char, fg: Option<Color>, bg: Option<Color>, )

Fill a rectangle

Source

pub fn bar(&mut self, x: u16, y: u16, width: u16, fg: Color, bg: Option<Color>)

Draw a filled bar (for Gantt charts, progress bars, etc.)

Source

pub fn partial_bar(&mut self, x: u16, y: u16, width: f32, fg: Color)

Draw a partial bar (for fractional values)

Source

pub fn text(&mut self, x: u16, y: u16, s: &str, fg: Option<Color>)

Draw text at position

Source

pub fn text_bold(&mut self, x: u16, y: u16, s: &str, fg: Option<Color>)

Draw bold text at position

Source

pub fn clear(&mut self)

Clear the canvas

Source

pub fn point(&mut self, x: u16, y: u16, fg: Color)

Draw a point/dot

Source

pub fn line( &mut self, x0: u16, y0: u16, x1: u16, y1: u16, ch: char, fg: Option<Color>, )

Draw a line between two points (Bresenham’s algorithm)

Auto Trait Implementations§

§

impl<'a> Freeze for DrawContext<'a>

§

impl<'a> RefUnwindSafe for DrawContext<'a>

§

impl<'a> Send for DrawContext<'a>

§

impl<'a> Sync for DrawContext<'a>

§

impl<'a> Unpin for DrawContext<'a>

§

impl<'a> !UnwindSafe for DrawContext<'a>

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.