Skip to main content

DrawItem

Enum DrawItem 

Source
pub enum DrawItem {
    Stroke {
        start: (f32, f32),
        end: (f32, f32),
        color: Rgb888,
        pixel_width: f32,
    },
    Ellipse {
        center: (f32, f32),
        axis_a: (f32, f32),
        axis_b: (f32, f32),
        color: Rgb888,
    },
    Circle {
        center: (f32, f32),
        pixel_radius: f32,
        color: Rgb888,
    },
    Bitmap {
        view: Image565View,
        top_left: Point,
    },
}
Expand description

A 2D drawing command that can be rendered onto a PixelTarget.

DrawItem is a compact, Copy representation for a heterogeneous scene. Its floating-point geometry is convenient for calculated or projected coordinates, but projection is not required. The same items can be passed to CydDisplay::draw_items, which composites and streams them without a pixel frame buffer, or rendered directly with DrawItem::draw when a frame is available.

For ordinary imperative drawing into a CydFrame, embedded-graphics primitives are also appropriate, particularly when their integer-coordinate geometry and styling API fit the scene. DrawItem::draw uses embedded-graphics internally for strokes and circles as an implementation detail; DrawItem does not replace the broader embedded-graphics API.

Coordinates and sizes are measured in display pixels. Colors are specified as Rgb888, and the target converts them to its native pixel format when needed.

§Example

This example loads a TGA bitmap at compile time and draws one of each item variant onto a full-screen frame.

use device_envoy_core::cyd::{
    Cyd, CydDisplay,
    display::{CydFrame, DrawItem, Image565Fixed, tga},
};
use embedded_graphics::{
    pixelcolor::Rgb888,
    prelude::{Point, RgbColor},
};

const BITMAP: Image565Fixed<45, 73, { 45 * 73 }> = tga!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/docs/assets/cyd_fill_contiguous.tga"
))
.to_565();

async fn draw<C: Cyd>(cyd: &mut C) -> Result<(), C::Error> {
    let display = cyd.display();
    let mut frame = display.full_frame_mut();
    let draw_items = [
        DrawItem::Bitmap {
            view: BITMAP.view(),
            top_left: Point::new(35, 84),
        },
        DrawItem::Circle {
            center: (125.0, 120.0),
            pixel_radius: 32.0,
            color: Rgb888::CYAN,
        },
        DrawItem::Ellipse {
            center: (215.0, 120.0),
            axis_a: (38.0, 0.0),
            axis_b: (12.0, 24.0),
            color: Rgb888::GREEN,
        },
        DrawItem::Stroke {
            start: (280.0, 80.0),
            end: (300.0, 160.0),
            color: Rgb888::YELLOW,
            pixel_width: 8.0,
        },
    ];
    for draw_item in draw_items {
        draw_item.draw(&mut frame);
    }
    frame.flush().await
}

Examples of all four DrawItem variants

Variants§

§

Stroke

A line stroke from start to end with the given pixel width.

Fields

§start: (f32, f32)

Start point in display coordinates.

§end: (f32, f32)

End point in display coordinates.

§color: Rgb888

Stroke color.

§pixel_width: f32

Stroke width in pixels.

§

Ellipse

A filled ellipse. It can also represent a projected disk.

The ellipse is the locus of center + s·axis_a + t·axis_b with s²+t² ≤ 1.

Fields

§center: (f32, f32)

Center in display coordinates.

§axis_a: (f32, f32)

First radius vector, measured in pixels.

§axis_b: (f32, f32)

Second radius vector, measured in pixels.

§color: Rgb888

Fill color.

§

Circle

A filled circle. It can also represent a projected sphere.

Fields

§center: (f32, f32)

Center in display coordinates.

§pixel_radius: f32

Radius in pixels.

§color: Rgb888

Fill color.

§

Bitmap

A statically stored RGB565 bitmap placed at a display position.

Fields

§view: Image565View

Bitmap pixels and dimensions.

§top_left: Point

Top-left corner in display coordinates.

Implementations§

Source§

impl DrawItem

Source

pub fn draw<T: PixelTarget>(&self, target: &mut T)

Draw this item onto a PixelTarget.

Strokes use the embedded-graphics Line primitive and circles use Circle; the general ellipse is rasterized with fill_ellipse_pixels.

See the DrawItem example.

Trait Implementations§

Source§

impl Clone for DrawItem

Source§

fn clone(&self) -> DrawItem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for DrawItem

Source§

impl Debug for DrawItem

Source§

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

Formats the value using the given formatter. 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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
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 = !

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

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.