embedded_canvas/
lib.rs

1//! [![sponsor-us]](https://github.com/sponsors/LechevSpace) [![github]](https://github.com/LechevSpace/embedded-canvas) [![crates-io]](https://crates.io/crates/embedded-canvas)
2//!
3//! `embedded-canvas` is a convenient crate for [`embedded-graphics`]
4//! and provides a [`Canvas`](#canvas) and [`CanvasAt`](#CanvasAt) on which you
5//! can draw anything with ease before drawing the pixels on the embedded display.
6//!
7//! > canvas - a piece of cloth backed or framed as a surface for a painting
8//!
9//! Based on [`embedded-graphics-core`] and [`embedded-graphics`]
10//! (see `transform` feature in [Crate features](#crate-features)).
11//!
12//! This crate is `no_std` and it has 2 sets of canvases:
13//! - [`Canvas`] and [`CanvasAt`] - require `alloc` feature
14//! - [`CCanvas`] and [`CCanvasAt`] - do **not** require `alloc` feature because they
15//!  use const generics instead.
16//!
17//! The main advantages of the canvases in this crate are:
18//!
19//! 1. **Transparency** - pixels that haven't been drawn, won't override pixels on the display.
20//!
21//! ![Example: Transparency][transparency_screenshot]
22//!
23//!_Example: Transparency - The canvas content (a circle) is drawn on the display where
24//! there's already a drawn square._
25//!
26//! 2. **Cropping** - The ability to crop leaves only the part of the canvas you want to
27//! draw on the display. This is especially useful when you want to
28//! partially show text, figures and images.
29//!
30//! ![Example: Cropping text][cropping_text_screenshot]
31//!
32//! _Example: Cropping text - The full canvas content is drawn on the left and
33//! only portion of it is cropped and drawn on the right._
34//!
35//! [`embedded-graphics`]: https://crates.io/crates/embedded-graphics
36//! [`embedded-graphics-core`]: https://crates.io/crates/embedded-graphics-core
37//! [transparency_screenshot]: https://github.com/LechevSpace/embedded-canvas/raw/81de4494c36d0d76c552823b83d3ac446b27b636/examples/screenshots/transparency.png
38//! [cropping_text_screenshot]: https://github.com/LechevSpace/embedded-canvas/raw/81de4494c36d0d76c552823b83d3ac446b27b636/examples/screenshots/cropping_text.png
39//!
40//! # How to work with canvases
41//!
42//! There are **two** main canvases you can work with:
43//!
44//! ## `Canvas` / `CCanvas`
45//!
46//! A canvas which you can draw on with origin [`Point::zero()`](embedded_graphics_core::geometry::Point::zero).
47//! The canvas location is not set for the provided display.
48//!
49//! After drawing decide where to place it on the display using the methods:
50//! - `Canvas::place_at(top_left: Point) -> CanvasAt` (with `alloc` feature) or `CCanvas::place_at(top_left: Point) -> CCanvasAt`
51//! - `Canvas::place_center(center: Point) -> CanvasAt` (with `alloc` feature) or `CCanvas::place_center(center: Point) -> CCanvasAt`
52//!
53//! ## `CanvasAt` / `CCanavasAt`
54//!
55//! [`CanvasAt`]/[`CCanvasAt`] is a type of canvas ready to be drawn on the display
56//! at specified location (hence the name [`CanvasAt`]/[`CCanvasAt`]).
57//!
58//! There are two ways of using [`CanvasAt`]/[`CCanvasAt`]:
59//!
60//! 1. Directly placing the [`CanvasAt`]/[`CCanvasAt`] on specified location on the display and drawing inside.
61//! 2. Create a [`Canvas`]/[`CCanvas`] and when ready to draw it on the display place the
62//!  [`Canvas`]/[`CCanvas`] at specified location using the methods:
63//!    - `Canvas::place_at(top_left: Point) -> CanvasAt` (with `alloc` feature) and `CCanvas::place_at(top_left: Point) -> CCanvasAt`
64//!    - `Canvas::place_center(center: Point) -> CanvasAt` (with `alloc` feature) and `CCanvas::place_center(center: Point) -> CCanvasAt`
65//!
66//! # Crate features
67//! - `default` features - `transform`
68//! - `alloc` - enables [`Canvas`] and [`CanvasAt`].
69//! - `transform` - enables the trait implementation of [`embedded_graphics::transform::Transform`] for [`CanvasAt`]/[`CCanvasAt`].
70//!
71//! [github]: https://img.shields.io/badge/github-3873AD?style=for-the-badge&labelColor=555555&logo=github
72//! [crates-io]: https://img.shields.io/crates/v/embedded-canvas?logo=rust&style=for-the-badge
73//! [sponsor-us]: https://img.shields.io/github/sponsors/LechevSpace?color=bf3989&label=Sponsor%20us&style=for-the-badge&logoColor=bf3989&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyBoZWlnaHQ9IjE2IiB2aWV3Qm94PSIwIDAgMTYgMTYiIHZlcnNpb249IjEuMSIgd2lkdGg9IjE2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogICAgPHBhdGggZmlsbD0iI2JmMzk4OSIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNNC4yNSAyLjVjLTEuMzM2IDAtMi43NSAxLjE2NC0yLjc1IDMgMCAyLjE1IDEuNTggNC4xNDQgMy4zNjUgNS42ODJBMjAuNTY1IDIwLjU2NSAwIDAwOCAxMy4zOTNhMjAuNTYxIDIwLjU2MSAwIDAwMy4xMzUtMi4yMTFDMTIuOTIgOS42NDQgMTQuNSA3LjY1IDE0LjUgNS41YzAtMS44MzYtMS40MTQtMy0yLjc1LTMtMS4zNzMgMC0yLjYwOS45ODYtMy4wMjkgMi40NTZhLjc1Ljc1IDAgMDEtMS40NDIgMEM2Ljg1OSAzLjQ4NiA1LjYyMyAyLjUgNC4yNSAyLjV6TTggMTQuMjVsLS4zNDUuNjY2LS4wMDItLjAwMS0uMDA2LS4wMDMtLjAxOC0uMDFhNy42NDMgNy42NDMgMCAwMS0uMzEtLjE3IDIyLjA3NSAyMi4wNzUgMCAwMS0zLjQzNC0yLjQxNEMyLjA0NSAxMC43MzEgMCA4LjM1IDAgNS41IDAgMi44MzYgMi4wODYgMSA0LjI1IDEgNS43OTcgMSA3LjE1MyAxLjgwMiA4IDMuMDIgOC44NDcgMS44MDIgMTAuMjAzIDEgMTEuNzUgMSAxMy45MTQgMSAxNiAyLjgzNiAxNiA1LjVjMCAyLjg1LTIuMDQ1IDUuMjMxLTMuODg1IDYuODE4YTIyLjA4IDIyLjA4IDAgMDEtMy43NDQgMi41ODRsLS4wMTguMDEtLjAwNi4wMDNoLS4wMDJMOCAxNC4yNXptMCAwbC4zNDUuNjY2YS43NTIuNzUyIDAgMDEtLjY5IDBMOCAxNC4yNXoiPjwvcGF0aD4KPC9zdmc%2BCg%3D%3D
74#![deny(clippy::all)]
75#![deny(rustdoc::broken_intra_doc_links)]
76#![no_std]
77// only enables the `doc_cfg` feature when
78// the `docsrs` configuration attribute is defined
79#![cfg_attr(docsrs, feature(doc_cfg))]
80
81#[cfg(feature = "alloc")]
82extern crate alloc;
83
84#[doc(inline)]
85#[cfg(feature = "alloc")]
86pub use canvas::{Canvas, CanvasAt};
87
88#[doc(inline)]
89pub use consts::{CCanvas, CCanvasAt};
90
91#[cfg(feature = "alloc")]
92#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
93mod canvas;
94
95mod consts;
96
97pub(crate) mod utils;