UI Toolbox logoUI Toolbox
Support

InlineIconLabel

An InlineIconLabel is a label with icons and input glyphs in its text. A name in braces, such as {south} or {gold}, is an element in the line, and the label wraps the words and the elements together. Use it for a button prompt in a sentence ("Press {south} to jump"), a price with a currency icon, an item description or a tutorial text.

A tutorial screen with a Reach the old gate objective, a tip with the A button icon inside its text, and the button hints Jump, Attack and Pause at the bottom rightA tutorial screen with a Reach the old gate objective, a tip with the A button icon inside its text, and the button hints Jump, Attack and Pause at the bottom right

<tb:InlineIconLabel
    text="Press {south} to jump, costs {gold} 50"
    family="Xbox" />
<tb:InlineIconLabel text="&lt;b&gt;Hold&lt;/b&gt; {mouse-left} to aim" />
// Once: a name for each picture. A white picture takes the color.
InlineIconLabel.RegisterIcon("gold", coinTexture,
    new Color(1f, 0.78f, 0.16f));
InlineIconLabel.RegisterIcon("heart", heartSprite);

var label =
    new InlineIconLabel("Press {south} to jump, costs {gold} 50");
label.Family = GamepadFamily.PlayStation;

// A text with more than one line, and a button in the family of its own
label.Text =
    "{gold} 50 for the sword\n{south:xbox} buy {east:xbox} leave";

Text

Text Result
{name} An inline element. The label looks up the name in this order: an icon from RegisterIcon, a gamepad button, a PromptFont glyph, an Icon of the built-in set.
{icon:name} An icon of the built-in set, such as {icon:settings}, even when a button or a glyph has the same name.
{button:family} A gamepad button in a family of its own: {south:playstation}. The family is a GamepadFamily name. The label uses Family when the token has no family.
{{ A brace.
A name that nothing knows The text as it is, with its braces, so a typing error shows.
A line feed A new line.
A rich text tag Works as in a Label: <b>, <i>, <color=#ff7070>, <size=24>. A tag can span words and elements.

Members

Member Description
Text (text) The text with the names in braces. Setting the same text does nothing.
Family (family) The look of the gamepad buttons that name no family: Generic (default), Xbox, PlayStation or Switch.
InlineIconLabel.RegisterIcon(name, texture) Makes name show the texture in every InlineIconLabel. The name has no braces, and its case does not matter. A second call with the same name replaces the picture.
InlineIconLabel.RegisterIcon(name, texture, tint) The same, with a color. A white texture takes any color, so one mask serves many icons.
InlineIconLabel.RegisterIcon(name, sprite), RegisterIcon(name, sprite, tint) The same for a Sprite.
InlineIconLabel.RegisterIcon(name, vectorImage), RegisterIcon(name, vectorImage, tint) The same for an SVG (VectorImage). The SVG keeps its own colors.
InlineIconLabel.UnregisterIcon(name) Removes an icon. Gives true when the name had one. Call it before you destroy the texture.
InlineIconLabel.IsIconRegistered(name) True when the name has an icon.
Refresh() Makes the elements again from the text. Call it after you register or unregister an icon whose name is already in a text.

Layout

The label is a row that wraps, with one element for each word and each inline element.

Performance

Styling

Class or property Element
tb-inline-icon-label The label: a row that wraps, with --tb-color-text as the color. font-size and color are the size and the color of the words.
tb-inline-icon-label__word A word. It is a TextElement, so -unity-font-style and -unity-font-definition work.
tb-inline-icon-label__icon A registered icon.
tb-inline-icon-label__glyph A gamepad button or a PromptFont glyph. color is its color.
tb-inline-icon-label__break The element for a line feed.
tb-inline-icon-label__tight On an element that has no space after it.
--tb-inline-icon-label-icon-scale A custom property on the label: the height of an icon and the size of a glyph as a multiple of the font size (1.3).
--tb-inline-icon-label-space A custom property on the label: the space between two elements as a multiple of the font size (0.3).
.shop-line { font-size: 18px; --tb-inline-icon-label-icon-scale: 1.5; }
.shop-line .tb-inline-icon-label__glyph {
    color: var(--tb-color-accent);
}
/* A registered icon with a white tint takes this color */
.shop-line .tb-inline-icon-label__icon {
    -unity-background-image-tint-color: var(--tb-color-warning);
}

A registered icon with a tint other than white sets its own tint on the element, and the USS rule does not apply to it.

Demo

The DisplayDemo example has an Inline icons tab. It registers a coin and a gem, edits the text, the family, the font size and the width of a label, and shows the UXML and the C# of the label.

The InlineIconLabelDemo scene shows tutorial tips with the keys or the buttons of the device the player picks, a quest page with item icons from textures it registers, a party chat that turns names in braces into icons, and four looks in USS.