epaint/
lib.rs

1//! A simple 2D graphics library for turning simple 2D shapes and text into textured triangles.
2//!
3//! Made for [`egui`](https://github.com/emilk/egui/).
4//!
5//! Create some [`Shape`]:s and pass them to [`tessellate_shapes`] to generate [`Mesh`]:es
6//! that you can then paint using some graphics API of your choice (e.g. OpenGL).
7//!
8//! ## Coordinate system
9//! The left-top corner of the screen is `(0.0, 0.0)`,
10//! with X increasing to the right and Y increasing downwards.
11//!
12//! `epaint` uses logical _points_ as its coordinate system.
13//! Those related to physical _pixels_ by the `pixels_per_point` scale factor.
14//! For example, a high-dpi screen can have `pixels_per_point = 2.0`,
15//! meaning there are two physical screen pixels for each logical point.
16//!
17//! Angles are in radians, and are measured clockwise from the X-axis, which has angle=0.
18//!
19//! ## Feature flags
20#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
21//!
22
23#![allow(clippy::float_cmp)]
24#![allow(clippy::manual_range_contains)]
25
26mod bezier;
27pub mod color;
28pub mod image;
29mod margin;
30mod mesh;
31pub mod mutex;
32mod shadow;
33mod shape;
34pub mod shape_transform;
35pub mod stats;
36mod stroke;
37pub mod tessellator;
38pub mod text;
39mod texture_atlas;
40mod texture_handle;
41pub mod textures;
42pub mod util;
43
44pub use self::{
45    bezier::{CubicBezierShape, QuadraticBezierShape},
46    color::ColorMode,
47    image::{ColorImage, FontImage, ImageData, ImageDelta},
48    margin::Margin,
49    mesh::{Mesh, Mesh16, Vertex},
50    shadow::Shadow,
51    shape::{
52        CircleShape, EllipseShape, PaintCallback, PaintCallbackInfo, PathShape, RectShape,
53        Rounding, Shape, TextShape,
54    },
55    stats::PaintStats,
56    stroke::{PathStroke, Stroke},
57    tessellator::{TessellationOptions, Tessellator},
58    text::{FontFamily, FontId, Fonts, Galley},
59    texture_atlas::TextureAtlas,
60    texture_handle::TextureHandle,
61    textures::TextureManager,
62};
63
64#[allow(deprecated)]
65pub use tessellator::tessellate_shapes;
66
67pub use ecolor::{Color32, Hsva, HsvaGamma, Rgba};
68pub use emath::{pos2, vec2, Pos2, Rect, Vec2};
69
70#[deprecated = "Use the ahash crate directly."]
71pub use ahash;
72
73pub use ecolor;
74pub use emath;
75
76#[cfg(feature = "color-hex")]
77pub use ecolor::hex_color;
78
79/// The UV coordinate of a white region of the texture mesh.
80///
81/// The default egui texture has the top-left corner pixel fully white.
82/// You need need use a clamping texture sampler for this to work
83/// (so it doesn't do bilinear blending with bottom right corner).
84pub const WHITE_UV: emath::Pos2 = emath::pos2(0.0, 0.0);
85
86/// What texture to use in a [`Mesh`] mesh.
87///
88/// If you don't want to use a texture, use `TextureId::Managed(0)` and the [`WHITE_UV`] for uv-coord.
89#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
90#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
91pub enum TextureId {
92    /// Textures allocated using [`TextureManager`].
93    ///
94    /// The first texture (`TextureId::Managed(0)`) is used for the font data.
95    Managed(u64),
96
97    /// Your own texture, defined in any which way you want.
98    /// The backend renderer will presumably use this to look up what texture to use.
99    User(u64),
100}
101
102impl Default for TextureId {
103    /// The epaint font texture.
104    fn default() -> Self {
105        Self::Managed(0)
106    }
107}
108
109/// A [`Shape`] within a clip rectangle.
110///
111/// Everything is using logical points.
112#[derive(Clone, Debug, PartialEq)]
113pub struct ClippedShape {
114    /// Clip / scissor rectangle.
115    /// Only show the part of the [`Shape`] that falls within this.
116    pub clip_rect: emath::Rect,
117
118    /// The shape
119    pub shape: Shape,
120}
121
122/// A [`Mesh`] or [`PaintCallback`] within a clip rectangle.
123///
124/// Everything is using logical points.
125#[derive(Clone, Debug)]
126pub struct ClippedPrimitive {
127    /// Clip / scissor rectangle.
128    /// Only show the part of the [`Mesh`] that falls within this.
129    pub clip_rect: emath::Rect,
130
131    /// What to paint - either a [`Mesh`] or a [`PaintCallback`].
132    pub primitive: Primitive,
133}
134
135/// A rendering primitive - either a [`Mesh`] or a [`PaintCallback`].
136#[derive(Clone, Debug)]
137pub enum Primitive {
138    Mesh(Mesh),
139    Callback(PaintCallback),
140}
141
142// ---------------------------------------------------------------------------
143
144/// Was epaint compiled with the `rayon` feature?
145pub const HAS_RAYON: bool = cfg!(feature = "rayon");