Documentation / Reference
Rectangle
Draw a closed rectangle that fills the supplied bounds.
Construction
Import the drawing API from refract::prelude::*.
use refract::prelude::*;
fn illustration() -> impl View {
shape(Rectangle)
.fill(Color::BLUE)
.width(120.0)
.height(80.0)
}Geometry and layout
Rectangle produces a four-sided path with square corners. A view's radius modifier does not change this path; draw custom geometry when the path itself needs rounded corners.
Rectangle is a unit struct implementing Shape. It has no constructor arguments or view modifiers of its own. Use shape(Rectangle) to create a view, or Rectangle.path(bounds) to obtain a path inside a canvas.
View-specific reference
Configure these methods before wrappers or type erasure consume the concrete builder.
| Method | Purpose |
|---|---|
fill | Sets the shape's fill to a solid Color or a Paint gradient. Shapes start with a black fill. Filling does not remove an existing stroke; the fill is drawn first. |
no_fill | Removes the fill. Use before stroke for an outline-only shape. A shape with neither a fill nor a stroke draws no ink. |
stroke | Sets the outline paint and stroke style. Width uses logical pixels; caps, joins, dashes, and dash offset come from StrokeStyle. Strokes are centered on the path, and ink outside the canvas content box is clipped. This does not remove the fill or inset the geometry. |
fill
Sets the shape's fill to a solid Color or a Paint gradient. Shapes start with a black fill. Filling does not remove an existing stroke; the fill is drawn first.
fn fill(self, paint: impl Into<Paint>) -> Selfno_fill
Removes the fill. Use before stroke for an outline-only shape. A shape with neither a fill nor a stroke draws no ink.
fn no_fill(self) -> Selfstroke
Sets the outline paint and stroke style. Width uses logical pixels; caps, joins, dashes, and dash offset come from StrokeStyle. Strokes are centered on the path, and ink outside the canvas content box is clipped. This does not remove the fill or inset the geometry.
fn stroke(self, paint: impl Into<Paint>, style: impl Into<StrokeStyle>) -> SelfCommon view modifiers
fill, no_fill, and stroke preserve ShapeView<S>. Configure them first: shared modifiers such as width, height, background, and padding use ViewExt and return wrappers, so shape-specific methods are no longer available afterward. foreground does not replace a shape's explicit fill.
Shape values are geometry, not views on their own. Pass them to shape(...) or call their path(bounds) method inside a canvas. See View Modifiers and Canvas.
Source reference
The implementation is in crates/core/src/drawing/shape.rs.