# Rectangle

Draw a closed rectangle that fills the supplied bounds.

<a id="construction"></a>

## Construction

Import the drawing API from refract::prelude::*.

```rust
use refract::prelude::*;

fn illustration() -> impl View {
    shape(Rectangle)
        .fill(Color::BLUE)
        .width(120.0)
        .height(80.0)
}
```

<a id="geometry"></a>

## 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.

<a id="view-specific-reference"></a>

## View-specific reference

Configure these methods before wrappers or type erasure consume the concrete builder.

| Method | Purpose |
| --- | --- |
| [`fill`](#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`](#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`](#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. |

<a id="fill"></a>

### `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.

```rust
fn fill(self, paint: impl Into<Paint>) -> Self
```

<a id="no-fill"></a>

### `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.

```rust
fn no_fill(self) -> Self
```

<a id="stroke"></a>

### `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.

```rust
fn stroke(self, paint: impl Into<Paint>, style: impl Into<StrokeStyle>) -> Self
```

<a id="common-modifiers"></a>

## Common 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](/docs/view-modifiers#drawing) and [Canvas](/docs/canvas).

<a id="source"></a>

## Source reference

The implementation is in `crates/core/src/drawing/shape.rs`.
