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.
![]()
![]()
<tb:InlineIconLabel
text="Press {south} to jump, costs {gold} 50"
family="Xbox" />
<tb:InlineIconLabel text="<b>Hold</b> {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. |
- The name of a gamepad button is a
GamepadGlyphButtonname in any case, with an optional hyphen between the words:{south},{left-shoulder},{dpad-up}. See GamepadGlyph and InputGlyph. - The name of a
PromptFontglyph is its code name:{mouse-left},{keyboard-enter},{xbox-a}. - A registered icon wins over a button or a glyph with the same name.
- The name of a built-in icon is one of the names on the Icon page:
{settings},{heart-filled}. It has the size and the color of the text. - A word right after an element, with no space between, sits next to it with no gap:
{south}.and{gold}x2stay together. - An emoji or any other character that the font has is a plain character of the text. For an emoji that the font does not have, register a picture of it under a name and write the name in braces.
- A
<that does not start a tag is a plain character:1 < 2.
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. |
- The registry is shared by all labels. Register the icons once, at the start of the game or the scene.
- The label does not own the textures. Destroy them yourself when you do not need them any more.
- An icon keeps the width to height ratio of its picture. It is as high as the font size times 1.3.
- A glyph has the size of an icon, and an icon or a glyph sits on the center line of the text.
- The label has no text selection and no links.
- The effects of AnimatedLabel and TypewriterLabel need one text element, so they do not work in this label.
Layout
The label is a row that wraps, with one element for each word and each inline element.
- A word never breaks. A word that is wider than the label goes over its edge.
- The size of the icons, the glyphs and the spaces follows the font size of the label. Set
font-sizein USS orstyle.fontSize, and the line follows. - The line wraps at the width of the label. Give the label a
width, or put it in a parent with a width. - The label shows long text as many elements. Use a normal
Labelfor a page of text, and anInlineIconLabelfor a line or a short paragraph.
Performance
- A change of the text makes the elements again. The label keeps the elements it does not need in pools, so the next text re-uses them, and the new text allocates only the strings of its words.
- Setting the same text, or the same family, does nothing and allocates no memory.
- The label runs no scheduled item and does no work each frame. A change of the font size changes the size of the icons once.
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.