Skip to content

Menu

A set of actions that opens when the player asks for it and closes once they pick one: a game’s main actions, a player’s options, a build tool’s modes. The same menu can be a list on mouse and keyboard, a ring on a controller and a fan from a corner button on touch, so each player gets the shape that suits their hands, and none of its actions need a button of their own.

Menu exampleMenu example
local button = Lucy.Button.new({ text = "Club", variant = "outline", Parent = parent })
Lucy.Menu.new({
    id = "club",
    open = true,
    anchor = button,
    items = {
        { value = "join", label = "Join the set", icon = "lucy:plus" },
        { value = "request", label = "Request a track" },
        { value = "shop", label = "Emote Shop" },
        { value = "dances", label = "Dances" },
        { value = "exit", label = "Exit", icon = "lucy:close" },
    },
    onSelect = function(value)
        app.toast(`Picked {value}`)
    end,
    Parent = parent,
})

A menu has no button of its own: give it an anchor and open it from a button, a key or anything else.

button.Activated:Connect(function()
    menu:toggle()
end)

Props

PropTypeDefaultState keyWhat it does
itemstableThe actions, see Items
variantstring or responsive"list"list, radial or arc, see Variants
anchorinstance, handle or getterWhat it opens from. With none, a ring opens in the middle of the screen
returnFocusobject, handle, getter or falseWhere keyboard and gamepad focus goes when it closes, in place of its anchor. false leaves nothing selected, for a menu or panel opened from a HUD whose buttons must not keep the left stick
openbooleanfalseyesWhether it is open
sidestring"auto"List: auto, bottom, top, left or right, see Where it opens
alignstring"start"List: start, center or end: how the list lines up with the anchor
widthnumber220List: at least this wide (and at least the anchor’s width when above or below it)
radiusnumberby item count, 900 for a fanRing: the distance from the centre to each button. Fan: the radius of its curve (larger is straighter)
towardstring"auto"Fan: the side its labels go, left or right; auto puts them toward the middle of the screen
shapestring or responsive"round"Ring and fan buttons: round, squircle or square, see Button shapes
sizestring or responsive"md"md or lg, like a Button’s: lg rows are as tall as a large button with larger text, and lg ring and fan buttons are bigger, with larger icons and labels
onSelectfunctionCalled with (value, handle) when the player picks an action
mountstring"shown"When its rows and buttons are built: "shown" the first time it opens, "immediate" when it is made (Building its rows)
keepbooleantruefalse takes its rows away once it has closed and builds them again the next time it opens. With mount = "shown" only
onBuildfunctionCalled with the handle once its rows and buttons exist, each time they are built, before it shows: the place to style them
preloadlist or functionIts pictures, or a function returning them, read when needed. Warmed by warm(), and first in the queue when it opens. See Warming ahead
triggerbutton, handle or listWhat opens it. Hovered or focused, it warms (it does not open)
aheadoverlays or functionOverlays warmed when this one opens, such as a sheet opened from inside it
visiblebooleantrueyesShows or hides it

It also takes the props every component takes.

Items

An item is a value, shown as its text, or a table with value, and optionally:

  • label (or text): what it says.
  • icon: any name Icon draws, a lucy: icon or one of your own. A ring or fan button shows it, or the label’s initials when there is none.
  • hint: the name of an action. The list shows its key beside the item, so a player learns the shortcut.
  • disabled: shown faded, and cannot be picked.

label, icon and disabled can also be a ref or a getter, so a menu made once keeps up with the game (see Items that change).

Variants

  • list: a list next to its anchor, like a dropdown. On touch it is a drawer from the bottom of the screen, where a thumb can reach it.
  • radial: a ring of round buttons around the anchor, or the middle of the screen with no anchor. When the ring does not fit around an anchor by the edge of the screen (a button in a bottom bar), it opens clear of the anchor, toward the middle, so it never covers it. On a controller the left stick points at a button, and A picks it.
  • arc: a fan like a dock’s stack: buttons one above another from the anchor along a gentle curve, each tilted a little more than the last, with its label in a pill beside it. It rises from an anchor in the lower half of the screen and drops from one in the upper half; the labels sit on the side toward the middle (or on the side toward names) and the curve bends away from them. It moves in when a button or label would be off the screen, and when the stack is taller than the screen (a phone held sideways) it wraps into curves side by side, each past the labels of the last with room for a focused item’s ring. The first item sits nearest the anchor. Up and down (the D-pad, the stick or the arrow keys) walk every item in order, wrapping round, even across wrapped curves; left and right step to the next curve.

Ring buttons show their label under them.

Menu exampleMenu example
Lucy.Menu.new({
    open = true,
    variant = "radial",
    items = {
        { value = "join", label = "Join the set", icon = "lucy:plus" },
        { value = "request", label = "Request a track" },
        { value = "shop", label = "Emote Shop" },
        { value = "dances", label = "Dances" },
        { value = "items", label = "Items" },
        { value = "exit", label = "Exit", icon = "lucy:close" },
    },
    Parent = parent,
})

