Skip to main content

Draw

Struct Draw 

Source
pub struct Draw { /* private fields */ }

Implementations§

Source§

impl Draw

Source

pub fn new() -> Self

An empty recorder, for a test that calls a draw function directly and asserts on what it records: the same list the canvas replays.

Source

pub fn ops(&self) -> &[DrawOp]

What has been recorded so far, in order.

Source§

impl Draw

Source

pub fn fill(&mut self, shape: Shape, paint: impl Into<Paint>)

Fill a shape with a solid color or a day_spec::LinearGradient (both convert to Paint; gradient unit points resolve against the shape’s bounding box, docs/shapes.md §3.2).

Source

pub fn stroke(&mut self, shape: Shape, color: Color, width: f64)

Stroke a shape with a solid color at width, the everyday case.

Source

pub fn stroke_styled( &mut self, shape: Shape, paint: impl Into<Paint>, style: StrokeStyle, )

Stroke with a full StrokeStyle (dash, cap, join) and any paint, gradients included.

Source

pub fn stamp(&mut self, shape: Shape, at: Vec<Point>, paint: impl Into<Paint>)

Draw shape once at every position in at: one op for the whole batch.

The template is authored around the origin and each copy is it translated by one point, so a 6-point dot is Shape::Ellipse(Rect::new(-3.0, -3.0, 6.0, 6.0)). Order is drawing order.

Reach for this the moment a drawing has more marks than it has kinds of mark. A scatter of fifty thousand points drawn one fill at a time is fifty thousand ops to build, compare and clone on every frame that re-records; as one stamp it is one op and a flat array of coordinates, and a backend can put every copy into a single path (docs/canvas.md “Stamping”). Every copy shares the shape, size and paint, so group by whatever varies.

Source

pub fn stamp_styled( &mut self, shape: Shape, at: Vec<Point>, paint: impl Into<Paint>, style: StrokeStyle, )

Draw::stamp, stroking each copy instead of filling it.

Source

pub fn image(&mut self, image: &Bitmap, rect: Rect)

Draw a decoded image into rect (docs/images.md).

Takes a decoded Bitmap, not bytes: the draw closure re-records on every tracked read, and a buffer here would be compared (and re-decoded) every frame. Decode once with day::decode_image, hold the handle, and draw it as often as you like.

ⓘ
let photo = day::decode_image(bytes).await?;          // once
canvas(move |d, size| d.image(&photo, Rect::from_size(size)))

Needs Cap::ImageDecode; a backend without it draws nothing here, the same as for any op it does not know.

Source

pub fn image_with_opacity(&mut self, image: &Bitmap, rect: Rect, opacity: f64)

Draw::image with an opacity in 0.0..=1.0 multiplying the image’s own alpha.

Source

pub fn clip(&mut self, shape: Shape)

Confine everything drawn afterwards to shape.

The clip lasts until the enclosing Draw::restore, so the usual shape is save → clip → draw → restore; Draw::clipped does exactly that for you.

Source

pub fn clipped(&mut self, shape: Shape, f: impl FnOnce(&mut Draw))

Draw f clipped to shape, restoring the previous clip afterwards.

Source

pub fn text(&mut self, text: &str, at: Point, style: TextStyle)

One line of text hung on at per the style’s anchor (docs/canvas.md “Text”); measure it first with day::measure_text when the drawing needs its extent.

Source

pub fn save(&mut self)

Save the current transform/clip; pair with Draw::restore.

Source

pub fn restore(&mut self)

Restore the transform/clip saved by the matching Draw::save.

Source

pub fn concat(&mut self, m: Affine)

Multiply an affine onto the current transform (shape rotate/scale/offset, §11).

Source

pub fn transformed(&mut self, m: Affine, f: impl FnOnce(&mut Draw))

Draw within m applied to the CTM, restoring afterwards.

Trait Implementations§

Source§

impl Default for Draw

Source§

fn default() -> Draw

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

Auto Trait Implementations§

§

impl Freeze for Draw

§

impl RefUnwindSafe for Draw

§

impl Send for Draw

§

impl Sync for Draw

§

impl Unpin for Draw

§

impl UnsafeUnpin for Draw

§

impl UnwindSafe for Draw

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
§

impl<T> ErasedDestructor for T
where T: 'static,

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, 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.
Day API ↩ Guides· daybrite.dev