UI Toolbox logoUI Toolbox

RadialMenu

RadialMenu in UIToolbox is a ring of wedges, as a weapon wheel or a quick menu of a game. Each RadialMenuItem has a wedge. The first item is at the top, and the others follow clockwise. The center shows the text of the highlighted item. An item can have sub-items, which fold out in a second ring. The RadialMenuDemo example scene has a weapon wheel, a build wheel and a command wheel.

<tb:RadialMenu name="wheel" inner-radius="0.45" cancel-text="Cancel">
    <tb:RadialMenuItem text="Sword" />
    <tb:RadialMenuItem text="Bow">
        <tb:RadialMenuItem text="Fire" />
        <tb:RadialMenuItem text="Ice" />
    </tb:RadialMenuItem>
</tb:RadialMenu>
var potion = wheel.AddItem("Potion");
potion.AddItem("Health", () => player.Drink(Potion.Health));
potion.AddItem("Mana", () => player.Drink(Potion.Mana));
wheel.ItemChosen += item => equip(item.Text);
wheel.Cancelled += closeWheel;
// A stick that points the wheel. A Value action is canceled, not performed, when the stick goes back.
stick.performed += context => wheel.Point(context.ReadValue<Vector2>());
stick.canceled += _ => wheel.Point(Vector2.zero);
Member Description
AddItem(text, action), Items The items, clockwise from the top. A child RadialMenuItem in UXML is an item too.
HighlightedIndex, Highlighted, HighlightChanged The highlighted item. A disabled item cannot be highlighted. A removed or disabled item loses the highlight. HighlightedIndex is -1 while a sub-item is highlighted; Highlighted is the sub-item.
Point(direction) Highlights the item in the direction of a stick, with y up. A direction shorter than 0.5 keeps the highlight.
Choose(), ItemChosen Chooses the highlighted item. RadialMenuItem.Chosen occurs first, then ItemChosen. For an item with sub-items, Choose() goes into the sub-items and raises no event.
Cancel(), Cancelled Cancel() goes back from a sub-item to its parent. With no sub-item highlighted, it raises Cancelled. A click in the center hole always raises Cancelled.
CancelText (cancel-text) A text in the center hole, under the text of the highlighted item, that shows where a click cancels. Empty (default) shows none.
OpenItem The item that shows its sub-items, or null.
SubRingSize (sub-ring-size) The depth of the ring of the sub-items as a share of the radius of the menu, from 0.1 to 0.5. Default 0.28.
ItemAt(localPosition) The item or sub-item at a local position, or null in the center hole.
InnerRadius The size of the center hole as a share of the radius, from 0 to 0.9. Default 0.45. 0 draws pie wedges.
Animate True (default) fades the highlight between the wedges.
RadialMenuItem.Text, Icon, Enabled The label, an optional image over the label, and the enabled state.
RadialMenuItem.AddItem(text, action), SubItems, ParentItem The sub-items of an item, and the parent of a sub-item. A child RadialMenuItem of an item in UXML is a sub-item too.

Input:

Sub-items:

Styling

Class Element
tb-radial-menu The menu: 320 px. Its variables set the look of the wedges (see below).
tb-radial-menu--outline A style: wedges with a line and no fill.
tb-radial-menu--solid A style: a disc with no space between the wedges, and a hub in the hole.
tb-radial-menu--over-center Set while the pointer is in the center hole. The cancel text is then --tb-color-danger.
tb-radial-menu__items The layer of the items. It fills the menu and has no look of its own.
tb-radial-menu__item An item, centered in the middle of its wedge with translate: -50% -50%.
tb-radial-menu__item--highlighted The highlighted item: scale 1.15 with a 0.15 s transition, and the label and icon in --tb-color-accent-text.
tb-radial-menu__item--open The item that shows its sub-items. It has no scale.
tb-radial-menu__item-sub-items The layer of the sub-items of an item. It fades in while the item is open.
tb-radial-menu__item-icon The icon: 32 px, tinted --tb-color-text. It shows only when the item has an icon.
tb-radial-menu__item-label The label, in --tb-color-text. A disabled item has opacity 0.5.
tb-radial-menu__hub The layer of the two texts in the center hole.
tb-radial-menu__center The text of the highlighted item in the center hole: bold, --tb-font-size-lg.
tb-radial-menu__cancel The cancel text: --tb-font-size-sm, --tb-color-text-muted.

The variables of tb-radial-menu:

Variable Description
--tb-radial-menu-wedge The wedge color. Default --tb-color-surface-hover. A disabled wedge draws at 40 percent of its alpha.
--tb-radial-menu-sub-wedge The color of the wedge of a sub-item, and of the band of an item with sub-items.
--tb-radial-menu-highlight The color of the highlighted wedge. Default --tb-color-accent.
--tb-radial-menu-center The color of a disc in the center hole. Default: no disc.
--tb-radial-menu-line The color of a line of 2 px around each wedge. Default: no line.
--tb-radial-menu-gap The space between two wedges in degrees. Default 1.5.

To make a style of your own, set the variables in a class and add the class to the menu:

.ember-wheel {
    --tb-radial-menu-wedge: rgba(120, 40, 20, 0.85);
    --tb-radial-menu-sub-wedge: rgba(90, 30, 15, 0.85);
    --tb-radial-menu-highlight: #ffb020;
    --tb-radial-menu-center: rgba(40, 14, 8, 0.9);
    --tb-radial-menu-line: #ff7a30;
    --tb-radial-menu-gap: 3;
}