Docsv3.20.2
Back to API Reference
Class

UniTextContextMenu

sealed
Implements:IPointerClickHandler

Context menu you lay out yourself in Unity UI: a panel and the objects its items show on, styled and localized however you like. Each of its Items binds an object of the layout to the command it runs; the menu shows the objects of the commands the field offers and runs a command when its object is clicked. It draws nothing itself, and one menu serves every field that presents it — a click acts on the field that showed it last.

Remarks

A command the field offers (Commands) shows on the first item whose command matches it; while it does not apply, the item hides its object or shows it disabled (WhenUnavailable). A Toggle shows whether the command's effect is on (IsActive), and an item's Label receives the command's title. The objects keep their places in the layout; an item whose command the field does not offer is hidden. The commands no item matches — added to the field or the project, or the Android apps of SystemTextActions — show on copies of the object of the first item without a command, right after it in the field's order. That object stays hidden; without such an item those commands are not shown. A menu that shows nothing stays hidden. A menu touch opened sits centred above the selection and its handles, or below them where only that fits, and leaves the rest of the screen to the field. A menu a mouse or pen opened hangs from the pointer, and one the keyboard opened from the caret or the selection with its first item highlighted; either turns left or up where it would leave the screen — the keyboard's up above the caret's line — closes on a press anywhere outside it and takes the field's keys (HandleKey). Every menu stays inside the canvas and the screen's safe area, and above a soft keyboard. Visibility is driven through the CanvasGroup, and the required FocusGuard keeps the field focused while the user presses an item.
public bool IsVisible{ get }
public override void Show()
public override void Hide()
public override void HandleKey()

Moves the keyboard highlight through the items that can run, in the layout's order — the arrows step and wrap, Home and End jump to the ends — and runs the highlighted item on Enter; other keys do nothing. The highlight shows through the hover state of the Selectables inside the highlighted object.