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 brush;
27pub mod color;
28mod corner_radius;
29mod corner_radius_f32;
30pub mod image;
31mod margin;
32mod marginf;
33mod mesh;
34pub mod mutex;
35mod shadow;
36pub mod shape_transform;
37mod shapes;
38pub mod stats;
39mod stroke;
40pub mod tessellator;
41pub mod text;
42mod texture_atlas;
43mod texture_handle;
44pub mod textures;
45pub mod util;
46mod viewport;
47
48pub use self::{
49 brush::Brush,
50 color::ColorMode,
51 corner_radius::CornerRadius,
52 corner_radius_f32::CornerRadiusF32,
53 image::{ColorImage, FontImage, ImageData, ImageDelta},
54 margin::Margin,
55 marginf::Marginf,
56 mesh::{Mesh, Mesh16, Vertex},
57 shadow::Shadow,
58 shapes::{
59 CircleShape, CubicBezierShape, EllipseShape, PaintCallback, PaintCallbackInfo, PathShape,
60 QuadraticBezierShape, RectShape, Shape, TextShape,
61 },
62 stats::PaintStats,
63 stroke::{PathStroke, Stroke, StrokeKind},
64 tessellator::{TessellationOptions, Tessellator},
65 text::{FontFamily, FontId, Fonts, Galley},
66 texture_atlas::TextureAtlas,
67 texture_handle::TextureHandle,
68 textures::TextureManager,
69 viewport::ViewportInPixels,
70};
71
72#[deprecated = "Renamed to CornerRadius"]
73pub type Rounding = CornerRadius;
74
75#[allow(deprecated)]
76pub use tessellator::tessellate_shapes;
77
78pub use ecolor::{Color32, Hsva, HsvaGamma, Rgba};
79pub use emath::{pos2, vec2, Pos2, Rect, Vec2};
80
81#[deprecated = "Use the ahash crate directly."]
82pub use ahash;
83
84pub use ecolor;
85pub use emath;
86
87#[cfg(feature = "color-hex")]
88pub use ecolor::hex_color;
89
90/// The UV coordinate of a white region of the texture mesh.
91///
92/// The default egui texture has the top-left corner pixel fully white.
93/// You need need use a clamping texture sampler for this to work
94/// (so it doesn't do bilinear blending with bottom right corner).
95pub const WHITE_UV: emath::Pos2 = emath::pos2(0.0, 0.0);
96
97/// What texture to use in a [`Mesh`] mesh.
98///
99/// If you don't want to use a texture, use `TextureId::Managed(0)` and the [`WHITE_UV`] for uv-coord.
100#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
101#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
102pub enum TextureId {
103 /// Textures allocated using [`TextureManager`].
104 ///
105 /// The first texture (`TextureId::Managed(0)`) is used for the font data.
106 Managed(u64),
107
108 /// Your own texture, defined in any which way you want.
109 /// The backend renderer will presumably use this to look up what texture to use.
110 User(u64),
111}
112
113impl Default for TextureId {
114 /// The epaint font texture.
115 fn default() -> Self {
116 Self::Managed(0)
117 }
118}
119
120/// A [`Shape`] within a clip rectangle.
121///
122/// Everything is using logical points.
123#[derive(Clone, Debug, PartialEq)]
124pub struct ClippedShape {
125 /// Clip / scissor rectangle.
126 /// Only show the part of the [`Shape`] that falls within this.
127 pub clip_rect: emath::Rect,
128
129 /// The shape
130 pub shape: Shape,
131}
132
133/// A [`Mesh`] or [`PaintCallback`] within a clip rectangle.
134///
135/// Everything is using logical points.
136#[derive(Clone, Debug)]
137pub struct ClippedPrimitive {
138 /// Clip / scissor rectangle.
139 /// Only show the part of the [`Mesh`] that falls within this.
140 pub clip_rect: emath::Rect,
141
142 /// What to paint - either a [`Mesh`] or a [`PaintCallback`].
143 pub primitive: Primitive,
144}
145
146/// A rendering primitive - either a [`Mesh`] or a [`PaintCallback`].
147#[derive(Clone, Debug)]
148pub enum Primitive {
149 Mesh(Mesh),
150 Callback(PaintCallback),
151}
152
153// ---------------------------------------------------------------------------
154
155/// Was epaint compiled with the `rayon` feature?
156pub const HAS_RAYON: bool = cfg!(feature = "rayon");