Expand description
Anti-aliased immediate 2D shapes: rounded rectangles, circles, rings, arcs, capsules, polylines, gradients, soft shadows and additive glows.
Smooth edges come from geometry alone: each edge gets a thin fringe strip
whose outer vertices are transparent, about one device pixel wide. No texture,
shader or render-state change is needed, so these draws batch with ordinary
crate::draw_rectangle geometry and respect the current 2D camera. Every
call writes straight into the frame’s existing vertex stream and performs no
heap allocation of its own.
Vertex counts are bounded per call (see each function). Curves use 2–16 segments per quarter turn, chosen from the on-screen radius. Their unit directions come from tables built once per process, so the hot path runs no per-point trigonometry (arcs and round joins rotate incrementally and re-anchor every 16 steps). Coordinates are the current camera’s logical units (pixels with the default camera). Non-finite or degenerate input draws nothing.
use ferravex_render::{Color, Rect, vec2, shapes::{self, Fill, Shadow}};
let card = Rect::new(40., 40., 240., 120.);
shapes::drop_shadow(card, 12., Shadow::soft(Color::new(0., 0., 0., 0.45)));
shapes::fill_rounded_rect(card, 12., Fill::vertical(card,
Color::from_hex(0x2b3550), Color::from_hex(0x1b2133)));
shapes::stroke_rounded_rect(card, 12., 1., Color::new(1., 1., 1., 0.12));
shapes::fill_circle(vec2(80., 100.), 16., Color::from_hex(0xf7b553));
shapes::glow_disc(vec2(80., 100.), 48., Color::new(1., 0.7, 0.3, 0.6));Structs§
- Shadow
- Soft drop shadow parameters for
drop_shadow. - Stroke
- Line style for
polylineandstroke_arc.
Enums§
- Cap
- How a
polylineorstroke_arcends. - Fill
- Paint for filled shapes. Gradients are evaluated per vertex and interpolated by the GPU; linear gradients are exact on these convex fans. A radial gradient on a circle it is centered on (reaching at least its edge) is exact along every spoke; on any other shape the fill is drawn on a subdivided mesh (four bands, long edges split) so the gradient follows its own circles instead of stretching to the outline.
- Join
- How a
polylineturns a corner.
Constants§
- MAX_
POLYGON_ POINTS - Most corners
fill_polygonaccepts; longer input draws nothing.
Functions§
- drop_
shadow - Soft shadow under a rounded rectangle. The falloff follows a smoothstep
across
blur, approximating a Gaussian with four feathered rings. Emits at most 1,836 vertices. - fill_
capsule - Filled, anti-aliased capsule (a segment with round ends) of
radius. Coincident end points draw a circle. Emits at most 612 vertices, or 2,592 for a subdividedFill::Radial. - fill_
circle - Filled, anti-aliased circle (up to 64 segments). Emits at most 612 vertices, or 2,592 for a radial fill that is not centered on the circle.
- fill_
polygon - Filled, anti-aliased convex polygon through
pointsin either winding. - fill_
rounded_ rect - Filled, anti-aliased rounded rectangle.
radiusis clamped to half the shorter side; zero gives crisp-but-smooth square corners. Emits at most 612 vertices, or 2,592 for a subdividedFill::Radial. - fill_
sector - Filled, anti-aliased pie slice of
radiusfromstartsweepingsweepradians (positive is clockwise on screen with Y down), for cooldown dials, timers and progress pies. A full turn or more fills the circle; a zero or non-finite sweep draws nothing. Emits at most 588 vertices. - fill_
triangle - Filled, anti-aliased triangle; a convenience for
fill_polygon. - glow_
disc - Additive soft glow disc for particles, pickups and highlights. Brightness
falls off as
(1 - r/radius)²over up to 12 rings;color.ascales intensity. Additive light brightens what is underneath and never darkens. Emits at most 3,312 vertices throughcrate::effects::draw_triangles(its per-frame budget applies); a 24-unit particle glow uses 4 rings. - glow_
ring - Additive soft glow ring (shockwaves, selection halos, portals) of total
widthcentered onradius, brightest on the center line and fading as(1 - |offset|)²toward both edges. Emits at most 6,912 vertices throughcrate::effects::draw_triangles; a 16-unit-wide ring uses 4 bands. - mix
- Linear color interpolation (
tis not clamped). - polyline
- Anti-aliased polyline through caller-owned
pointswith joins and caps. - stroke_
arc - Anti-aliased arc of
radiusfromstartsweepingsweepradians (positive is clockwise on screen with Y down). Useful for radial meters and cooldowns. A sweep of a full turn or more draws a closed ring. Emits at most 1,782 vertices. - stroke_
circle - Anti-aliased ring of
widthcentered onradius. Emits at most 1,224 vertices. - stroke_
rounded_ rect - Anti-aliased rounded-rectangle border of
width, centered on the edge ofrect. Strokes thinner than a device pixel fade instead of vanishing. Emits at most 1,224 vertices.