docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ImageLightbox

    A modal viewer for a single image, sized to the panel.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    ImageLightbox
    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 ImageLightbox : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
    Remarks

    The image is never scaled beyond its natural size: an asset whose only available file is small stays crisp at its own resolution rather than being upscaled into a blurry wall. The aspect ratio is preserved by construction, because the drawn size is the natural size times a single uniform factor that is only ever a shrink.

    Focus trapping, Esc, the scrim and outside-click dismissal all come from Modal rather than a hand-rolled overlay: Show(VisualElement) wraps this element in one and returns it, so the caller can keep configuring or dismiss it.

    Why it measures. The registry sizes this in viewport units — max-w-[min(90vw,64rem)], max-h-[90vh], the image at max-h-[70vh] — and UI Toolkit has no viewport unit. Nor is a percentage usable here: the lightbox's parent is the modal's shrink-to-fit content box, whose own size is what the lightbox is trying to determine, so a percentage against it is circular. So the element measures the Panel it is shown in on GeometryChangedEvent and applies the same fractions itself. They are viewport fractions, not design tokens, which is why they live in C# as panelWidthFraction / panelHeightFraction / imageHeightFraction rather than being invented as --appui-* vars. Everything that is design — the surface, the padding, the caption's colour and type — stays in USS on tokens.

    The caption doubles as the viewer's title, so there is no separate heading repeating the same string. With no src, or one whose texture never resolved, the fallback element is shown in the image's place.

    Navigation. Set navigationCount above 1 to show the image as one of a set: previous and next buttons either side of the caption, Left / Right arrow keys step too, and the caption leads with the position ("2 / 5"). Stepping never wraps. Each step updates navigationIndex and raises navigationIndexChanged; the caller swaps src and caption. When a step reaches an end and disables the button that had focus, focus moves to the other step button so the arrow keys keep working.

    Tall images. A picture more than tallRatio times taller than wide is shown at its full (capped) width and scrolls vertically, rather than being shrunk to the panel's height until nothing in it reads.

    Examples

    Opening a viewer over the current panel.

    var lightbox = new ImageLightbox
    {
        src = BackgroundExtensions.FromObject(fullResTexture),
        alt = "Cliff face, tiling",
        caption = "cliff-face-01.png",
    };
    lightbox.Show(rootVisualElement);

    UXML declaration — usually you let ZoomableThumbnail own one instead.

    <appui:ImageLightbox caption="cliff-face-01.png" alt="Cliff face, tiling" />

    Constructors

    ImageLightbox()

    Default constructor.

    Declaration
    public ImageLightbox()

    Fields

    captionUssClassName

    The styling class of the caption under the image.

    Declaration
    public const string captionUssClassName = "appui-imagelightbox__caption"
    Field Value
    Type Description
    string

    fallbackUssClassName

    The styling class of the container holding the fallback content.

    Declaration
    public const string fallbackUssClassName = "appui-imagelightbox__fallback"
    Field Value
    Type Description
    string

    footerUssClassName

    The styling class of the row holding the step buttons and the title.

    Declaration
    public const string footerUssClassName = "appui-imagelightbox__footer"
    Field Value
    Type Description
    string

    imageHeightFraction

    The share of the panel height the image itself may occupy, leaving room for the caption. The registry's max-h-[70vh].

    Declaration
    public const float imageHeightFraction = 0.7
    Field Value
    Type Description
    float

    imageUssClassName

    The styling class of the element the image is painted on.

    Declaration
    public const string imageUssClassName = "appui-imagelightbox__image"
    Field Value
    Type Description
    string

    navigationUssClassName

    The modifier class set while the viewer shows one image of a set.

    Declaration
    public const string navigationUssClassName = "appui-imagelightbox--navigation"
    Field Value
    Type Description
    string

    nextUssClassName

    The styling class of the next image button.

    Declaration
    public const string nextUssClassName = "appui-imagelightbox__next"
    Field Value
    Type Description
    string

    panelHeightFraction

    The share of the panel height the viewer may occupy. The registry's 90vh.

    Declaration
    public const float panelHeightFraction = 0.9
    Field Value
    Type Description
    float

    panelWidthFraction

    The share of the panel width the viewer may occupy. The registry's 90vw.

    Declaration
    public const float panelWidthFraction = 0.9
    Field Value
    Type Description
    float

    positionUssClassName

    The styling class of the position indicator ("2 / 5").

    Declaration
    public const string positionUssClassName = "appui-imagelightbox__position"
    Field Value
    Type Description
    string

    previousUssClassName

    The styling class of the previous image button.

    Declaration
    public const string previousUssClassName = "appui-imagelightbox__previous"
    Field Value
    Type Description
    string

    scrollUssClassName

    The styling class of the scroller holding the image. It only scrolls for a tall image.

    Declaration
    public const string scrollUssClassName = "appui-imagelightbox__scroll"
    Field Value
    Type Description
    string

    separatorUssClassName

    The styling class of the separator between the position and the caption.

    Declaration
    public const string separatorUssClassName = "appui-imagelightbox__separator"
    Field Value
    Type Description
    string

    tallRatio

    Taller than wide by more than this, a picture scrolls at full width instead of shrinking. The registry's TALL_RATIO.

    Declaration
    public const float tallRatio = 1.25
    Field Value
    Type Description
    float

    tallUssClassName

    The modifier class set while the image is tall enough to scroll.

    Declaration
    public const string tallUssClassName = "appui-imagelightbox--tall"
    Field Value
    Type Description
    string

    titleUssClassName

    The styling class of the title, the position followed by the caption.

    Declaration
    public const string titleUssClassName = "appui-imagelightbox__title"
    Field Value
    Type Description
    string

    ussClassName

    The ImageLightbox main styling class.

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

    Properties

    alt

    A textual description of the image, for assistive technology and for the tooltip.

    Declaration
    [CreateProperty]
    [UxmlAttribute("alt")]
    [Header("Image Lightbox")]
    public string alt { get; set; }
    Property Value
    Type Description
    string

    caption

    Shown under the image and used as the viewer's accessible name.

    Declaration
    [CreateProperty]
    [UxmlAttribute("caption")]
    public string caption { get; set; }
    Property Value
    Type Description
    string

    fallback

    Rendered in place of the image when there is no src, or its texture never resolved.

    Declaration
    public VisualElement fallback { get; set; }
    Property Value
    Type Description
    VisualElement

    hasImage

    Whether there is an image to paint.

    Declaration
    public bool hasImage { get; }
    Property Value
    Type Description
    bool
    Remarks

    A VectorImage counts, even though NaturalSize() deliberately reports zero for one: it has no pixel resolution to cap against, which is a sizing question, not a question of whether an image is there. Asking NaturalSize alone would hide a perfectly good vector image behind the fallback.

    isTall

    Whether the image is tall enough (see tallRatio) to be shown at full width and scrolled.

    Declaration
    public bool isTall { get; }
    Property Value
    Type Description
    bool

    navigationCount

    How many images the set holds. Above 1, the viewer shows step buttons, the position and answers the arrow keys; at 0 or 1 it shows a single image.

    Declaration
    [CreateProperty]
    [UxmlAttribute("navigation-count")]
    public int navigationCount { get; set; }
    Property Value
    Type Description
    int

    navigationIndex

    Which image of the set is shown, counting from zero. Only meaningful while navigationCount is above 1.

    Declaration
    [CreateProperty]
    [UxmlAttribute("navigation-index")]
    public int navigationIndex { get; set; }
    Property Value
    Type Description
    int

    nextLabel

    The accessible name of the next image button.

    Declaration
    [CreateProperty]
    [UxmlAttribute("next-label")]
    public string nextLabel { get; set; }
    Property Value
    Type Description
    string

    previousLabel

    The accessible name of the previous image button.

    Declaration
    [CreateProperty]
    [UxmlAttribute("previous-label")]
    public string previousLabel { get; set; }
    Property Value
    Type Description
    string

    src

    The image to display. Leave it unset while a larger image is still resolving, or when none exists — the fallback stands in.

    Declaration
    [CreateProperty]
    public Background src { get; set; }
    Property Value
    Type Description
    Background

    Methods

    Show(VisualElement)

    Show this viewer as a modal over the given panel.

    Declaration
    public Modal Show(VisualElement referenceView)
    Parameters
    Type Name Description
    VisualElement referenceView

    Any element in the panel the viewer should cover.

    Returns
    Type Description
    Modal

    The modal hosting this viewer.

    Remarks

    The modal owns the scrim, the focus trap, Esc and outside-click dismissal. The returned instance is not yet shown, so the caller can keep configuring it; call Show() on it, which this method already does, or Dismiss() to close it again.

    Events

    navigationIndexChanged

    Raised when the user steps to another image, with the index to show. The caller swaps src and caption.

    Declaration
    public event Action<int> navigationIndexChanged
    Event Type
    Type Description
    Action<int>

    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)