docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Canvas

    A Canvas is a VisualElement that can be used to group other VisualElements. You can use it to create a scrollable area inside a window.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    Canvas
    Implements
    IEventHandler
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IResolvedStyle
    IContextOverrideElement
    Inherited Members
    BaseVisualElement.contextPrefix
    BaseVisualElement.scaleOverride
    BaseVisualElement.themeOverride
    BaseVisualElement.langOverride
    BaseVisualElement.layoutDirectionOverride
    BaseVisualElement.preferredTooltipPlacementOverride
    BaseVisualElement.tooltipDelayMsOverride
    BaseVisualElement.GetLayoutDirectionUssClassName(Dir)
    VisualElement.disabledUssClassName
    VisualElement.ExecuteDefaultAction(EventBase)
    VisualElement.Focus()
    VisualElement.SendEvent(EventBase)
    VisualElement.SetEnabledFromHierarchy(bool)
    VisualElement.SetEnabled(bool)
    VisualElement.MarkDirtyRepaint()
    VisualElement.ContainsPoint(Vector2)
    VisualElement.Overlaps(Rect)
    VisualElement.DoMeasure(float, VisualElement.MeasureMode, float, VisualElement.MeasureMode)
    VisualElement.ToString()
    VisualElement.GetClasses()
    VisualElement.ClearClassList()
    VisualElement.AddToClassList(string)
    VisualElement.RemoveFromClassList(string)
    VisualElement.ToggleInClassList(string)
    VisualElement.EnableInClassList(string, bool)
    VisualElement.ClassListContains(string)
    VisualElement.FindAncestorUserData()
    VisualElement.Add(VisualElement)
    VisualElement.Insert(int, VisualElement)
    VisualElement.Remove(VisualElement)
    VisualElement.RemoveAt(int)
    VisualElement.Clear()
    VisualElement.ElementAt(int)
    VisualElement.IndexOf(VisualElement)
    VisualElement.Children()
    VisualElement.Sort(Comparison<VisualElement>)
    VisualElement.BringToFront()
    VisualElement.SendToBack()
    VisualElement.PlaceBehind(VisualElement)
    VisualElement.PlaceInFront(VisualElement)
    VisualElement.RemoveFromHierarchy()
    VisualElement.GetFirstOfType<T>()
    VisualElement.GetFirstAncestorOfType<T>()
    VisualElement.Contains(VisualElement)
    VisualElement.FindCommonAncestor(VisualElement)
    VisualElement.viewDataKey
    VisualElement.userData
    VisualElement.canGrabFocus
    VisualElement.focusController
    VisualElement.usageHints
    VisualElement.transform
    VisualElement.layout
    VisualElement.contentRect
    VisualElement.paddingRect
    VisualElement.worldBound
    VisualElement.localBound
    VisualElement.worldTransform
    VisualElement.pickingMode
    VisualElement.name
    VisualElement.enabledInHierarchy
    VisualElement.enabledSelf
    VisualElement.visible
    VisualElement.generateVisualContent
    VisualElement.experimental
    VisualElement.hierarchy
    VisualElement.cacheAsBitmap
    VisualElement.parent
    VisualElement.panel
    VisualElement.visualTreeAssetSource
    VisualElement.this[int]
    VisualElement.childCount
    VisualElement.schedule
    VisualElement.style
    VisualElement.customStyle
    VisualElement.styleSheets
    VisualElement.tooltip
    VisualElement.resolvedStyle
    Focusable.Blur()
    Focusable.focusable
    Focusable.tabIndex
    Focusable.delegatesFocus
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)
    CallbackEventHandler.HandleEvent(EventBase)
    CallbackEventHandler.HasTrickleDownHandlers()
    CallbackEventHandler.HasBubbleUpHandlers()
    CallbackEventHandler.ExecuteDefaultActionAtTarget(EventBase)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.AppUI.UI
    Assembly: Unity.AppUI.dll
    Syntax
    public class Canvas : BaseVisualElement, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle, IContextOverrideElement

    Constructors

    Canvas()

    Instantiates a Canvas element.

    Declaration
    public Canvas()

    Fields

    backgroundUssClassName

    USS class name of the background element of this type.

    Declaration
    public const string backgroundUssClassName = "appui-canvas__background"
    Field Value
    Type Description
    string

    cursorUssClassName

    USS class name prefix for the cursor.

    Declaration
    public const string cursorUssClassName = "cursor--"
    Field Value
    Type Description
    string

    horizontalScrollerUssClassName

    USS class name of the horizontal scroller element of this type.

    Declaration
    public const string horizontalScrollerUssClassName = "appui-canvas__horizontal-scroller"
    Field Value
    Type Description
    string

    ussClassName

    USS class name of elements of this type.

    Declaration
    public const string ussClassName = "appui-canvas"
    Field Value
    Type Description
    string

    verticalScrollerUssClassName

    USS class name of the vertical scroller element of this type.

    Declaration
    public const string verticalScrollerUssClassName = "appui-canvas__vertical-scroller"
    Field Value
    Type Description
    string

    viewportContainerUssClassName

    USS class name of the viewport container element of this type.

    Declaration
    public const string viewportContainerUssClassName = "appui-canvas__viewport-container"
    Field Value
    Type Description
    string

    viewportUssClassName

    USS class name of the viewport element of this type.

    Declaration
    public const string viewportUssClassName = "appui-canvas__viewport"
    Field Value
    Type Description
    string

    Properties

    contentContainer

    The content container of the Canvas.

    Declaration
    public override VisualElement contentContainer { get; }
    Property Value
    Type Description
    VisualElement
    Overrides
    VisualElement.contentContainer

    controlScheme

    The current control scheme of the canvas.

    Declaration
    public CanvasControlScheme controlScheme { get; set; }
    Property Value
    Type Description
    CanvasControlScheme

    frameContainer

    The container used for framing the Canvas.

    Declaration
    public Optional<Rect> frameContainer { get; set; }
    Property Value
    Type Description
    Optional<Rect>
    Remarks

    The container rect value must be defined in the Canvas' local coordinates.

    frameMargin

    The margin applied when framing the Canvas.

    Declaration
    public float frameMargin { get; set; }
    Property Value
    Type Description
    float

    grabMode

    The current grab state of the canvas (to pan).

    Declaration
    public GrabMode grabMode { get; }
    Property Value
    Type Description
    GrabMode

    maxZoom

    The maximum zoom factor of the Canvas.

    Declaration
    public float maxZoom { get; set; }
    Property Value
    Type Description
    float

    minZoom

    The minimum zoom factor of the Canvas.

    Declaration
    public float minZoom { get; set; }
    Property Value
    Type Description
    float

    panMultiplier

    The pan multiplier when Shift key is hold.

    Declaration
    public float panMultiplier { get; set; }
    Property Value
    Type Description
    float

    primaryManipulator

    The current manipulator of the canvas for the primary pointer without modifier.

    Declaration
    public CanvasManipulator primaryManipulator { get; set; }
    Property Value
    Type Description
    CanvasManipulator

    scrollDirection

    The scroll direction of the Canvas. See ScrollDirection for more information.

    Declaration
    public ScrollDirection scrollDirection { get; set; }
    Property Value
    Type Description
    ScrollDirection

    scrollOffset

    The scroll coordinates of the Canvas.

    Declaration
    public Vector2 scrollOffset { get; set; }
    Property Value
    Type Description
    Vector2

    scrollSpeed

    The scroll speed of the Canvas.

    Declaration
    public float scrollSpeed { get; set; }
    Property Value
    Type Description
    float

    useSpaceBar

    Whether the Canvas should use the Space bar to pan.

    Declaration
    public bool useSpaceBar { get; set; }
    Property Value
    Type Description
    bool

    zoom

    The zoom factor of the Canvas.

    Declaration
    public float zoom { get; set; }
    Property Value
    Type Description
    float

    zoomMultiplier

    The zoom speed multiplier when Shift key is hold.

    Declaration
    public float zoomMultiplier { get; set; }
    Property Value
    Type Description
    float

    zoomSpeed

    The zoom speed of the Canvas.

    Declaration
    public float zoomSpeed { get; set; }
    Property Value
    Type Description
    float

    Methods

    FrameAll()

    Frame the Canvas to see all elements.

    Declaration
    public void FrameAll()

    FrameArea(Rect)

    Frame the Canvas to the given area. The area is in the Viewport's local coordinates.

    Declaration
    public void FrameArea(Rect viewportArea)
    Parameters
    Type Name Description
    Rect viewportArea

    The area to frame.

    FrameElement(VisualElement)

    Frame the Canvas to the given element. The element is in the Viewport's local coordinates.

    Declaration
    public void FrameElement(VisualElement element)
    Parameters
    Type Name Description
    VisualElement element

    The element to frame.

    FrameWorldRect(Rect)

    Frame the Canvas to the given world area. The area is in world coordinates.

    Declaration
    public void FrameWorldRect(Rect worldRect)
    Parameters
    Type Name Description
    Rect worldRect

    The area to frame.

    GetGrabModeUssClassName(GrabMode)

    Declaration
    public static string GetGrabModeUssClassName(GrabMode enumValue)
    Parameters
    Type Name Description
    GrabMode enumValue
    Returns
    Type Description
    string

    Events

    scrollOffsetChanged

    Event that is triggered when the scroll position of the Canvas has changed.

    Declaration
    public event Action scrollOffsetChanged
    Event Type
    Type Description
    Action

    zoomChanged

    Event that is triggered when the zoom factor of the Canvas has changed.

    Declaration
    public event Action zoomChanged
    Event Type
    Type Description
    Action

    Implements

    IEventHandler
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IResolvedStyle
    IContextOverrideElement

    Extension Methods

    VisualElementExtensions.FindNavController(VisualElement)
    VisualElementExtensions.GetChildren<T>(VisualElement, bool)
    VisualElementExtensions.GetContextProvider<T>(VisualElement)
    VisualElementExtensions.GetContext<T>(VisualElement)
    VisualElementExtensions.GetPreferredTooltipPlacement(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement)
    VisualElementExtensions.GetTooltipTemplate(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement)
    VisualElementExtensions.ProvideContext<T>(VisualElement, T)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.SetPreferredTooltipPlacement(VisualElement, OptionalEnum<PopoverPlacement>)
    VisualElementExtensions.SetTooltipTemplate(VisualElement, VisualElement)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)