Color type for iced widget properties.
All colors are canonical hex strings: "#rrggbb" or "#rrggbbaa".
Use the constructors from_rgb/3, from_rgba/4, and from_hex/1 to build
colors. Use cast/1 to normalize any supported input form (named atoms
or hex strings) into a canonical hex string.
All 148 CSS Color Module Level 4 named colors are supported, plus
:transparent.
Examples
iex> Toddy.Iced.Color.from_rgb(255, 128, 0)
"#ff8000"
iex> Toddy.Iced.Color.from_hex("ff8800")
"#ff8800"
iex> Toddy.Iced.Color.cast(:red)
"#ff0000"
iex> Toddy.Iced.Color.cast(:cornflowerblue)
"#6495ed"
Summary
Types
Named CSS color atom (148 CSS Color Module Level 4 colors plus :transparent).
Canonical hex color string ("#rrggbb" or "#rrggbbaa").
Functions
Returns black as a hex string.
Normalizes any supported color input to a canonical hex string.
Encodes a color for the wire format. Identity since all colors are hex strings.
Normalizes a hex string (with or without leading #) to canonical form.
Creates a hex color string from 0-255 RGB integer values.
Creates a hex color string with alpha from 0-255 RGB integers and a 0.0-1.0 alpha float.
Returns the map of all supported named colors.
Returns fully transparent black as a hex string.
Returns white as a hex string.
Types
Any value accepted by cast/1: hex string, short hex, or named color atom.
@type named() ::
:transparent
| :beige
| :hotpink
| :lawngreen
| :turquoise
| :firebrick
| :blueviolet
| :lightslategrey
| :seagreen
| :silver
| :lightsalmon
| :powderblue
| :darkslateblue
| :darkgreen
| :cornflowerblue
| :khaki
| :mediumturquoise
| :coral
| :goldenrod
| :orange
| :indianred
| :springgreen
| :yellowgreen
| :darkslategray
| :papayawhip
| :black
| :orchid
| :lightseagreen
| :darkmagenta
| :orangered
| :crimson
| :steelblue
| :ghostwhite
| :peachpuff
| :white
| :forestgreen
| :sienna
| :navajowhite
| :blue
| :tomato
| :darkolivegreen
| :darkcyan
| :burlywood
| :darkgoldenrod
| :ivory
| :lightyellow
| :darkkhaki
| :greenyellow
| :wheat
| :plum
| :lavender
| :lightgrey
| :chocolate
| :salmon
| :darkturquoise
| :dodgerblue
| :lightskyblue
| :cadetblue
| :aqua
| :lavenderblush
| :linen
| :lightgray
| :pink
| :magenta
| :sandybrown
| :darksalmon
| :yellow
| :mediumpurple
| :floralwhite
| :lightslategray
| :dimgrey
| :slategray
| :mintcream
| :lime
| :midnightblue
| :palegreen
| :maroon
| :lightcyan
| :lightcoral
| :azure
| :mediumslateblue
| :antiquewhite
| :lightblue
| :mediumorchid
| :slategrey
| :lightpink
| :gainsboro
| :grey
| :honeydew
| :royalblue
| :mediumblue
| :red
| :mediumaquamarine
| :gold
| :indigo
| :darkred
| :lightsteelblue
| :brown
| :darkslategrey
| :lightgoldenrodyellow
| :thistle
| :aliceblue
| :whitesmoke
| :chartreuse
| :snow
| :olivedrab
| :rebeccapurple
| :navy
| :green
| :darkgrey
| :deepskyblue
| :paleturquoise
| :palevioletred
| :gray
| :darkviolet
| :darkorchid
| :teal
| :tan
| :darkseagreen
| :mediumvioletred
| :fuchsia
| :lemonchiffon
| :olive
| :slateblue
| :mediumseagreen
| :darkorange
| :purple
| :cornsilk
| :rosybrown
| :limegreen
| :mistyrose
| :cyan
| :palegoldenrod
| :aquamarine
| :bisque
| :mediumspringgreen
| :peru
| :seashell
| :saddlebrown
| :moccasin
| :dimgray
| :blanchedalmond
| :skyblue
| :lightgreen
| :violet
| :deeppink
| :darkblue
| :oldlace
| :darkgray
Named CSS color atom (148 CSS Color Module Level 4 colors plus :transparent).
@type t() :: String.t()
Canonical hex color string ("#rrggbb" or "#rrggbbaa").
Functions
@spec black() :: t()
Returns black as a hex string.
Normalizes any supported color input to a canonical hex string.
Accepts:
- Named atoms: all 148 CSS Color Module Level 4 named colors (e.g.
:red,:cornflowerblue,:rebeccapurple) plus:transparent - Hex strings:
"#rrggbb","#rrggbbaa","#rgb","#rgba"(normalized to canonical 6/8-char lowercase hex)
Raises ArgumentError for unsupported atoms.
Examples
iex> Toddy.Iced.Color.cast(:black)
"#000000"
iex> Toddy.Iced.Color.cast(:transparent)
"#00000000"
iex> Toddy.Iced.Color.cast("#FF0000")
"#ff0000"
iex> Toddy.Iced.Color.cast(:cornflowerblue)
"#6495ed"
Encodes a color for the wire format. Identity since all colors are hex strings.
Examples
iex> Toddy.Iced.Color.encode("#ff0000")
"#ff0000"
Normalizes a hex string (with or without leading #) to canonical form.
Downcases the hex digits for consistency.
Examples
iex> Toddy.Iced.Color.from_hex("#FF8800")
"#ff8800"
iex> Toddy.Iced.Color.from_hex("ff8800")
"#ff8800"
iex> Toddy.Iced.Color.from_hex("#ff880080")
"#ff880080"
Creates a hex color string from 0-255 RGB integer values.
Examples
iex> Toddy.Iced.Color.from_rgb(0, 0, 0)
"#000000"
iex> Toddy.Iced.Color.from_rgb(255, 255, 255)
"#ffffff"
iex> Toddy.Iced.Color.from_rgb(255, 128, 0)
"#ff8000"
Creates a hex color string with alpha from 0-255 RGB integers and a 0.0-1.0 alpha float.
Examples
iex> Toddy.Iced.Color.from_rgba(255, 0, 0, 1.0)
"#ff0000ff"
iex> Toddy.Iced.Color.from_rgba(0, 0, 0, 0.0)
"#00000000"
iex> Toddy.Iced.Color.from_rgba(255, 128, 0, 0.5)
"#ff800080"
Returns the map of all supported named colors.
Keys are atoms, values are canonical hex strings.
@spec transparent() :: t()
Returns fully transparent black as a hex string.
@spec white() :: t()
Returns white as a hex string.