Shapes

Shapes describe simple geometry that an app can draw and style as part of its interface. They are useful for diagrams, indicators, and illustrations that need to resize with the layout.

Day provides rectangles, circles, ellipses, capsules, arcs, lines, and polygons as pieces. Shapes size with their layout bounds and redraw when their reactive properties change. Use a shape group for a small illustration, or a canvas for a dense drawing or arbitrary paths.

Add to your app

This control is included in day-pieces and re-exported through day::prelude::*. No additional crate or control feature is required.

Authoring

This example draws a decorative marker from two shapes in one view.

use day::prelude::*;

pub fn marker() -> impl Piece {
    shape_group([
        circle().fill(Color::hex(0x2463eb)),
        circle()
            .fill(Color::hex(0xffffff))
            .at(0.35, 0.35, 0.30, 0.30),
    ])
    .frame(32.0, 32.0)
    .a11y(|a| a.decorative())
}
# This decorative drawing has no user-facing text.

For meaningful or interactive graphics, provide a localized accessibility label and role. See accessibility.

Geometry and sizing

ConstructorGeometry
rectangle()Fills the assigned rectangle.
rounded_rectangle(corner)Rectangle with a fixed corner radius in points, or a Corner value.
circle()Centered circle whose diameter is the shorter side.
ellipse()Ellipse filling the bounds.
capsule()Rounded rectangle with a radius of half the shorter side.
arc(start_deg, sweep_deg)Arc of the bounds’ ellipse; zero degrees points right and positive angles run clockwise.
line(from, to)Segment between fractional (x, y) points; requires a stroke.
polygon(points)Closed polygon through fractional (x, y) points.

shape(kind) accepts a constant or reactive ShapeKind. Shapes grow to fill available space; use .frame(width, height) or a bounded parent to give them a useful size.

Line and polygon coordinates are fractions of the bounds and are not clamped to 0–1. Corner::Fixed is clamped to half the shorter side; Corner::Fraction(1.0) gives that maximum radius.

Fills and strokes

.fill(color) sets a solid fill. Use .fill_linear(gradient) or .fill_radial(gradient) for gradients. These accept values, signals, or closures. If several fill types are set, radial takes precedence over linear, then solid; call order does not change that precedence.

.stroke(color, width) adds a solid outline. Shapes have no fill or stroke by default. A line ignores fills. For gradient strokes, dash patterns, and arbitrary paths, use the canvas drawing API.

Closed shapes other than polygons inset their geometry by half the stroke width to keep the outline within the frame. Lines and polygons use their authored points exactly; strokes at an edge may clip. See Colors for color and gradient values.

Placement and transforms

ModifierEffect
.at(x, y, width, height)Places the shape in a fractional subrectangle of its bounds.
.inset(points)Insets that rectangle before resolving the geometry.
.rotate(degrees)Rotates the drawing around its center.
.scale(factor)Scales the drawing uniformly around its center.
.offset(x, y)Translates the drawing within its layout frame.

Drawing transforms do not change the shape’s allocated layout size. Inset, rotation, scale, and offset can read reactive values. Use animation to interpolate those values over time.

Shape groups

shape_group(shapes) draws shapes in order in a single canvas view. Each child’s reactive properties still update the drawing. shape_group_fn(f) receives the laid-out size and returns a vector of shapes, for geometry that depends on available space.

A group has one identity and accessibility node. Child gesture handlers are not connected; put gestures and accessibility information on the group. Use separate shape pieces when children need independent focus, actions, or labels.

Gestures

.on_tap(f) on a shape checks the tap in its transformed local coordinates. Circles and ellipses use ellipse containment; polygons use polygon containment. Rectangles, rounded rectangles, arcs, and lines use rectangular bounds, so hit testing does not follow every visible contour.

.on_drag(f) reports a Drag with phase, local pointer location, and cumulative translation. The press location is location - translation; the first reported drag event may arrive after the pointer has already moved. Drag handling does not use the tap containment test.

On iOS and Android, a shape with no tap, drag, hover, context menu or key handler takes no touches: a tap on it reaches whatever is beneath it, so a border stroked over a row of controls with .overlay(...) leaves the controls working.

Toolkit implementations

Shapes use each toolkit’s canvas renderer. Drawing support and export limits follow the canvas reference. A shape group reduces the number of native views; it does not provide a separate view for each child.