Module shapes

Source
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 polyline and stroke_arc.

Enums§

Cap
How a polyline or stroke_arc ends.
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 polyline turns a corner.

Constants§

MAX_POLYGON_POINTS
Most corners fill_polygon accepts; 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 subdivided Fill::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 points in either winding.
fill_rounded_rect
Filled, anti-aliased rounded rectangle. radius is clamped to half the shorter side; zero gives crisp-but-smooth square corners. Emits at most 612 vertices, or 2,592 for a subdivided Fill::Radial.
fill_sector
Filled, anti-aliased pie slice of radius from start sweeping sweep radians (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.a scales intensity. Additive light brightens what is underneath and never darkens. Emits at most 3,312 vertices through crate::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 width centered on radius, brightest on the center line and fading as (1 - |offset|)² toward both edges. Emits at most 6,912 vertices through crate::effects::draw_triangles; a 16-unit-wide ring uses 4 bands.
mix
Linear color interpolation (t is not clamped).
polyline
Anti-aliased polyline through caller-owned points with joins and caps.
stroke_arc
Anti-aliased arc of radius from start sweeping sweep radians (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 width centered on radius. Emits at most 1,224 vertices.
stroke_rounded_rect
Anti-aliased rounded-rectangle border of width, centered on the edge of rect. Strokes thinner than a device pixel fade instead of vanishing. Emits at most 1,224 vertices.