draw/
lib.rs

1//! `draw` is a simple 2D vector drawing library.
2//!
3//! - `Canvas` is a container that defines the size and top-level components of your drawing.
4//! - `Drawing` defines the position, style, and sub-components of a drawing.
5//! - `Shape` defines the geometry of an individual shape such as a `Circle` or `Line`.
6//! - `Style` defines the fill and stroke of a drawing.  
7//!
8//! The general flow for creating a piece of art is:
9//!
10//! 1. Create a `Canvas`
11//! 2. Create `Drawing` objects and add them to the Canvas `display_list`.
12//! 3. Position and style the drawings
13//! 4. Render and save the `Canvas` to whatever output format you want. (SVG, PNG, etc...)
14//!
15//! ## Basic Example
16//!
17//! ```rust
18//! use draw::*;
19//!
20//! // create a canvas to draw on
21//! let mut canvas = Canvas::new(100, 100);
22//!
23//! // create a new drawing
24//! let mut rect = Drawing::new()
25//!     // give it a shape
26//!     .with_shape(Shape::Rectangle {
27//!         width: 50,
28//!         height: 50,
29//!     })
30//!     // move it around
31//!     .with_xy(25.0, 25.0)
32//!     // give it a cool style
33//!     .with_style(Style::stroked(5, Color::black()));
34//!
35//! // add it to the canvas
36//! canvas.display_list.add(rect);
37//!
38//! // save the canvas as an svg
39//! render::save(
40//!     &canvas,
41//!     "tests/svg/basic_end_to_end.svg",
42//!     SvgRenderer::new(),
43//! )
44//! .expect("Failed to save");
45//! ```
46//!
47use cgmath::EuclideanSpace;
48use cgmath::Point2;
49use rgb;
50
51pub mod canvas;
52pub mod drawing;
53pub mod render;
54pub mod shape;
55pub mod style;
56
57pub use crate::canvas::Canvas;
58pub use crate::drawing::{DisplayList, Drawing};
59pub use crate::render::svg::SvgRenderer;
60pub use crate::shape::{LineBuilder, Shape};
61pub use crate::style::Color;
62pub use crate::style::{Fill, Stroke, Style};
63
64/// Drawings are stored in a vector; this `usize` is a handle to access the child
65pub type DrawingId = usize;
66
67pub type Point = Point2<f32>;
68
69/// An alias for RGB<u8>
70pub type RGB = rgb::RGB<u8>;