Skip to main content

Canvas

Struct Canvas 

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

One frame being drawn: everything painters emit goes through it.

Canvas::begin starts the frame on both the instance list and the glyph cache, so the cache’s “used this frame” protection spans every painter of the frame: a glyph drawn by one painter cannot be evicted by the next. One glyph cache serves every painter of a frame loop and its updates feed one GPU atlas (densa_render::GpuRenderer).

Positions go through a translation and are clipped to a rectangle (see translate and clip); state and restore save and bring back both, as a widget does around its children. Clipping happens here, on each rectangle and glyph, so a frame stays one draw call.

Allocation-free once the frame’s glyphs are cached.

Implementations§

Source§

impl<'a> Canvas<'a>

Source

pub fn begin(cache: &'a mut GlyphCache, out: &'a mut InstanceBuffer) -> Self

Starts a frame: clears out and begins a frame on cache.

Source

pub fn state(&self) -> CanvasState

The current translation and clip, to restore later.

Source

pub fn restore(&mut self, state: CanvasState)

Brings back a translation and clip saved with state.

Source

pub fn translate(&mut self, dx: f32, dy: f32)

Moves everything drawn from now on by dx, dy.

Source

pub fn clip(&mut self, rect: Rect)

Draws from now on only inside rect (in current coordinates), within the current clip.

Source

pub fn clip_rect(&self) -> Rect

The area drawing still shows in, in current coordinates; empty when everything is clipped away.

Source

pub fn fill_rect(&mut self, rect: Rect, color: Color)

A filled rectangle.

Source

pub fn draw_glyph( &mut self, font: &Font, glyph: GlyphId, px: f32, at: Point, color: Color, )

glyph of font at px pixels per em, its pen at at: x is the pen position (fractional: drawn at the nearest subpixel bin), y the baseline (rounded to a whole pixel).

Glyphs the cache cannot provide this frame are skipped (counted in its stats).

Source

pub fn draw_run(&mut self, run: GlyphRun<'_>, origin: Point)

Every glyph of run, offset by origin.

Source

pub fn cache(&self) -> &GlyphCache

The glyph cache this frame draws through.

Source

pub fn instances(&self) -> &InstanceBuffer

The instances emitted so far this frame.

Trait Implementations§

Source§

impl<'a> Debug for Canvas<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<'a> Freeze for Canvas<'a>

§

impl<'a> RefUnwindSafe for Canvas<'a>

§

impl<'a> Send for Canvas<'a>

§

impl<'a> Sync for Canvas<'a>

§

impl<'a> Unpin for Canvas<'a>

§

impl<'a> UnsafeUnpin for Canvas<'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 = !

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.