pub struct Draw { /* private fields */ }Implementations§
Source§impl Draw
impl Draw
Sourcepub fn fill(&mut self, shape: Shape, paint: impl Into<Paint>)
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).
Sourcepub fn stroke(&mut self, shape: Shape, color: Color, width: f64)
pub fn stroke(&mut self, shape: Shape, color: Color, width: f64)
Stroke a shape with a solid color at width, the everyday case.
Sourcepub fn stroke_styled(
&mut self,
shape: Shape,
paint: impl Into<Paint>,
style: StrokeStyle,
)
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.
Sourcepub fn stamp(&mut self, shape: Shape, at: Vec<Point>, paint: impl Into<Paint>)
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.
Sourcepub fn stamp_styled(
&mut self,
shape: Shape,
at: Vec<Point>,
paint: impl Into<Paint>,
style: StrokeStyle,
)
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.
Sourcepub fn image(&mut self, image: &Bitmap, rect: Rect)
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.
Sourcepub fn image_with_opacity(&mut self, image: &Bitmap, rect: Rect, opacity: f64)
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.
Sourcepub fn clip(&mut self, shape: Shape)
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.
Sourcepub fn clipped(&mut self, shape: Shape, f: impl FnOnce(&mut Draw))
pub fn clipped(&mut self, shape: Shape, f: impl FnOnce(&mut Draw))
Draw f clipped to shape, restoring the previous clip afterwards.
Sourcepub fn text(&mut self, text: &str, at: Point, style: TextStyle)
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.
Sourcepub fn save(&mut self)
pub fn save(&mut self)
Save the current transform/clip; pair with Draw::restore.
Sourcepub fn restore(&mut self)
pub fn restore(&mut self)
Restore the transform/clip saved by the matching Draw::save.
Sourcepub fn concat(&mut self, m: Affine)
pub fn concat(&mut self, m: Affine)
Multiply an affine onto the current transform (shape rotate/scale/offset, §11).
Sourcepub fn transformed(&mut self, m: Affine, f: impl FnOnce(&mut Draw))
pub fn transformed(&mut self, m: Affine, f: impl FnOnce(&mut Draw))
Draw within m applied to the CTM, restoring afterwards.
Trait Implementations§
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> 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<T> ErasedDestructor for Twhere
T: 'static,
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