Plushie.Type.Gradient (Plushie v0.6.0)

Copy Markdown View Source

Gradient backgrounds for container widgets.

Used via the background prop on containers. The renderer parses gradient maps and converts them to iced::gradient::Linear.

Wire format

%{
  type: "linear",
  angle: 45,
  stops: [
    %{offset: 0.0, color: "#ff0000"},
    %{offset: 1.0, color: "#0000ff"}
  ]
}

angle is in degrees (converted to radians by the renderer).

Example

gradient = Plushie.Type.Gradient.linear(90, [
  {0.0, "#ff0000"},
  {0.5, "#00ff00"},
  {1.0, "#0000ff"}
])

Summary

Types

A gradient color stop with offset (0.0-1.0) and color (canonical hex string).

Color input for gradient stops: any Color.input() form, or a float RGBA map.

t()

Gradient specification with type, angle, and color stops.

Functions

Encodes a gradient to the wire format.

Creates a linear gradient with an angle (degrees) and a list of {offset, color} stops. Colors accept any form Color.cast/1 supports (hex strings or named atoms).

Types

stop()

@type stop() :: %{offset: float(), color: String.t()}

A gradient color stop with offset (0.0-1.0) and color (canonical hex string).

stop_color()

@type stop_color() ::
  Plushie.Type.Color.input() | %{r: float(), g: float(), b: float(), a: float()}

Color input for gradient stops: any Color.input() form, or a float RGBA map.

t()

@type t() :: %{type: String.t(), angle: number(), stops: [stop()]}

Gradient specification with type, angle, and color stops.

Functions

encode(gradient)

@spec encode(gradient :: t()) :: t()

Encodes a gradient to the wire format.

linear(angle, stops)

@spec linear(angle :: number(), stops :: [{number(), stop_color()}]) :: t()

Creates a linear gradient with an angle (degrees) and a list of {offset, color} stops. Colors accept any form Color.cast/1 supports (hex strings or named atoms).