pub struct DrawContext { /* private fields */ }Expand description
Immediate-mode drawing context used by canvas(size, draw).
Implementations§
Source§impl DrawContext
impl DrawContext
Sourcepub fn bounds(&self) -> Bounds<Pixels>
pub fn bounds(&self) -> Bounds<Pixels>
Returns the canvas-local bounds for the current draw pass.
Sourcepub fn command_count(&self) -> usize
pub fn command_count(&self) -> usize
Number of queued draw commands that have not been flushed to the window.
Sourcepub fn reserve_commands(&mut self, additional: usize)
pub fn reserve_commands(&mut self, additional: usize)
Reserve command storage for a known batch size.
Real-time canvases should call this before emitting large, similarly sized batches to avoid growing the command buffer during a frame.
Sourcepub fn path_count(&self) -> usize
pub fn path_count(&self) -> usize
Number of queued path commands.
Sourcepub fn quad_count(&self) -> usize
pub fn quad_count(&self) -> usize
Number of queued quad commands.
Sourcepub fn filled_quad_count(&self) -> usize
pub fn filled_quad_count(&self) -> usize
Number of queued filled quad commands.
Sourcepub fn stroked_quad_count(&self) -> usize
pub fn stroked_quad_count(&self) -> usize
Number of queued stroked quad commands.
Sourcepub fn text_count(&self) -> usize
pub fn text_count(&self) -> usize
Number of queued text commands.
Sourcepub fn image_count(&self) -> usize
pub fn image_count(&self) -> usize
Number of queued image commands.
Sourcepub fn state_stack_depth(&self) -> usize
pub fn state_stack_depth(&self) -> usize
Number of saved drawing states waiting to be restored.
Sourcepub fn fill_path(&mut self, path: &Path<Pixels>, fill: impl Into<Background>)
pub fn fill_path(&mut self, path: &Path<Pixels>, fill: impl Into<Background>)
Fill an existing path with the given background.
Sourcepub fn stroke_path(&mut self, path: &Path<Pixels>, stroke: Stroke)
pub fn stroke_path(&mut self, path: &Path<Pixels>, stroke: Stroke)
Stroke a path using the retained source outline stored on the path.
Sourcepub fn stroke_line(
&mut self,
from: Point<Pixels>,
to: Point<Pixels>,
stroke: Stroke,
)
pub fn stroke_line( &mut self, from: Point<Pixels>, to: Point<Pixels>, stroke: Stroke, )
Stroke a straight line segment between two points.
Sourcepub fn fill_rect(&mut self, bounds: Bounds<Pixels>, fill: impl Into<Background>)
pub fn fill_rect(&mut self, bounds: Bounds<Pixels>, fill: impl Into<Background>)
Fill an axis-aligned rectangle.
Sourcepub fn fill_rects(
&mut self,
rects: impl IntoIterator<Item = (Bounds<Pixels>, Background)>,
)
pub fn fill_rects( &mut self, rects: impl IntoIterator<Item = (Bounds<Pixels>, Background)>, )
Queue a batch of axis-aligned rectangles with one command-buffer reservation.
Sourcepub fn fill_rounded_rect(
&mut self,
bounds: Bounds<Pixels>,
radii: impl Into<Corners<Pixels>>,
fill: impl Into<Background>,
)
pub fn fill_rounded_rect( &mut self, bounds: Bounds<Pixels>, radii: impl Into<Corners<Pixels>>, fill: impl Into<Background>, )
Fill a rounded rectangle.
Sourcepub fn stroke_rect(&mut self, bounds: Bounds<Pixels>, stroke: Stroke)
pub fn stroke_rect(&mut self, bounds: Bounds<Pixels>, stroke: Stroke)
Stroke the outline of an axis-aligned rectangle (web canvas strokeRect).
Sourcepub fn stroke_rounded_rect(
&mut self,
bounds: Bounds<Pixels>,
radii: impl Into<Corners<Pixels>>,
stroke: Stroke,
)
pub fn stroke_rounded_rect( &mut self, bounds: Bounds<Pixels>, radii: impl Into<Corners<Pixels>>, stroke: Stroke, )
Stroke the outline of a rounded rectangle.
Sourcepub fn fill_circle(
&mut self,
center: Point<Pixels>,
radius: Pixels,
fill: impl Into<Background>,
)
pub fn fill_circle( &mut self, center: Point<Pixels>, radius: Pixels, fill: impl Into<Background>, )
Fill a circle.
Sourcepub fn fill_circles(
&mut self,
circles: impl IntoIterator<Item = (Point<Pixels>, Pixels, Background)>,
)
pub fn fill_circles( &mut self, circles: impl IntoIterator<Item = (Point<Pixels>, Pixels, Background)>, )
Queue a batch of filled circles through the renderer’s rounded-quad fast path.
Sourcepub fn stroke_circle(
&mut self,
center: Point<Pixels>,
radius: Pixels,
stroke: Stroke,
)
pub fn stroke_circle( &mut self, center: Point<Pixels>, radius: Pixels, stroke: Stroke, )
Stroke a circle.
Sourcepub fn fill_ellipse(
&mut self,
center: Point<Pixels>,
radius_x: Pixels,
radius_y: Pixels,
fill: impl Into<Background>,
)
pub fn fill_ellipse( &mut self, center: Point<Pixels>, radius_x: Pixels, radius_y: Pixels, fill: impl Into<Background>, )
Fill an ellipse centered at center with the given horizontal and vertical radii.
Sourcepub fn stroke_ellipse(
&mut self,
center: Point<Pixels>,
radius_x: Pixels,
radius_y: Pixels,
stroke: Stroke,
)
pub fn stroke_ellipse( &mut self, center: Point<Pixels>, radius_x: Pixels, radius_y: Pixels, stroke: Stroke, )
Stroke an ellipse centered at center with the given horizontal and vertical radii.
Sourcepub fn with_transform<R>(
&mut self,
matrix: TransformationMatrix,
f: impl FnOnce(&mut Self) -> R,
) -> R
pub fn with_transform<R>( &mut self, matrix: TransformationMatrix, f: impl FnOnce(&mut Self) -> R, ) -> R
Apply an affine transform to commands issued within the callback.
Sourcepub fn with_opacity<R>(
&mut self,
opacity: f32,
f: impl FnOnce(&mut Self) -> R,
) -> R
pub fn with_opacity<R>( &mut self, opacity: f32, f: impl FnOnce(&mut Self) -> R, ) -> R
Multiply the current drawing opacity for commands issued within the callback.
Sourcepub fn with_clip<R>(
&mut self,
bounds: Bounds<Pixels>,
f: impl FnOnce(&mut Self) -> R,
) -> R
pub fn with_clip<R>( &mut self, bounds: Bounds<Pixels>, f: impl FnOnce(&mut Self) -> R, ) -> R
Restrict drawing to an additional clip rectangle.
Sourcepub fn save(&mut self)
pub fn save(&mut self)
Save the current drawing state (transform, opacity, clip) onto the state stack.
Mirrors CanvasRenderingContext2D.save(). Pair every save with a matching
DrawContext::restore. This is the flat alternative to the scoped
DrawContext::with_transform / DrawContext::with_opacity / DrawContext::with_clip
helpers, for loops and recursion where closures are awkward.
Sourcepub fn restore(&mut self)
pub fn restore(&mut self)
Restore the most recently saved drawing state. No-op if the stack is empty.
Mirrors CanvasRenderingContext2D.restore().
Sourcepub fn translate(&mut self, x: Pixels, y: Pixels)
pub fn translate(&mut self, x: Pixels, y: Pixels)
Translate the current transform by the given offset, in canvas-local pixels.
Sourcepub fn rotate(&mut self, radians: f32)
pub fn rotate(&mut self, radians: f32)
Rotate the current transform clockwise by the given angle in radians.
Sourcepub fn scale(&mut self, x: f32, y: f32)
pub fn scale(&mut self, x: f32, y: f32)
Scale the current transform by independent x and y factors.
Sourcepub fn set_global_alpha(&mut self, alpha: f32)
pub fn set_global_alpha(&mut self, alpha: f32)
Set the global drawing opacity applied to subsequent commands (clamped to 0.0..=1.0).
Mirrors CanvasRenderingContext2D.globalAlpha. Saved and restored by
DrawContext::save / DrawContext::restore.
Sourcepub fn clip_rect(&mut self, bounds: Bounds<Pixels>)
pub fn clip_rect(&mut self, bounds: Bounds<Pixels>)
Restrict subsequent drawing to the given rectangle, intersected with any
existing clip. The flat counterpart to DrawContext::with_clip.
Sourcepub fn draw_text(
&mut self,
text: &ShapedLine,
origin: Point<Pixels>,
color: Hsla,
)
pub fn draw_text( &mut self, text: &ShapedLine, origin: Point<Pixels>, color: Hsla, )
Draw a shaped line of text at the given local origin.
Sourcepub fn draw_text_aligned(
&mut self,
text: &ShapedLine,
origin: Point<Pixels>,
color: Hsla,
align: TextAlign,
)
pub fn draw_text_aligned( &mut self, text: &ShapedLine, origin: Point<Pixels>, color: Hsla, align: TextAlign, )
Draw a shaped line of text anchored horizontally at origin per align, mirroring
the web canvas textAlign (origin.x is the left/center/right anchor).
Sourcepub fn draw_image(&mut self, image: Arc<RenderImage>, bounds: Bounds<Pixels>)
pub fn draw_image(&mut self, image: Arc<RenderImage>, bounds: Bounds<Pixels>)
Draw an image filling the given rectangle, respecting the current transform,
clip, and opacity. Mirrors CanvasRenderingContext2D.drawImage.
Sourcepub fn draw_image_rounded(
&mut self,
image: Arc<RenderImage>,
bounds: Bounds<Pixels>,
corner_radii: impl Into<Corners<Pixels>>,
)
pub fn draw_image_rounded( &mut self, image: Arc<RenderImage>, bounds: Bounds<Pixels>, corner_radii: impl Into<Corners<Pixels>>, )
Draw an image filling the given rectangle with rounded corners.
Sourcepub fn draw_image_frame(
&mut self,
image: Arc<RenderImage>,
bounds: Bounds<Pixels>,
frame_index: usize,
grayscale: bool,
)
pub fn draw_image_frame( &mut self, image: Arc<RenderImage>, bounds: Bounds<Pixels>, frame_index: usize, grayscale: bool, )
Draw a single frame of a multi-frame image (e.g. an animated GIF), optionally desaturated.
Auto Trait Implementations§
impl Freeze for DrawContext
impl RefUnwindSafe for DrawContext
impl Send for DrawContext
impl Sync for DrawContext
impl Unpin for DrawContext
impl UnsafeUnpin for DrawContext
impl UnwindSafe for DrawContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more