docs.unity3d.com
    Show / Hide Table of Contents

    Class VisualElementExtensions

    VisualElementExtensions is a set of extension methods useful for VisualElement.

    Inheritance
    Object
    VisualElementExtensions
    Namespace: UnityEngine.UIElements
    Syntax
    public static class VisualElementExtensions : object

    Methods

    AddManipulator(VisualElement, IManipulator)

    Add a manipulator associated to a VisualElement.

    Declaration
    public static void AddManipulator(this VisualElement ele, IManipulator manipulator)
    Parameters
    Type Name Description
    VisualElement ele

    VisualElement associated to the manipulator.

    IManipulator manipulator

    Manipulator to be added to the VisualElement.

    ChangeCoordinatesTo(VisualElement, VisualElement, Rect)

    Transforms a rectangle from the local space of an element to the local space of another element.

    Declaration
    public static Rect ChangeCoordinatesTo(this VisualElement src, VisualElement dest, Rect rect)
    Parameters
    Type Name Description
    VisualElement src

    The element to use as a reference as the source local space.

    VisualElement dest

    The element to use as a reference as the destination local space.

    Rect rect

    The rectangle to transform, in the local space of the source element.

    Returns
    Type Description
    Rect

    A rectangle in the local space of destination element.

    Remarks

    The elements both need to be attached to a panel and have received a valid layout. Otherwise, this method may return invalid results.

    ChangeCoordinatesTo(VisualElement, VisualElement, Vector2)

    Transforms a point from the local space of an element to the local space of another element.

    Declaration
    public static Vector2 ChangeCoordinatesTo(this VisualElement src, VisualElement dest, Vector2 point)
    Parameters
    Type Name Description
    VisualElement src

    The element to use as a reference as the source local space.

    VisualElement dest

    The element to use as a reference as the destination local space.

    Vector2 point

    The point to transform, in the local space of the source element.

    Returns
    Type Description
    Vector2

    A point in the local space of destination element.

    Remarks

    The elements both need to be attached to a panel and must receive a valid layout. Otherwise, this method may return invalid results.

    LocalToWorld(VisualElement, Rect)

    Transforms a rectangle from the local space of the element to the world space.

    Declaration
    public static Rect LocalToWorld(this VisualElement ele, Rect r)
    Parameters
    Type Name Description
    VisualElement ele

    The element to use as a reference for the local space.

    Rect r

    The rectangle to transform, in local space.

    Returns
    Type Description
    Rect

    A rectangle in the world space.

    Remarks

    This element needs to be attached to a panel and must receive a valid layout. Otherwise, this method may return invalid results.

    LocalToWorld(VisualElement, Vector2)

    Transforms a point from the local space of the element to the world space.

    Declaration
    public static Vector2 LocalToWorld(this VisualElement ele, Vector2 p)
    Parameters
    Type Name Description
    VisualElement ele

    The element to use as a reference for the local space.

    Vector2 p

    The point to transform, in local space.

    Returns
    Type Description
    Vector2

    A point in the world space.

    Remarks

    This element needs to be attached to a panel and must receive a valid layout. Otherwise, this method may return invalid results.

    RemoveManipulator(VisualElement, IManipulator)

    Remove a manipulator associated to a VisualElement.

    Declaration
    public static void RemoveManipulator(this VisualElement ele, IManipulator manipulator)
    Parameters
    Type Name Description
    VisualElement ele

    VisualElement associated to the manipulator.

    IManipulator manipulator

    Manipulator to be removed from the VisualElement.

    StretchToParentSize(VisualElement)

    Aligns a VisualElement's left, top, right and bottom edges with the corresponding edges of its parent.

    Declaration
    public static void StretchToParentSize(this VisualElement elem)
    Parameters
    Type Name Description
    VisualElement elem

    The element to be aligned with its parent

    Remarks

    This method provides a way to set the following styles in one operation:

    • position is set to Absolute
    • left is set to 0
    • top is set to 0
    • right is set to 0
    • bottom is set to 0

    StretchToParentWidth(VisualElement)

    Aligns a VisualElement's left and right edges with the corresponding edges of its parent.

    Declaration
    public static void StretchToParentWidth(this VisualElement elem)
    Parameters
    Type Name Description
    VisualElement elem

    The element to be aligned with its parent

    Remarks

    This method provides a way to set the following styles in one operation:

    • position is set to Absolute
    • left is set to 0
    • right is set to 0

    WorldToLocal(VisualElement, Rect)

    Transforms a rectangle from the world space to the local space of the element.

    Declaration
    public static Rect WorldToLocal(this VisualElement ele, Rect r)
    Parameters
    Type Name Description
    VisualElement ele

    The element to use as a reference for the local space.

    Rect r

    The rectangle to transform, in world space.

    Returns
    Type Description
    Rect

    A rectangle in the local space of the element.

    Remarks

    This element needs to be attached to a panel and must receive a valid layout. Otherwise, this method may return invalid results.

    WorldToLocal(VisualElement, Vector2)

    Transforms a point from the world space to the local space of the element.

    Declaration
    public static Vector2 WorldToLocal(this VisualElement ele, Vector2 p)
    Parameters
    Type Name Description
    VisualElement ele

    The element to use as a reference for the local space.

    Vector2 p

    The point to transform, in world space.

    Returns
    Type Description
    Vector2

    A point in the local space of the element.

    Remarks

    This element needs to be attached to a panel and must have a valid layout. Otherwise, this method might return invalid results.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023