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>
impl<'a> Canvas<'a>
Sourcepub fn begin(cache: &'a mut GlyphCache, out: &'a mut InstanceBuffer) -> Self
pub fn begin(cache: &'a mut GlyphCache, out: &'a mut InstanceBuffer) -> Self
Starts a frame: clears out and begins a frame on cache.
Sourcepub fn state(&self) -> CanvasState
pub fn state(&self) -> CanvasState
The current translation and clip, to restore later.
Sourcepub fn restore(&mut self, state: CanvasState)
pub fn restore(&mut self, state: CanvasState)
Brings back a translation and clip saved with state.
Sourcepub fn clip(&mut self, rect: Rect)
pub fn clip(&mut self, rect: Rect)
Draws from now on only inside rect (in current coordinates), within the current
clip.
Sourcepub fn clip_rect(&self) -> Rect
pub fn clip_rect(&self) -> Rect
The area drawing still shows in, in current coordinates; empty when everything is clipped away.
Sourcepub fn draw_glyph(
&mut self,
font: &Font,
glyph: GlyphId,
px: f32,
at: Point,
color: Color,
)
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).
Sourcepub fn draw_run(&mut self, run: GlyphRun<'_>, origin: Point)
pub fn draw_run(&mut self, run: GlyphRun<'_>, origin: Point)
Every glyph of run, offset by origin.
Sourcepub fn cache(&self) -> &GlyphCache
pub fn cache(&self) -> &GlyphCache
The glyph cache this frame draws through.
Sourcepub fn instances(&self) -> &InstanceBuffer
pub fn instances(&self) -> &InstanceBuffer
The instances emitted so far this frame.