31 releases

0.7.0 Oct 24, 2024
0.6.2 Jan 30, 2023
0.6.0 Nov 24, 2022
0.5.0 Nov 12, 2021
0.0.2 Feb 22, 2019

#21 in Graphics APIs

Download history 1805/week @ 2024-08-23 1826/week @ 2024-08-30 1556/week @ 2024-09-06 1501/week @ 2024-09-13 1712/week @ 2024-09-20 1364/week @ 2024-09-27 1042/week @ 2024-10-04 1047/week @ 2024-10-11 1473/week @ 2024-10-18 1319/week @ 2024-10-25 1376/week @ 2024-11-01 787/week @ 2024-11-08 756/week @ 2024-11-15 1261/week @ 2024-11-22 1495/week @ 2024-11-29 1164/week @ 2024-12-06

4,729 downloads per month
Used in 81 crates (28 directly)

Apache-2.0 OR MIT

325KB
3K SLoC

image of piet logo

Piet: a 2D graphics abstraction

Crates.io Documentation Build Status

Cross-platform 2D graphics.

The Piet project consists of a core crate (piet) which describes a 2D graphics API, and a number of "backends", which implement that API on top of the built-in 2D graphics system of a given platform. This allows the same drawing code to be used on different platforms, without having to bundle a full 2D renderer.

The motivation for this crate is set forth in this blog post. It is used as the basis of Druid, a cross-platform GUI toolkit.

A companion for Bézier path representation and geometry is kurbo.

Getting started

Running the examples requires that submodules be checked out. From the root directory, run

git submodule update --init

Contributing

Piet is in maintenance mode.

Piet has largely stabilized, and no major API additions are planned by the original developers. Bug fixes and performance improvements are welcome.

If there is a significant feature you would like to add that can be discussed. For a new feature to be considered, there must be a plan for how it would be implemented in at least the coregraphics, direct2d, and cairo backends, and the actual implementation should include support for at least two of these.

For questions and discussions we use a zulip chat instance at xi.zulipchat.com under the #piet stream.

Backends

For cross-platform use, the piet-common crate reexports the most appropriate implementation for the current target.

piet-cairo crates.io

The piet-cairo crate depends on the cairo library. A simple test of the cairo backend is to run cargo run --example test-picture 0 in the piet-cairo directory, which should produce an image file called cairo-test-00-2.00.png.

piet-coregraphics crates.io

The piet-coregraphics crate works on macOS only. A simple test of the coregraphics backend is to run cargo run --example test-picture 0 in the piet-coregraphics directory, which should produce an image file called coregraphics-test-00-2.00.png.

piet-direct2d crates.io

The piet-direct2d crate works on Windows only. A simple test of the direct2d backend is to run cargo run --example test-picture 0 in the piet-direct2d directory, which should produce an image called d2d-test-00-2.00.png.

piet-svg crates.io

piet-web crates.io

Inspirations

Piet's interface is largely inspired by the Skia Graphics Library as well as the C++ 2D graphics api proposal although piet aims to be much more lightweight and modular.

The Name

The library is named after Piet Mondrian. It is abstract and intended to be used for drawing lots of rectangles.

Dependencies

~0.7–8.5MB
~70K SLoC