RecordingCanvas

Struct RecordingCanvas 

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

A Canvas implementation that records draw operations as DrawCommands.

This is useful for:

  • Testing (verify what was painted)
  • Serialization (send commands to GPU/WASM)
  • Diffing (compare render outputs)

Implementations§

Source§

impl RecordingCanvas

Source

pub fn new() -> RecordingCanvas

Create a new empty recording canvas.

Source

pub fn commands(&self) -> &[DrawCommand]

Get the recorded draw commands.

Source

pub fn take_commands(&mut self) -> Vec<DrawCommand>

Take ownership of the recorded commands, clearing the canvas.

Source

pub fn command_count(&self) -> usize

Get the number of recorded commands.

Source

pub fn is_empty(&self) -> bool

Check if no commands have been recorded.

Source

pub fn clear(&mut self)

Clear all recorded commands.

Source

pub fn current_transform(&self) -> Transform2D

Get the current transform (identity if no transforms pushed).

Source

pub fn current_clip(&self) -> Option<Rect>

Get the current clip bounds (None if no clips pushed).

Source

pub fn clip_depth(&self) -> usize

Get the clip stack depth.

Source

pub fn transform_depth(&self) -> usize

Get the transform stack depth.

Source

pub fn add_command(&mut self, command: DrawCommand)

Add a raw draw command.

Source

pub fn fill_circle(&mut self, center: Point, radius: f32, color: Color)

Draw a filled circle.

Source

pub fn draw_line(&mut self, from: Point, to: Point, color: Color, width: f32)

Draw a line between two points.

Source

pub fn draw_path( &mut self, points: &[Point], closed: bool, color: Color, width: f32, )

Draw a path (polyline).

Source

pub fn fill_rounded_rect(&mut self, rect: Rect, radius: f32, color: Color)

Draw a rounded rectangle.

Trait Implementations§

Source§

impl Canvas for RecordingCanvas

Source§

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

Draw a filled rectangle.
Source§

fn stroke_rect(&mut self, rect: Rect, color: Color, width: f32)

Draw a stroked rectangle.
Source§

fn draw_text(&mut self, text: &str, position: Point, style: &TextStyle)

Draw text.
Source§

fn draw_line(&mut self, from: Point, to: Point, color: Color, width: f32)

Draw a line between two points.
Source§

fn fill_circle(&mut self, center: Point, radius: f32, color: Color)

Draw a filled circle.
Source§

fn stroke_circle( &mut self, center: Point, radius: f32, color: Color, width: f32, )

Draw a stroked circle.
Source§

fn fill_arc( &mut self, center: Point, radius: f32, start_angle: f32, end_angle: f32, color: Color, )

Draw a filled arc (pie slice).
Source§

fn draw_path(&mut self, points: &[Point], color: Color, width: f32)

Draw a path (polyline).
Source§

fn fill_polygon(&mut self, points: &[Point], color: Color)

Fill a polygon.
Source§

fn push_clip(&mut self, rect: Rect)

Push a clip region.
Source§

fn pop_clip(&mut self)

Pop the clip region.
Source§

fn push_transform(&mut self, transform: Transform2D)

Push a transform.
Source§

fn pop_transform(&mut self)

Pop the transform.
Source§

impl Debug for RecordingCanvas

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for RecordingCanvas

Source§

fn default() -> RecordingCanvas

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,