A variant for each input

variant takes a responsive value, so one menu can be a different variant for each input, and changes shape when the player picks up a controller or puts it down:

Lucy.Menu.new({
    items = actions,
    variant = { gamepad = "radial", touch = "arc", default = "list" },
    anchor = clubButton,
})

Button shapes

shape sets the outline of ring and fan buttons, to match the rest of a game’s buttons:

  • round: circles (the default).
  • squircle: rounded squares, softer than a square and firmer than a circle.
  • square: squares with the theme’s medium corner radius.

Like variant, it takes a responsive value.

Menu exampleMenu example
Lucy.Menu.new({
    open = true,
    variant = "radial",
    shape = "squircle",
    items = {
        { value = "join", label = "Join the set", icon = "lucy:plus" },
        { value = "request", label = "Request a track" },
        { value = "shop", label = "Emote Shop" },
        { value = "dances", label = "Dances" },
        { value = "exit", label = "Exit", icon = "lucy:close" },
    },
    Parent = parent,
})

Items that change

An item’s label, icon and disabled can be a ref or a getter. The item follows it, so a menu made once keeps up with the game, with no need to make it again. Here JOIN THE SET turns into LEAVE THE SET once the player is in, and PRACTICE fades out until they leave:

Menu exampleMenu example
local inSet = Lucy.ref(true)

Lucy.Menu.new({
    open = true,
    variant = "arc",
    shape = "squircle",
    items = {
        {
            value = "set",
            label = function()
                return if inSet() then "Leave the set" else "Join the set"
            end,
            icon = function()
                return if inSet() then "lucy:minus" else "lucy:plus"
            end,
        },
        { value = "practice", label = "Practice", disabled = inSet },
        { value = "request", label = "Request a track" },
        { value = "exit", label = "Exit", icon = "lucy:close" },
    },
    Parent = parent,
})

Building its rows

A menu is built the first time it opens: its overlay, its list or ring and every row and button. Until then nothing of it floats, so a game with menus on its HUD pays for them only when a player opens one. They are built before anything hears that it opened: focus lands on the first action, it is placed round its rows, and open is reported once they are there. Once built they are kept, so opening it again is instant.

The first time a ring or fan shows after it is built, it appears one frame later than it opens: that frame measures its labels, so it never shows placed for labels it has not measured. Focus and open do not wait.

To style the rows (tags for the game’s own look), do it in onBuild, which is called with the menu once menu.items and menu.slices exist:

Lucy.Menu.new({
    items = actions,
    variant = "arc",
    anchor = clubButton,
    onBuild = function(menu)
        for _, slice in menu.slices do
            Lucy.hydrate(slice)({ Tags = { "my-menu-button" } })
        end
    end,
})
  • keep = false takes the rows away once it has closed and builds them again the next time it opens. Use it for a big menu the player seldom opens.
  • mount = "immediate" builds them when the menu is made, for code that must reach them before it opens.
  • menu:build() builds them ahead of time without opening it, so the first open is instant (Lucy.prebuild({ menu, ... }) does it for several, one a frame, see Building on open).

Until they are built, menu.items and menu.slices are nil: code that reaches into them before the first open calls menu:build() first.

Where it opens

A list opens beside its anchor on the side you ask for, and moves to the other side when that has more room. With side = "auto" (the default) it opens below if it fits, then above, then to the right or left, so a menu from a top bar drops down and one from a bottom bar pops up. It stays inside the screen: a list near the right edge shifts left, and one beside its anchor shifts up or down to fit.

A ring is moved in from the edges until all of it shows. A fan always opens away from the edges, toward the middle of the screen.

Input

It opens on the app’s overlay layer, above everything opened before it, and holds keyboard and gamepad focus while open:

  • Mouse and touch: press an action. On a ring or fan the whole action takes the press, its button, its label and the gap between them. A press outside closes it, and so does a press on its anchor, even where a ring or fan covers it.
  • Keyboard and D-pad: move between actions and press Enter or A.
  • Stick: on a ring or fan, point the left stick at a button to select it.
  • Back: B or Backspace closes it without picking anything.

On a ring or fan, the focus ring goes round the whole action, its button and its label, following the button’s shape: a pill round a round button, a rounded box round a squircle or square one.

When it closes, the anchor is selected again on a controller.

Methods and events

NameWhat it does
menu:open()Opens it
menu:close()Closes it
menu:toggle()Opens it if closed, closes it if open
menu:select(value)Picks value as if the player had, and closes it
menu:build()Builds its rows and buttons now without opening it. Does nothing once they are built
menu.itemsIts list rows, one per item in order (nil until built)
menu.slicesIts ring and fan buttons, one per item in order (nil until built)
menu.variant()The variant in use: list, radial or arc
menu.shape()The button shape in use: round, squircle or square
menu.size()The size in use: md or lg
menu.presentation()For a list, "popup" or "drawer", for this opening

It reports open and close, and select with the value picked, for game sounds.

Preview

In Studio, from the command bar: Lucy.Preview.show("Menu").