# shape

Fill or stroke built-in geometry, an existing path, or your own Shape implementation.

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

## Construction

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

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

fn disc() -> impl View {
    shape(Circle)
        .fill(Color::BLUE)
        .width(80.0)
        .height(80.0)
}
```

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

## Geometry from bounds

shape<S: Shape>(geometry: S) returns ShapeView<S>. Shape requires fn path(&self, bounds: Rect) -> Path and a 'static lifetime. Geometry is generated from the canvas bounds when drawing; it does not determine the layout allocation.

Circle fits the largest centered circle; Ellipse and Rectangle fill the supplied bounds. Path also implements Shape, returning its existing coordinates unchanged. For a fixed-coordinate path that must scale to fit, use canvas(...).view_box(...).

| Geometry | Reference |
| --- | --- |
| Circle | [Centered circle](/docs/circle) |
| Ellipse | [Ellipse filling bounds](/docs/ellipse) |
| Rectangle | [Rectangle filling bounds](/docs/rectangle) |
| Path | [Explicit paths and curves](/docs/path) |

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