UI Toolbox logoUI Toolbox
Support

AnchoredPopup

AnchoredPopup in UIToolbox shows an element under an anchor, as a drop-down. SearchDropdown, ComboBox, AutoCompleteField, DatePicker and the PropertyGrid color swatch use it.

An AnchoredPopup open under a Sort by button with a Sort order heading and three togglesAn AnchoredPopup open under a Sort by button with a Sort order heading and three toggles

// adds the tb-popup class to content
var popup = new AnchoredPopup(content);
popup.Closed += () => Debug.Log("closed");
button.clicked += () =>
{
    if (popup.IsOpen) popup.Close();
    else popup.Open(field, keepOpenOn: button);
};
Member Description
Open(anchor, keepOpenOn, matchWidth) Shows the content under the anchor, at its left edge. matchWidth makes the content as wide as the anchor. The content follows the layout of the anchor while it shows, so a popup opened on a panel that shows in the same frame goes under the anchor at its first layout. Returns false when the popup is open or the anchor has no panel.
OpenBeside(anchor, side, keepOpenOn, gap) Shows the content on one side of the anchor (TooltipPlacement.Above, Below, Left or Right), centered along it, gap pixels away (2 by default). It goes to the opposite side when side has no room, and it stays inside its host. It is placed again when the content changes size or the anchor changes its layout while it shows. Returns false when the popup is open or the anchor has no panel.
OpenAt(anchor, worldPosition, keepOpenOn, owner) Shows the content at a panel position, such as the pointer. owner is a popup that this one belongs to, such as the menu of a submenu: a click in the owner does not close this popup.
Close(), IsOpen, Closed Hides the content. Closed is sent after Close() and after a click outside.
Content The element that shows.
CloseOnEscape True to close the popup on Escape or the Cancel button of a gamepad, and give the focus back to the anchor that opened it. Off by default.

A popup above a button, such as a volume slider, that closes on Escape and gives the focus back to the button:

var popup = new AnchoredPopup(panel) { CloseOnEscape = true };
sound.clicked += () =>
{
    if (popup.IsOpen) popup.Close();
    else popup.OpenBeside(sound, TooltipPlacement.Above,
        keepOpenOn: sound);
};

Styling

Class Element
tb-popup The content of every AnchoredPopup: the search list, the calendar and the color popup. Absolute position, surface, border and small radius. It is in the workspace or the top element of the document, not in the control.
tb-style-scope Not on the popup: on an ancestor of the control. The open popup takes the classes of the nearest one. See Style families and style scopes.