Class Popover
A popup usually anchored to another UI element.
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
public sealed class Popover : AnchorPopup<Popover>
Properties
modalBackdrop
Enable or disable the blocking of outside click events.
Declaration
public bool modalBackdrop { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
movable
True if the popup is movable by dragging, False otherwise. Default is False.
Declaration
public bool movable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
When the Popup is set to movable, it can be dragged by clicking and dragging the popover element.
resizable
True if the popup is resizable, False otherwise. Default is False.
Declaration
public bool resizable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
When the Popup is set to resizable, it will be resizable by dragging the bottom right corner.
resizeDirection
The direction of the drag.
Declaration
public Draggable.DragDirection resizeDirection { get; set; }
Property Value
| Type | Description |
|---|---|
| Draggable.DragDirection |
resizeSizeModifier
Optional callback invoked during resize to modify the size before it is applied to the target. The first parameter is the computed new size, the second is the original size at drag start. The callback must return the adjusted size to apply.
Declaration
public Func<Vector2, Vector2, Vector2> resizeSizeModifier { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Vector2, Vector2, Vector2> |
Methods
Build(VisualElement, VisualElement)
Build a new Popover instance.
Declaration
public static Popover Build(VisualElement referenceView, VisualElement contentView)
Parameters
| Type | Name | Description |
|---|---|---|
| VisualElement | referenceView | An arbitrary UI element in the current panel. |
| VisualElement | contentView | The content that will appear inside this popup. |
Returns
| Type | Description |
|---|---|
| Popover | The Popover instance. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the referenceView is null. |
EnsureEventHandlersRegistered()
Ensure that the event handlers are registered. This is useful when the popover is used in a smir and the root view can change.
Declaration
public void EnsureEventHandlersRegistered()
GetFocusableElement()
Returns the element that will be focused when the view will become visible.
The default value is `null`.
Declaration
protected override VisualElement GetFocusableElement()
Returns
| Type | Description |
|---|---|
| VisualElement | The element that will be focused when the view will become visible. |
Overrides
GetMovableElement()
Method which must return the visual element that needs to be moved, based on the anchor position and size.
Declaration
public override VisualElement GetMovableElement()
Returns
| Type | Description |
|---|---|
| VisualElement | The visual element which will be moved. The default value is view. |
Overrides
HideView(DismissType)
Called when it is time to hide the popup.
Declaration
protected override void HideView(DismissType reason)
Parameters
| Type | Name | Description |
|---|---|---|
| DismissType | reason | The reason why the popup should be dismissed. |
Overrides
InvokeShownEventHandlers()
Called when the popup has become visible. This method will invoke any handlers attached to the shown event.
Declaration
protected override void InvokeShownEventHandlers()
Overrides
SetModalBackdrop(bool)
Enable or disable the blocking of outside click events.
Declaration
public Popover SetModalBackdrop(bool enableModalBackdrop)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enableModalBackdrop | Whether to enable the blocking of outside click events. |
Returns
| Type | Description |
|---|---|
| Popover | The Popover instance. |
SetMovable(bool)
Set the popup as movable by dragging.
Declaration
public Popover SetMovable(bool isMovable)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isMovable |
|
Returns
| Type | Description |
|---|---|
| Popover | The popover instance. |
See Also
SetPosition(Vector2)
Set the position of the popover programmatically.
Declaration
public Popover SetPosition(Vector2 position)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | position | The desired position (left, top) in pixels. |
Returns
| Type | Description |
|---|---|
| Popover | The popover instance. |
Remarks
This method only works when movable is true.
The position is clamped to the container bounds.
Calling this method sets the manual move flag, which prevents automatic position refresh.
SetResizable(bool)
Set the popup as resizable.
Declaration
public Popover SetResizable(bool isResizable)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isResizable |
|
Returns
| Type | Description |
|---|---|
| Popover | The popover instance. |
See Also
SetResizeDirection(DragDirection)
Set the resize direction of the popover.
Declaration
public Popover SetResizeDirection(Draggable.DragDirection direction)
Parameters
| Type | Name | Description |
|---|---|---|
| Draggable.DragDirection | direction | The direction of the resize. |
Returns
| Type | Description |
|---|---|
| Popover | The popover instance. |
SetResizeSizeModifier(Func<Vector2, Vector2, Vector2>)
Set a callback to modify the size during resize before it is applied to the target.
Declaration
public Popover SetResizeSizeModifier(Func<Vector2, Vector2, Vector2> modifier)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector2, Vector2, Vector2> | modifier | A function that receives the computed new size and the original size at drag start,
and returns the adjusted size. Pass |
Returns
| Type | Description |
|---|---|
| Popover | The popover instance. |
See Also
SetSize(Vector2)
Set the size of the popover content programmatically.
Declaration
public Popover SetSize(Vector2 size)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | size | The desired size (width, height) in pixels. |
Returns
| Type | Description |
|---|---|
| Popover | The popover instance. |
Remarks
This method only works when resizable is true.
The size is clamped so the popover fits within the container bounds.
Calling this method sets the manual resize flag, which prevents automatic position refresh.
ShouldAnimate()
Implement this method to know if the popup should call AnimateViewIn() and AnimateViewOut(DismissType) methods or not.
Declaration
protected override bool ShouldAnimate()
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
ShouldRefreshPosition()
Method to determine if the position of the popup should be refreshed every time the anchor or the popup's content geometry changes.
Declaration
protected override bool ShouldRefreshPosition()
Returns
| Type | Description |
|---|---|
| bool |
|