docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class CardGrid

    A responsive gallery that flows Card tiles into as many columns as the available width allows.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    CardGrid
    Implements
    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder
    Inherited Members
    BaseVisualElement.contextPrefix
    BaseVisualElement.densityOverride
    BaseVisualElement.themeOverride
    BaseVisualElement.langOverride
    BaseVisualElement.layoutDirectionOverride
    BaseVisualElement.preferredTooltipPlacementOverride
    BaseVisualElement.tooltipDelayMsOverride
    BaseVisualElement.GetLayoutDirectionUssClassName(Dir)
    VisualElement.disabledUssClassName
    VisualElement.SetActivePseudoState(bool)
    VisualElement.SetCheckedPseudoState(bool)
    VisualElement.Focus()
    VisualElement.SendEvent(EventBase)
    VisualElement.SetEnabledFromHierarchy(bool)
    VisualElement.SetEnabled(bool)
    VisualElement.MarkDirtyRepaint()
    VisualElement.IsMarkedForRepaint()
    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.SetBinding(BindingId, Binding)
    VisualElement.GetBinding(BindingId)
    VisualElement.TryGetBinding(BindingId, out Binding)
    VisualElement.GetBindingInfos()
    VisualElement.GetBindingInfos(List<BindingInfo>)
    VisualElement.HasBinding(BindingId)
    VisualElement.ClearBinding(BindingId)
    VisualElement.ClearBindings()
    VisualElement.GetHierarchicalDataSourceContext()
    VisualElement.GetDataSourceContext(BindingId)
    VisualElement.TryGetDataSourceContext(BindingId, out DataSourceContext)
    VisualElement.TryGetLastBindingToUIResult(in BindingId, out BindingResult)
    VisualElement.TryGetLastBindingToSourceResult(in BindingId, out BindingResult)
    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.disablePlayModeTint
    VisualElement.usageHints
    VisualElement.transform
    VisualElement.scaledPixelsPerPoint
    VisualElement.layout
    VisualElement.contentRect
    VisualElement.paddingRect
    VisualElement.worldBound
    VisualElement.localBound
    VisualElement.worldTransform
    VisualElement.hasActivePseudoState
    VisualElement.hasInactivePseudoState
    VisualElement.hasHoverPseudoState
    VisualElement.hasCheckedPseudoState
    VisualElement.hasEnabledPseudoState
    VisualElement.hasDisabledPseudoState
    VisualElement.hasFocusPseudoState
    VisualElement.hasRootPseudoState
    VisualElement.pickingMode
    VisualElement.name
    VisualElement.enabledInHierarchy
    VisualElement.enabledSelf
    VisualElement.languageDirection
    VisualElement.visible
    VisualElement.generateVisualContent
    VisualElement.dataSource
    VisualElement.dataSourcePath
    VisualElement.dataSourceType
    VisualElement.experimental
    VisualElement.hierarchy
    VisualElement.cacheAsBitmap
    VisualElement.parent
    VisualElement.panel
    VisualElement.contentContainer
    VisualElement.visualTreeAssetSource
    VisualElement.this[int]
    VisualElement.childCount
    VisualElement.schedule
    VisualElement.style
    VisualElement.resolvedStyle
    VisualElement.customStyle
    VisualElement.styleSheets
    VisualElement.tooltip
    Focusable.Blur()
    Focusable.focusable
    Focusable.tabIndex
    Focusable.delegatesFocus
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, CallbackOptions)
    CallbackEventHandler.UnregisterAllRemovableCallbacks()
    CallbackEventHandler.HasTrickleDownHandlers()
    CallbackEventHandler.HasBubbleUpHandlers()
    CallbackEventHandler.ExecuteDefaultActionAtTarget(EventBase)
    CallbackEventHandler.HandleEventBubbleUp(EventBase)
    CallbackEventHandler.HandleEventTrickleDown(EventBase)
    CallbackEventHandler.ExecuteDefaultAction(EventBase)
    CallbackEventHandler.NotifyPropertyChanged(in BindingId)
    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
    [UxmlElement]
    public class CardGrid : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
    Remarks

    CardGrid is the UITK counterpart of a CSS repeat(auto-fill, ...) grid. UI Toolkit has no CSS grid and no gap, so the layout is computed instead: the grid is a wrapping flex row, and on every resize it works out how many columns of at least minItemWidth fit, then writes a width and the inter-tile margins onto each child. The result matches the web component's behaviour, including the ragged trailing row.

    fill picks between the two column strategies: with true (the default) the columns stretch to share the leftover width, so tiles only change size when the column count changes; with false every column is exactly minItemWidth wide and the row is left-packed, so tile size tracks minItemWidth continuously.

    The gap stays a token rather than a C# constant. CardGrid.uss sizes a hidden, absolutely positioned probe element from a density-aware --appui-sizing-* step, and the grid reads the gap back off that probe's resolved width. It therefore rescales with Panel.density on its own and never appears as a literal in code. (UITK cannot read a px length back through a float custom property, which is why the probe exists.)

    The grid is layout-direction aware. Under .appui--rtl the row itself flips to row-reverse in USS, so tile 0 sits against the right edge, and Reflow() writes the inter-tile gap onto margin-left instead of margin-right so it stays on the trailing edge of each tile. The column arithmetic is direction-agnostic, so column count and tile widths are identical in both directions.

    Note: because CardGrid writes width, margin-left, margin-right and margin-bottom onto its children, do not set those four inline on a tile — they are overwritten on every re-flow. Everything else, including the tile height, is yours.

    Examples

    A template gallery in UXML.

    <appui:CardGrid min-item-width="240">
        <appui:Card interactive="true">
            <appui:CardHeader><appui:CardTitle text="2D Platformer" /></appui:CardHeader>
        </appui:Card>
        <appui:Card interactive="true">
            <appui:CardHeader><appui:CardTitle text="First Person" /></appui:CardHeader>
        </appui:Card>
    </appui:CardGrid>

    Fixed-width columns, built in C#.

    var grid = new CardGrid { minItemWidth = 160, fill = false };
    foreach (var template in templates)
    {
        var card = new Card { interactive = true };
        var header = new CardHeader();
        header.Add(new CardTitle { text = template.name });
        card.Add(header);
        grid.Add(card);
    }

    Constructors

    CardGrid()

    Default constructor.

    Declaration
    public CardGrid()

    Fields

    gapProbeUssClassName

    The styling class of the hidden element the grid measures its inter-tile gap from.

    Declaration
    public const string gapProbeUssClassName = "appui-card-grid__gap-probe"
    Field Value
    Type Description
    string

    ussClassName

    The CardGrid main styling class.

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

    Properties

    fill

    Whether the columns stretch to fill the row.

    Declaration
    [Tooltip("Whether the columns stretch to share the leftover width.")]
    [CreateProperty]
    [UxmlAttribute]
    public bool fill { get; set; }
    Property Value
    Type Description
    bool
    Remarks

    true (the default) shares the leftover width between the columns, so the trailing edge is flush. false pins every column to minItemWidth and leaves the leftover width unused at the end of the row.

    minItemWidth

    The per-item width, in pixels.

    Declaration
    [Tooltip("The minimum width of a tile before the grid drops a column.")]
    [CreateProperty]
    [UxmlAttribute]
    public float minItemWidth { get; set; }
    Property Value
    Type Description
    float
    Remarks

    With fill this is the minimum width a tile may have before the grid drops a column; without it, it is the exact column width.

    resolvedColumnCount

    The number of columns the grid last flowed into. 1 until the grid has been laid out.

    Declaration
    public int resolvedColumnCount { get; }
    Property Value
    Type Description
    int

    resolvedGap

    The gap currently applied between tiles, in resolved pixels.

    Declaration
    public float resolvedGap { get; }
    Property Value
    Type Description
    float
    Remarks

    Read-only, and driven by the --appui-card-grid-gap custom property, so it changes with the panel density rather than with any C# setting.

    resolvedLayoutDirection

    The layout direction the grid last flowed in.

    Declaration
    public Dir resolvedLayoutDirection { get; }
    Property Value
    Type Description
    Dir
    Remarks

    Read-only, and driven by the nearest DirContext provider, usually the Panel. In Rtl the tiles flow from the right edge and the gap moves to each tile's left side.

    Methods

    Reflow()

    Recomputes the column count and re-applies the tile widths and margins.

    Declaration
    public void Reflow()
    Remarks

    This runs automatically whenever the grid resizes, its density changes or one of its properties is set. Call it directly only after mutating the children outside a layout pass.

    Implements

    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder

    Extension Methods

    VisualElementExtensions.FindNavController(VisualElement)
    RegisterUpdateCallbackExtensions.RegisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    RegisterUpdateCallbackExtensions.UnregisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    VisualElementExtensions.EnableDynamicTransform(VisualElement, bool)
    VisualElementExtensions.EnablePicking(VisualElement, bool)
    VisualElementExtensions.GetChildren<T>(VisualElement, bool)
    VisualElementExtensions.GetContextProvider<T>(VisualElement)
    VisualElementExtensions.GetContextProvider<T>(VisualElement, string)
    VisualElementExtensions.GetContext<T>(VisualElement)
    VisualElementExtensions.GetContext<T>(VisualElement, string)
    VisualElementExtensions.GetExclusiveRootElement(VisualElement)
    VisualElementExtensions.GetLastAncestorOfType<T>(VisualElement)
    VisualElementExtensions.GetPreferredTooltipPlacement(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement, string)
    VisualElementExtensions.GetTooltipContent(VisualElement)
    VisualElementExtensions.GetTooltipTemplate(VisualElement)
    VisualElementExtensions.HasAncestorOfType<T>(VisualElement, bool)
    VisualElementExtensions.HasAncestorsOfType<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement, string)
    VisualElementExtensions.IsInvisible(VisualElement)
    VisualElementExtensions.IsOnScreen(VisualElement)
    VisualElementExtensions.ProvideContext<T>(VisualElement, string, T)
    VisualElementExtensions.ProvideContext<T>(VisualElement, T)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.SetPreferredTooltipPlacement(VisualElement, OptionalEnum<PopoverPlacement>)
    VisualElementExtensions.SetTooltipContent(VisualElement, VisualElementExtensions.TooltipContentCallback)
    VisualElementExtensions.SetTooltipTemplate(VisualElement, VisualElement)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    In This Article
    Back to top
    Copyright © 2026 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)