UI Toolbox logoUI Toolbox
Support

StatTile

A StatTile is the tile of a dashboard: a small title, an optional "…" menu button, a big value, the change beside the value with a StatDelta, a chart under them and an optional caption. The chart is a Sparkline by default, and any element can take its place. Put the tiles in a wrapping row or a grid for a screen with the numbers of a server, a shop, a season or a run.

A tile with the title Gold earned, the value 2.9k, a green rising arrow with 12.5% and an area sparkline under themA tile with the title Gold earned, the value 2.9k, a green rising arrow with 12.5% and an area sparkline under them

Video tutorial: Stat tiles. All videos: Video tutorials.

How to add it:

<tb:StatTile title="Gold earned" value="2.9k" from="2600" to="2925"
    values="3,5,4,6,8,7,9" caption="Last 7 days" />
<tb:StatTile title="Latency" value="182 ms" from="170" to="182"
    higher-is-better="false" values="12,14,13,17,16,18" />
<tb:StatTile title="New reviews" caption="Waiting for data" />
var tile = root.Q<StatTile>("gold");
tile.SetValue(2925f);                    // "2.9k"
tile.SetChange(2600f, 2925f);            // an arrow and "12.5%"
tile.SetData(week);                      // a float[] or a List<float>
tile.AddMenuItem("Refresh", refresh);    // a "…" button appears
tile.AddMenuItem("Hide", () =>
    tile.style.display = DisplayStyle.None);

// Any element can be the chart
var ping = new StatTile { Title = "Ping" };
ping.SetChart(new Gauge { Value = 42f });

// A tile that reports its click
tile.Clickable = true;
tile.Clicked += () => OpenDetails();

A tile with no values in its chart shows the faint line and the "No data" pill of the Sparkline, so a new tile never shows an empty box.

Why a Card

StatTile is a Card. It has the border, the surface, the corner radius, the title and the footer of the card in every theme, and the themes already style them, so a tile looks right in Fluent, Glass, Neon, Paper, Terminal and Game with no extra work. The tile adds the value row, the chart slot, the menu and the focus as one tile.

Settings

Member Description
Title (title) The small text at the top, from Card.
Value (value) The big value as text, such as "2.9k".
From (from), To (to) The value before and after the change. Setting either one shows the StatDelta beside the value as an arrow and the percent of From.
HigherIsBetter (higher-is-better) True (the default) makes a rise green. False makes a fall green, as for a latency or a loss.
Values (values) The values of the sparkline as a comma list, such as 3,5,4,6. An empty list shows the "No data" pill.
Caption (caption) A muted line under the chart. Empty hides it.
Clickable (clickable) The tile takes the focus and raises Clicked.
Delta The StatDelta, to change its display, arrow style or format. The default is ArrowsAndPercent with the Slanted arrow.
Sparkline The default sparkline (area type), or null after SetChart.
ChartSlot The element that holds the chart.
MenuButton The "…" button. It shows while the tile has menu items.
HasChange True while the change shows.
IsMenuOpen, MenuItemCount The state of the menu, and the number of its items.

Methods

Method Description
SetValue(text) Sets the value text.
SetValue(number) Sets a compact number: "842", "2.9k", "1.2M", "3B" or "1T", with the decimal mark of the current language.
SetValue(number, unit) A compact number and a unit, such as SetValue(182f, " ms") for "182 ms".
SetChange(from, to) Shows the change from one number to the other. A from of 0 shows the number, never NaN or Infinity.
SetChange(percent) Shows a change of a percent, such as 12.5 for "+12.5%".
ClearChange() Hides the change.
SetData(values) Replaces the values of the default sparkline.
SetChart(element) Puts another element in the place of the sparkline, such as a Graph or a Gauge.
AddMenuItem(text, callback) Adds an item to the "…" menu. The first item shows the button and makes the tile take the focus. After an item has run, the focus goes back to the tile.
ClearMenu() Removes the items and the button.
OpenMenu(), CloseMenu() Opens or closes the menu in code.
StatTile.FormatCompact(number, decimals, current) The compact text of a number, with no element. Numbers that are not finite give "—".

Events

Clicked is raised by a click, or by A, Enter or Space on the focused tile, while Clickable is on. A click on the "…" button opens the menu and does not raise it.

Mouse, keyboard and gamepad

Input Action
Click on the "…" button Opens the menu under the button. A click outside, or on an item, closes it.
Tab Moves the focus to the tile, once for the whole tile, and on to the next tile.
Arrow keys, gamepad D-pad and left stick Move the focus to the nearest tile in that direction, by its place on the screen, so a grid moves up and down too. They never open or close anything.
Enter, Space, gamepad A On a tile that is Clickable, raises Clicked. On a tile with a menu that is not Clickable, opens the menu.
Escape, gamepad B Closes the menu, and the focus goes back to the tile.
Right click, Menu key, long press (touch or pen) Open the menu of a tile that has one, also a tile that is Clickable. A gamepad has no button for it: your game can send the Menu key, as the Context menus page shows.

A tile that has both a menu and Clickable raises Clicked on A, and opens its menu with the "…" button. The focused tile has a ring inside its border, so the focus shows in every theme without color alone.

Performance

In the examples

The StatTileDemo scene is a dashboard of six tiles in a grid: gold earned, players online, win rate, quests completed, latency (less is better) and new reviews (a tile that starts with no data). A timer updates the values every second. Each tile has a "…" menu with Refresh and Hide, and a Playground tab changes the display of the change, the arrow style, the direction, the "No data" state and the click of one tile. The Styles scene shows four looks of the tile.

Styling

Class Element
tb-stat-tile The tile, a Card.
tb-stat-tile--interactive A tile that takes the focus: it has a menu or Clickable is on.
tb-stat-tile--menu-open The tile while its menu shows.
tb-stat-tile__row The row of the value and the change.
tb-stat-tile__value The big value.
tb-stat-tile__chart The place of the chart.
tb-stat-tile__caption The caption.
tb-stat-tile__menu The "…" button.
tb-stat-tile__ring The focus ring.

The colors come from the theme: --tb-color-text for the value, --tb-color-text-muted for the title and the caption, --tb-color-success and --tb-color-danger for the change, --tb-color-accent for the sparkline and --tb-color-focus-ring for the focus ring. Redefine the accent on a tile to give it its own color.