UI Toolbox logoUI Toolbox
Support

Badge

A Badge is a small label for a status or a count, such as "New" or "12". Put it next to a title, in a list row, or on the corner of a button or a UserAvatar.

A Blacksmith shop list of five items, each with a badge: New, Sale, 2 left, Owned and Sold outA Blacksmith shop list of five items, each with a badge: New, Sale, 2 left, Owned and Sold out

How to add a badge:

<tb:Badge text="New" />
<tb:Badge text="Online" tone="Success" />
<tb:Badge count="120" tone="Error" />
<ui:VisualElement>
    <ui:Button text="Inbox" name="inbox" />
    <tb:Badge name="unread" count="5" tone="Error" corner="true" />
</ui:VisualElement>
<tb:Badge text="Draft" tone="Warning" outline="true" />
<tb:Badge
    name="filter"
    text="Clear filter"
    outline="true"
    clickable="true" />
var unread = root.Q<Badge>("unread");
// 0 hides the badge
mailbox.Changed += () => unread.Count = mailbox.UnreadCount;

var filter = root.Q<Badge>("filter");
filter.Icon = Background.FromSprite(closeIcon);
filter.Clicked += ClearFilter;

The badge is an AnimatedLabel, so the effect tags work in its text. A "New" badge that shines:

row.Add(new Badge("<shine>New</shine>", BadgeTone.Neutral));
Member Description
text The text of a status badge. Badge is an AnimatedLabel, so it can hold effect tags. A text with no tag does no work each frame.
Tone (tone) Neutral (the default), Accent, Success, Warning or Error. It sets the class tb-badge--neutral, --accent, --success, --warning or --error.
Count (count) A number to show in place of the text. 0 hides the badge. Badge.NO_COUNT (-1, the default) shows the text.
MaxCount (max-count) The largest count that shows as a number (default 99). A larger count shows as "99+".
Dot (dot) Shows a 10 px dot and no text.
Corner (corner) Puts the badge on the top right corner of its parent, outside the layout.
Outline (outline) Shows the badge with no fill. The text takes the color of the tone.
Icon (icon) A picture in front of the text, in the color of the text. An empty Background takes it away.
Clickable (clickable) Makes the badge a button: it takes the pointer and the focus.
Clicked Raised by a click or a submit on a clickable badge.
Effect (effect), Speed (speed), Playing (playing), Amplitude (amplitude) Inherited from AnimatedLabel: the effects of the whole text (None), the speed of the effects (1), false to stop them (true), and how far a glyph moves in pixels (4).

Tips:

In the examples

Styling

Class Element
tb-badge The badge, an AnimatedLabel without the tb-animated-label class: bold small text, a border and a radius of 9 px, on --tb-color-surface-alt.
tb-badge--neutral, --accent, --success, --warning, --error The tone. It sets the background, the border and the text color. Error uses --tb-color-danger.
tb-badge--outline A badge with Outline on: a transparent background, and the text in the tone color.
tb-badge--icon A badge with an Icon: the picture is the background image, 11 px, left of the text.
tb-badge--clickable A badge with Clickable on. It becomes a little transparent under the pointer, and the focused badge has a border in --tb-color-text.
tb-badge--dot A badge with Dot on: 10 px and no text. The rule is after the tones.
tb-badge--corner A badge with Corner on: position: absolute, 4 px outside the top right corner of the parent.

To make the error badges square and move the corner badges in:

.tb-badge--error { border-radius: 2px; }
.tb-badge--corner { top: 0; right: 0; }

The BadgeDemo scene shows a status on each item of a shop, counts on the buttons of a game menu, clickable chips that filter a bag, and the looks of the badge.

SVG: Icon is a Background. An SVG imported as a VectorImage works as well as a texture. See Pictures: PNG or SVG.