Documentation / Reference

Path

Construct shared vector paths in local logical pixels.

Build a path

Path is geometry, not a view. Draw it with GraphicsContext::fill or stroke, or pass it to shape(path). Clones share storage until a mutation copies the elements. Coordinates use f64 logical pixels, with positive x to the right and positive y downward.

triangle.rs
use refract::prelude::*;

fn triangle() -> Path {
    let mut path = Path::new();
    path.move_to((50.0, 8.0));
    path.line_to((92.0, 84.0));
    path.line_to((8.0, 84.0));
    path.close();
    path
}

Segments and subpaths

Mutation methods operate on &mut Path. Begin each subpath with move_to. A closed path joins its last point back to the start; polyline leaves the path open. Segment methods accept Point or an (f64, f64) tuple.

MethodBehavior
move_to(point)Starts a subpath.
line_to(point)Adds a straight segment.
quad_to(control, end)Adds a quadratic Bézier segment.
cubic_to(first, second, end)Adds a cubic Bézier segment with two control points.
close()Closes the current subpath; an empty path stays empty.
elements() -> &[PathElement]Borrows the recorded move, line, curve, and close commands.

Convenience geometry

polygon and polyline accept an iterator of Point values. Rect uses x, y, width, and height; Size uses width and height.

ConstructorBehavior
Path::polygon(points)Connects points and closes the path.
Path::polyline(points)Connects points without closing.
Path::rectangle(rect)Creates a closed rectangle.
Path::ellipse(rect)Creates a closed ellipse inside the rectangle.
Path::arc(center, radii, start, sweep)Approximates an elliptical arc with cubic curves. Angles use radians; sweep is clamped to one revolution in either direction. The result is open.
path.bounds() -> Option<Rect>Returns conservative control-point bounds, not exact curve extrema. Empty paths return None.

Paint and placement

Paths store no paint or layout constraints. Use shape for a simple fill/stroke view or canvas for layers, clips, and transforms. See Canvas for paints, stroke styles, and effects. The implementation is in crates/core/src/drawing/geometry.rs.