Class SelectionRect
The rubber-band rectangle drawn while drag-selecting on a Canvas.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class SelectionRect : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
Purely presentational, and deliberately so: the caller owns the drag and the hit testing, and feeds the result in through rect. Keeping the two apart is what lets the same marquee serve a node graph, a timeline or a tile map without knowing what it is selecting.
A drag that runs right-to-left or bottom-to-top produces a negative extent, which no layout system draws. Normalize(Vector2, Vector2) turns two drag corners into the positive rect this element expects, so every caller does not have to rediscover that.
The element ignores the pointer, so a marquee never eats the release that ends the drag it is drawing.
Examples
Driving the marquee from a drag.
var marquee = new SelectionRect { visible = false };
canvas.Add(marquee);
canvas.RegisterCallback<PointerMoveEvent>(evt =>
{
marquee.visible = true;
marquee.rect = SelectionRect.Normalize(dragOrigin, canvas.WorldToLocal(evt.position));
});
In UXML.
<appui:SelectionRect />
Constructors
SelectionRect()
Default constructor.
Declaration
public SelectionRect()
Fields
ussClassName
The SelectionRect main styling class.
Declaration
public const string ussClassName = "appui-selection-rect"
Field Value
| Type | Description |
|---|---|
| string |
Properties
rect
The marquee's rectangle, in the coordinate space of whatever the marquee is a child of — the same space the elements it selects are positioned in.
Declaration
[CreateProperty]
[UxmlAttribute]
public Rect rect { get; set; }
Property Value
| Type | Description |
|---|---|
| Rect |
Remarks
A negative width or height is clamped to zero rather than silently drawing nothing: pass a rect through Normalize(Vector2, Vector2) first.
Methods
Normalize(Vector2, Vector2)
Turns the two corners of a drag into a rectangle with a positive extent.
Declaration
public static Rect Normalize(Vector2 origin, Vector2 current)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | origin | Where the drag started. |
| Vector2 | current | Where the pointer is now. |
Returns
| Type | Description |
|---|---|
| Rect | The rectangle spanned by the two points. |