Class OverflowTooltip
A truncating label that surfaces its full text in a Tooltip, but only while the text actually overflows.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class OverflowTooltip : LocalizedTextElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IVisualElementScheduler, IBindable, INotifyValueChanged<string>, ITextEdition, ITextElementExperimentalFeatures, IExperimentalFeatures, ITextSelection, IContextOverrideElement, IAdditionalDataHolder
Remarks
A label that already fits gets no tooltip: repeating text the user can plainly read is noise, and it makes every genuinely truncated label harder to notice. The element measures itself against its own content box and only then publishes the tooltip.
Overflow is re-measured whenever the box changes — a GeometryChangedEvent covers the container narrowing or the density changing — and whenever the text changes, since a rename can overflow the same box without moving it. The tooltip therefore appears and disappears live, and never goes stale.
Use it for names in tight columns: grid view item labels, asset rows, breadcrumb segments.
The truncation itself comes from USS (text-overflow: ellipsis over
white-space: nowrap), so the element's width is whatever its parent gives it.
Examples
A label inside a fixed-width tile.
var tile = new VisualElement { style = { width = 120 } };
tile.Add(new OverflowTooltip { text = asset.name });
// Renaming re-measures on its own.
label.text = asset.name;
Declaring one in UXML.
<UXML>
<appui:OverflowTooltip text="A very long asset name" placement="Top" />
</UXML>
Constructors
OverflowTooltip()
Default constructor.
Declaration
public OverflowTooltip()
OverflowTooltip(string)
Constructor with a reference text.
Declaration
public OverflowTooltip(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The reference text, or a Localization dictionary key. |
Fields
defaultPlacement
The default tooltip placement, matching the registry's side default.
Declaration
public const PopoverPlacement defaultPlacement = Top
Field Value
| Type | Description |
|---|---|
| PopoverPlacement |
overflowingUssClassName
The styling class applied while the text is truncated.
Declaration
public const string overflowingUssClassName = "appui-overflow-tooltip--overflowing"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The main styling class of the OverflowTooltip.
Declaration
public const string ussClassName = "appui-overflow-tooltip"
Field Value
| Type | Description |
|---|---|
| string |
Properties
isOverflowing
true while the text does not fit in the element's content box, which is exactly when
the tooltip is published.
Declaration
[CreateProperty(ReadOnly = true)]
public bool isOverflowing { get; }
Property Value
| Type | Description |
|---|---|
| bool |
placement
Where the tooltip opens relative to the label. Defaults to defaultPlacement.
Declaration
[Tooltip("Where the tooltip opens relative to the label.")]
[CreateProperty]
[UxmlAttribute]
[Header("Overflow Tooltip")]
public PopoverPlacement placement { get; set; }
Property Value
| Type | Description |
|---|---|
| PopoverPlacement |
text
The reference text, or a Localization dictionary key.
Declaration
public string text { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Shadows text only to re-measure. A rename can overflow the same box without moving it, so GeometryChangedEvent alone would never fire. The measure is deferred one frame because the localized string resolves after the reference text is assigned.
Methods
RefreshOverflow()
Re-measure the text against the content box and publish or withdraw the tooltip. Called automatically on layout and text changes; call it by hand only after changing something the element cannot observe, such as a font asset swapped underneath it.
Declaration
public void RefreshOverflow()
Events
overflowChanged
Raised when isOverflowing flips, and only then. Lets a container react to a label becoming truncated without polling.
Declaration
public event Action<bool> overflowChanged
Event Type
| Type | Description |
|---|---|
| Action<bool> |