Crate epaint

source ·
Expand description

A simple 2D graphics library for turning simple 2D shapes and text into textured triangles.

Made for egui.

Create some Shape:s and pass them to tessellate_shapes to generate Mesh:es that you can then paint using some graphics API of your choice (e.g. OpenGL).

§Coordinate system

The left-top corner of the screen is (0.0, 0.0), with X increasing to the right and Y increasing downwards.

epaint uses logical points as its coordinate system. Those related to physical pixels by the pixels_per_point scale factor. For example, a high-dpi screeen can have pixels_per_point = 2.0, meaning there are two physical screen pixels for each logical point.

Angles are in radians, and are measured clockwise from the X-axis, which has angle=0.

§Feature flags

  • bytemuckbytemuck enables you to cast Vertex to &[u8].

  • cintcint enables interoperability with other color libraries.

  • color-hex — Enable the hex_color macro.

  • deadlock_detection — This will automatically detect deadlocks due to double-locking on the same thread. If your app freezes, you may want to enable this! Only affects mutex::RwLock (which epaint and egui uses a lot).

  • default_fonts (enabled by default) — If set, epaint will use include_bytes! to bundle some fonts. If you plan on specifying your own fonts you may disable this feature.

  • extra_debug_asserts — Enable additional checks if debug assertions are enabled (debug builds).

  • extra_asserts — Always enable additional checks.

  • log — Turn on the log feature, that makes egui log some errors using the log crate.

  • mintmint enables interoperability with other math libraries such as glam and nalgebra.

  • puffin — Enable profiling with the puffin crate.

    Only enabled on native, because of the low resolution (1ms) of clocks in browsers.

  • rayon — Enable parallel tessellation using rayon.

    This can help performance for graphics-intense applications.

  • serde — Allow serialization using serde.

  • unity — Change Vertex layout to be compatible with unity

§Optional dependencies

  • document-features — Enable this when generating docs.
  • serde — Allow serialization using serde .

Re-exports§

Modules§

  • Helper module that adds extra checks when the deadlock_detection feature is turned on.
  • Collect statistics about what is being painted.
  • Converts graphics primitives into textured triangles.
  • Everything related to text, fonts, text layout, cursors etc.

Macros§

  • An assert that is only active when epaint is compiled with the extra_asserts feature or with the extra_debug_asserts feature in debug builds.
  • Construct a crate::Color32 from a hex RGB or RGBA string.

Structs§

Enums§

  • A rendering primitive - either a Mesh or a PaintCallback.
  • A paint primitive such as a circle or a piece of text. Coordinates are all screen space points (not physical pixels).
  • What texture to use in a Mesh mesh.

Constants§

  • Was epaint compiled with the rayon feature?
  • The UV coordinate of a white region of the texture mesh. The default egui texture has the top-left corner pixel fully white. You need need use a clamping texture sampler for this to work (so it doesn’t do bilinear blending with bottom right corner).

Functions§

  • pos2(x, y) == Pos2::new(x, y)
  • vec2(x, y) == Vec2::new(x, y)