Skip to main content

Canvas2DCommand

Enum Canvas2DCommand 

Source
pub enum Canvas2DCommand {
Show 15 variants Clear { color: Color, }, FillRect { x: f32, y: f32, width: f32, height: f32, color: Color, }, StrokeRect { x: f32, y: f32, width: f32, height: f32, color: Color, line_width: f32, }, FillCircle { x: f32, y: f32, radius: f32, color: Color, }, StrokeCircle { x: f32, y: f32, radius: f32, color: Color, line_width: f32, }, Line { x1: f32, y1: f32, x2: f32, y2: f32, color: Color, line_width: f32, }, FillText { text: String, x: f32, y: f32, font: String, color: Color, align: TextAlign, baseline: TextBaseline, }, DrawImage { texture_id: u32, x: f32, y: f32, width: f32, height: f32, }, DrawImageSlice { texture_id: u32, src_x: f32, src_y: f32, src_width: f32, src_height: f32, dst_x: f32, dst_y: f32, dst_width: f32, dst_height: f32, }, Save, Restore, Translate { x: f32, y: f32, }, Rotate { angle: f32, }, Scale { x: f32, y: f32, }, SetAlpha { alpha: f32, },
}
Expand description

Canvas2D render commands that are serialized to JSON.

These commands are designed to be minimal and directly map to Canvas2D API calls. The JavaScript renderer simply iterates over commands and executes them.

Variants§

§

Clear

Clear the entire canvas with a color.

Fields

§color: Color

Fill color for clearing

§

FillRect

Fill a rectangle.

Fields

§x: f32

X position

§y: f32

Y position

§width: f32

Width

§height: f32

Height

§color: Color

Fill color

§

StrokeRect

Stroke a rectangle outline.

Fields

§x: f32

X position

§y: f32

Y position

§width: f32

Width

§height: f32

Height

§color: Color

Stroke color

§line_width: f32

Line width

§

FillCircle

Fill a circle.

Fields

§x: f32

Center X

§y: f32

Center Y

§radius: f32

Radius

§color: Color

Fill color

§

StrokeCircle

Stroke a circle outline.

Fields

§x: f32

Center X

§y: f32

Center Y

§radius: f32

Radius

§color: Color

Stroke color

§line_width: f32

Line width

§

Line

Draw a line.

Fields

§x1: f32

Start X

§y1: f32

Start Y

§x2: f32

End X

§y2: f32

End Y

§color: Color

Line color

§line_width: f32

Line width

§

FillText

Draw text.

Fields

§text: String

Text content

§x: f32

X position

§y: f32

Y position

§font: String

CSS font string (e.g., “48px monospace”)

§color: Color

Text color

§align: TextAlign

Text alignment

§baseline: TextBaseline

Text baseline

§

DrawImage

Draw an image/sprite from a loaded texture.

Fields

§texture_id: u32

Texture ID (index into loaded textures array)

§x: f32

Destination X

§y: f32

Destination Y

§width: f32

Destination width

§height: f32

Destination height

§

DrawImageSlice

Draw a portion of an image (sprite sheet).

Fields

§texture_id: u32

Texture ID

§src_x: f32

Source X in texture

§src_y: f32

Source Y in texture

§src_width: f32

Source width

§src_height: f32

Source height

§dst_x: f32

Destination X

§dst_y: f32

Destination Y

§dst_width: f32

Destination width

§dst_height: f32

Destination height

§

Save

Save the current canvas state.

§

Restore

Restore the previously saved canvas state.

§

Translate

Translate the canvas origin.

Fields

§x: f32

X translation

§y: f32

Y translation

§

Rotate

Rotate the canvas.

Fields

§angle: f32

Rotation angle in radians

§

Scale

Scale the canvas.

Fields

§x: f32

X scale factor

§y: f32

Y scale factor

§

SetAlpha

Set global alpha (opacity).

Fields

§alpha: f32

Alpha value (0.0 to 1.0)

Trait Implementations§

Source§

impl Clone for Canvas2DCommand

Source§

fn clone(&self) -> Canvas2DCommand

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Canvas2DCommand

Source§

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

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

impl<'de> Deserialize<'de> for Canvas2DCommand

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Canvas2DCommand

Source§

fn eq(&self, other: &Canvas2DCommand) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Canvas2DCommand

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Canvas2DCommand

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,