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 any Paint: a Color, a SystemColor, an
Ink, or a linear, radial or conic gradient, whose unit points resolve against the
shape’s bounding box (docs/shapes.md §3.2). A role or a light/dark pair resolves for the
current appearance, and the drawing re-records when it changes.
Sourcepub fn stroke(&mut self, shape: Shape, color: impl Into<Ink>, width: f64)
pub fn stroke(&mut self, shape: Shape, color: impl Into<Ink>, width: f64)
Stroke a shape with one ink 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 image_region(&mut self, image: &Bitmap, source: Rect, rect: Rect)
pub fn image_region(&mut self, image: &Bitmap, source: Rect, rect: Rect)
Draw the source region of a decoded image into rect (docs/images.md “Drawing on a
canvas”).
source is in the bitmap’s own PIXELS, not points: a sprite sheet lays its cells out in
pixels, and Bitmap::info says how many of them make a point.
The region is scaled into rect exactly as Draw::image scales the whole image. A
region reaching outside the bitmap is clamped to it, never an error, and an empty
intersection draws nothing.
let sheet = day::decode_image(sprites).await?; // once
canvas(move |d, _| d.image_region(&sheet, icon.cell, Rect::new(10.0, 10.0, 24.0, 24.0)))Sourcepub fn image_region_with_opacity(
&mut self,
image: &Bitmap,
source: Rect,
rect: Rect,
opacity: f64,
)
pub fn image_region_with_opacity( &mut self, image: &Bitmap, source: Rect, rect: Rect, opacity: f64, )
Draw::image_region 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 shadow(&mut self, shadow: impl Into<Option<Shadow>>)
pub fn shadow(&mut self, shadow: impl Into<Option<Shadow>>)
Cast shadow from everything drawn afterwards: each fill, stroke, text and image gets
its own (docs/canvas.md “Shadows”). None stops casting one.
The shadow lasts until the enclosing Draw::restore, like a clip;
Draw::shadowed saves, sets, draws and restores for you.
Sourcepub fn shadowed(&mut self, shadow: Shadow, f: impl FnOnce(&mut Draw))
pub fn shadowed(&mut self, shadow: Shadow, f: impl FnOnce(&mut Draw))
Draw f with everything in it casting shadow, restoring the previous shadow
afterwards.
d.shadowed(Shadow::new(Color::rgba(0.0, 0.0, 0.0, 0.3), 16.0).offset(0.0, 6.0), |d| {
d.fill(Shape::RoundedRect(card, 14.0), Color::WHITE);
});Sourcepub fn blend(&mut self, mode: BlendMode)
pub fn blend(&mut self, mode: BlendMode)
Set how everything drawn afterwards combines with what the canvas already holds
(docs/canvas.md “Blend modes”). Lasts until the enclosing Draw::restore;
Draw::blended scopes it for you.
Sourcepub fn blended(&mut self, mode: BlendMode, f: impl FnOnce(&mut Draw))
pub fn blended(&mut self, mode: BlendMode, f: impl FnOnce(&mut Draw))
Draw f in blend mode mode, restoring the previous mode afterwards.
d.fill(Shape::RoundedRect(ticket, 14.0), paper);
d.blended(BlendMode::Erase, |d| d.fill(Shape::Ellipse(hole), Color::BLACK));Sourcepub fn save(&mut self)
pub fn save(&mut self)
Save the current transform, clip, shadow and blend mode; pair with Draw::restore.
Sourcepub fn restore(&mut self)
pub fn restore(&mut self)
Restore the transform, clip, shadow and blend mode 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 Forget for Draw
impl Freeze for Draw
impl Move 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