Class ContextCounter
How full a model's context window is, as a compact pill.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class ContextCounter : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
A ring fills as the window does, next to a label and the percentage, with the exact "used / total (pct)" reading in the tooltip. Past nearThreshold the readout turns warning-coloured, which is the point at which a user needs to think about starting a new conversation.
The ring is a determinate CircularProgress rather than a hand-drawn arc, so it follows the package's progress styling and density behaviour.
Examples
A window a little over half full.
var counter = new ContextCounter { used = 120000, total = 200000 };
parentElement.Add(counter);
In UXML, close to full.
<appui:ContextCounter used="190000" total="200000" />
Constructors
ContextCounter()
Default constructor.
Declaration
public ContextCounter()
Fields
defaultLabel
The default leading label.
Declaration
public const string defaultLabel = "Context"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The styling class of the leading label.
Declaration
public const string labelUssClassName = "appui-context-counter__label"
Field Value
| Type | Description |
|---|---|
| string |
nearThreshold
The fill ratio at which the counter starts warning.
Declaration
public const float nearThreshold = 0.85
Field Value
| Type | Description |
|---|---|
| float |
nearUssClassName
The styling class applied once the window is nearly full.
Declaration
public const string nearUssClassName = "appui-context-counter--near"
Field Value
| Type | Description |
|---|---|
| string |
percentUssClassName
The styling class of the percentage.
Declaration
public const string percentUssClassName = "appui-context-counter__percent"
Field Value
| Type | Description |
|---|---|
| string |
ringUssClassName
The styling class of the ring.
Declaration
public const string ringUssClassName = "appui-context-counter__ring"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The ContextCounter main styling class.
Declaration
public const string ussClassName = "appui-context-counter"
Field Value
| Type | Description |
|---|---|
| string |
Properties
label
The leading label. "Context" by default.
Declaration
[CreateProperty]
[UxmlAttribute]
public string label { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
near
Whether the window is close enough to full to warrant a warning.
Declaration
public bool near { get; }
Property Value
| Type | Description |
|---|---|
| bool |
percent
How full the window is, as a whole percentage.
Declaration
public int percent { get; }
Property Value
| Type | Description |
|---|---|
| int |
Remarks
Rounded half up, like the registry's Math.round. Mathf.RoundToInt rounds a
midpoint to even, so 20.5% would report 20 there and 21 on the web.
ratio
How full the window is, from 0 to 1. A non-positive total reads as empty rather than dividing by zero.
Declaration
public float ratio { get; }
Property Value
| Type | Description |
|---|---|
| float |
ring
The ring the counter fills.
Declaration
public CircularProgress ring { get; }
Property Value
| Type | Description |
|---|---|
| CircularProgress |
total
The size of the context window.
Declaration
[CreateProperty]
[UxmlAttribute]
public float total { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
used
How much of the context window is in use.
Declaration
[CreateProperty]
[UxmlAttribute]
public float used { get; set; }
Property Value
| Type | Description |
|---|---|
| float |