Search documentation of Plushie

# Plushie.Type.Border (Plushie v0.7.2)

Copy Markdown View Source

Border specification for container and widget styling.

A border has three properties:

- `color` - hex color string (e.g. `"#ff0000"`). `nil` means no color override.
- `width` - border width in pixels. Default: `0`.
- `radius` - corner radius. Either a uniform number or a per-corner `radius_map()` from `radius/4`. Default: `0`.

## Wire format

The encoded border is a map:

    %{color: "#ff0000", width: 2, radius: 8}

Radius can be a uniform number or a per-corner map:

    %{top_left: 8, top_right: 8, bottom_right: 0, bottom_left: 0}

## Example

    border = Plushie.Type.Border.new()
             |> Plushie.Type.Border.color("#3366ff")
             |> Plushie.Type.Border.width(2)
             |> Plushie.Type.Border.rounded(8)

## Summary

### Types

radius_map()

Per-corner radius map.

t()

Border specification with color, width, and radius.

### Functions

cast(border)

Validates a border value.

color(border, color)

Sets the border color. Accepts a hex string or named color atom.

encode(border)

Encodes a border to the wire format.

from_opts(opts)

Constructs a `Border` from a keyword list.

new()

Creates a new border with default values (no color, zero width, zero radius).

radius(top_left, top_right, bottom_right, bottom_left)

Creates a per-corner radius map.

rounded(border, radius)

Sets a uniform corner radius in pixels.

width(border, width)

Sets the border width in pixels.

## Types

# radius_map()

    @type radius_map() :: %{
      top_left: number(),
      top_right: number(),
      bottom_right: number(),
      bottom_left: number()
    }

Per-corner radius map.

# t()

    @type t() :: %Plushie.Type.Border{
      color: Plushie.Type.Color.t() | nil,
      radius: number() | radius_map(),
      width: number()
    }

Border specification with color, width, and radius.

## Functions

# cast(border)

    @spec cast(term()) :: {:ok, t()} | :error

Validates a border value.

Accepts a `%Border{}` struct or a map with border fields.

## Examples

    iex> Plushie.Type.Border.cast(%Plushie.Type.Border{width: 2})
    {:ok, %Plushie.Type.Border{width: 2}}

# color(border, color)

    @spec color(border :: t(), color :: Plushie.Type.Color.input()) :: t()

Sets the border color. Accepts a hex string or named color atom.

# encode(border)

    @spec encode(border :: t()) :: map()

Encodes a border to the wire format.

# from_opts(opts)

    @spec from_opts(opts :: keyword()) :: t()

Constructs a `Border` from a keyword list.

# new()

    @spec new() :: t()

Creates a new border with default values (no color, zero width, zero radius).

# radius(top_left, top_right, bottom_right, bottom_left)

    @spec radius(
      top_left :: number(),
      top_right :: number(),
      bottom_right :: number(),
      bottom_left :: number()
    ) :: radius_map()

Creates a per-corner radius map.

# rounded(border, radius)

    @spec rounded(border :: t(), radius :: number()) :: t()

Sets a uniform corner radius in pixels.

# width(border, width)

    @spec width(border :: t(), width :: number()) :: t()

Sets the border width in pixels.