Icon
A small picture that takes its colour from the theme, so it changes with light and dark mode and with the text around it. Name it, or give it an asset id.
local function stat(icon, variant, text)
return Lucy.Stack.new({
direction = "horizontal",
gap = "Space2",
align = "center",
children = {
Lucy.Icon.new({ icon = icon, variant = variant, size = "lg" }),
Lucy.Text.new({ text = text, variant = "large", autoWidth = true }),
},
})
end
Lucy.Stack.new({
direction = "horizontal",
gap = "Space6",
align = "center",
children = {
stat("lucide-extended:heart-duotone", "destructive", "72 hype"),
stat("lucide-extended:flame-duotone", "warning", "8x combo"),
stat("lucide-extended:coins-duotone", "primary", "1250 coins"),
},
Parent = parent,
})
Registering icons
Apart from the few icons Lucy draws in its own components, icons come from your game. It registers a map of names to images once, before it builds any UI:
Lucy.Icon.register({
["club:coin"] = { image = 1234567 },
["club:logo"] = { image = 7654321, tint = false },
})
Write the map yourself for your own images, or let the lucy-icons build make it
from any Iconify icon you name in your
code, such as "lucide-extended:heart-duotone". Add icons covers both,
with every field of the map.
On a client, every sheet you register is pinned
when you register it, and Lucy's own sheet the first time one of its icons is
drawn: one picture holds every icon on it, so keeping it in use means an icon
never pops in. Unregistering lets a sheet go once no registered icon uses it.
Set Lucy.Icon.pin = false before registering to turn this off.
Props
| Prop | Type | Default | State key | What it does |
|---|---|---|---|---|
icon | string or number | "" | yes | A registered name, an asset id or a url |
size | string or number | "md" | yes | sm (16 pixels), md (20), lg (24), xl (28), or a number of pixels. A quarter larger on TV |
variant | string | "default" | yes | The colour: default (the text colour), muted, primary, destructive, success, warning or info |
visible | boolean | true | yes | Shows or hides it |
It also takes the props every component takes.
A name that was never registered draws nothing and warns once in the output, so the rest of the screen still builds. Register before you build: an icon does not change when a name is registered later.
Lucy.Icon.has(name) tells you whether a name is registered, and
Lucy.Icon.resolve(value) what it would draw.
Examples
An icon before a label:
Lucy.Stack.new({
direction = "horizontal",
gap = "Space2",
align = "center",
children = {
Lucy.Icon.new({ icon = "lucide-extended:music-filled", variant = "muted" }),
Lucy.Text.new({ text = "Now playing", autoWidth = true }),
},
Parent = header,
})
As the media of a list row:
Lucy.Item.new({
title = "Streamer mode",
media = Lucy.Icon.new({ icon = "lucide-extended:radio-filled", size = "lg" }),
actions = { Lucy.Switch.new({ checked = streamerMode }) },
Parent = settings,
})
For artwork that keeps its colours, such as a song cover, use Image.
Preview
In Studio, from the command bar: Lucy.Preview.show("Icon").