pub struct Drawing { /* private fields */ }Expand description
A recorded drawing at a fixed size: what a canvas would replay, kept for export.
Write the drawing once as a plain function and call it from the canvas and from export:
fn draw_chart(d: &mut Draw, size: Size, series: &[f64]) { /* … */ }
canvas(move |d, size| draw_chart(d, size, &series.get())) // on screen
let drawing = Drawing::record(Size::new(600.0, 400.0), |d, size| {
draw_chart(d, size, &series.get_untracked())
});
day::task(async move {
if let Ok(png) = drawing.to_png(2.0).await { /* save it */ }
});Rendering goes through the toolkit’s own canvas painter (Core Graphics, cairo, QPainter,
an android Canvas, …), so an export matches the screen. Probe canvas_exports before
offering a command.
Implementations§
Source§impl Drawing
impl Drawing
Sourcepub fn record(size: Size, draw: impl FnOnce(&mut Draw, Size)) -> Drawing
pub fn record(size: Size, draw: impl FnOnce(&mut Draw, Size)) -> Drawing
Run draw once, untracked, at size points. Signal reads inside it subscribe nothing,
so recording from a binding or a menu action is safe.
Sourcepub fn from_ops(size: Size, ops: Vec<DrawOp>) -> Drawing
pub fn from_ops(size: Size, ops: Vec<DrawOp>) -> Drawing
A drawing of ops recorded elsewhere, at size points.
Sourcepub fn to_bitmap(&self, scale: f64) -> RenderBitmap ⓘ
pub fn to_bitmap(&self, scale: f64) -> RenderBitmap ⓘ
Render to a bitmap of size × scale pixels whose info().scale is scale, so
image(&bitmap) shows it at the drawing’s point size. Await it inside day::task.
Err(ExportError::Unsupported) where the toolkit has no offscreen painter
(Cap::CanvasBitmap); Err(ExportError::TooLarge) above
16,384 pixels a side or 64 megapixels.
Sourcepub fn to_png(
&self,
scale: f64,
) -> impl Future<Output = Result<Vec<u8>, ExportError>> + 'static
pub fn to_png( &self, scale: f64, ) -> impl Future<Output = Result<Vec<u8>, ExportError>> + 'static
Render to a bitmap and encode it as PNG: Drawing::to_bitmap then
Bitmap::encode. Err(ExportError::Unsupported) where either half is missing
(CanvasExports::png answers that up front).
Sourcepub fn to_pdf(&self) -> RenderPdf ⓘ
pub fn to_pdf(&self) -> RenderPdf ⓘ
A one-page PDF the size of the drawing. Err(ExportError::Unsupported) where the
platform has no PDF writer (Cap::CanvasPdf).
Trait Implementations§
impl StructuralPartialEq for Drawing
Auto Trait Implementations§
impl Freeze for Drawing
impl RefUnwindSafe for Drawing
impl Send for Drawing
impl Sync for Drawing
impl Unpin for Drawing
impl UnsafeUnpin for Drawing
impl UnwindSafe for Drawing
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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