UI Toolbox logoUI Toolbox

HoverCard

A HoverCard is a popup with your content that opens when the pointer rests on a control, or when the control gets the focus. Use it for the details of the thing under the pointer, such as the stats of an item in an inventory. For a text only, use a ToolTip.

A hover card that shows the name of an item, its kind and its stats

How to add a hover card in UXML:

  1. Declare the card in the UXML of a window. Put its content in it as child elements.
  2. Set target to the name of the control that opens it. No code is necessary.
<ui:Button name="swordSlot" text="Sword" />
<tb:HoverCard target="swordSlot" title="Iron sword" text="A plain blade.">
    <ui:Label text="Damage 12" />
    <ui:Label text="Weight 3" />
</tb:HoverCard>

How to use one card for many controls:

var card = new HoverCard { OpenDelayMs = 300 };
var stats = new Label();
card.Add(stats);
foreach (var slot in slots) card.AttachTo(slot);
// The card opens for one slot at a time: fill it from its target
card.Opened += () =>
{
    var item = (Item)card.Target.userData;
    card.Title = item.Name;
    stats.text = $"Damage {item.Damage}";
};

A HoverCard is a Callout. It has all the members of the Callout, and these:

Member Description
OpenDelayMs (open-delay-ms) The time that the pointer rests on a target, or that the target has the focus, before the card opens, in milliseconds. 500 by default.
CloseDelayMs (close-delay-ms) The time from when the pointer leaves the target and the card until the card closes, in milliseconds. 300 by default.
TargetName (target) The name of the control that opens the card. The card attaches to it when it is added to a panel.
AttachTo(target) Makes target open the card. Call it for each control that the card serves.
Detach(target) Stops target from opening the card, and closes the card that is open for it.
Title (title), Text (text) The bold first line and the text above the content, as on a callout.
Placement (placement), Alignment (alignment) The side of the target and the place along that side. Below and Center by default.
Target The control that the card is open for.

Tips:

Styling

Class Element
tb-hover-card The card. It also has the class tb-callout and its parts. It is on --tb-color-surface with a border in --tb-color-border.
tb-callout__title, tb-callout__text The bold title and the text, above the content.
tb-callout--hidden, --anim-in, --anim-out The enter and exit animations, as on a callout.

To make every hover card wider, with a round border:

.tb-hover-card.tb-callout {
    max-width: 420px;
    border-radius: 12px;
}