Class ZoomableThumbnail
A thumbnail that can be opened full-size.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class ZoomableThumbnail : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
The thumbnail owns its own ImageLightbox and builds a Modal for it only when the user asks, so a grid of these costs no more than the images themselves. The modal is dismissed by a click outside the viewer, by Esc, or by CloseZoom().
triggerMode chooses the affordance. Corner puts a
ZoomTriggerButton in the top corner, hidden until the thumbnail is hovered or the
control itself takes focus. Whole stretches that same control over
the whole image and paints a scrim behind its glyph on hover, which is what tells the user the
picture is a button. USS has no :focus-within, so the reveal is keyed off the control's own
:focus plus a class this element raises while hovered.
Set trigger to false to render just the image, with no control and no viewer, for a caller whose thumbnail sits inside another interactive element such as a list item or a button. A nested control there is unreachable, so such a caller hosts the control and the viewer itself, as a sibling of that element.
A larger image can be supplied up front through fullSrc, or resolved lazily through loadFullSrc, which is called at most once and never on mount, so a grid of these issues no requests until someone actually zooms.
Not ported from the registry. The web version keeps its dialog mounted at all times, because unmounting it in the same commit that closes it skips the library's close path and can leave the document hit-test-dead. UI Toolkit's Modal owns no such global state and is dismissed explicitly, so the viewer is built on demand here and the guard would be dead code.
Examples
A grid tile with a corner control and a lazily resolved full-size image.
var thumb = new ZoomableThumbnail
{
src = BackgroundExtensions.FromObject(previewTexture),
alt = "Cliff face, tiling",
caption = "cliff-face-01.png",
fallback = new Icon { iconName = "image" },
};
thumb.loadFullSrc = resolved => StartCoroutine(FetchFullRes(url, resolved));
UXML declaration — the whole picture is the control.
<appui:ZoomableThumbnail caption="cliff-face-01.png" alt="Cliff face" trigger-mode="Whole" />
Constructors
ZoomableThumbnail()
Default constructor.
Declaration
public ZoomableThumbnail()
Fields
fallbackUssClassName
The styling class of the container holding the fallback content.
Declaration
public const string fallbackUssClassName = "appui-zoomablethumbnail__fallback"
Field Value
| Type | Description |
|---|---|
| string |
imageUssClassName
The styling class of the element the thumbnail is painted on.
Declaration
public const string imageUssClassName = "appui-zoomablethumbnail__image"
Field Value
| Type | Description |
|---|---|
| string |
triggerModeUssClassName
The ZoomableThumbnail trigger-mode styling class.
Declaration
public const string triggerModeUssClassName = "appui-zoomablethumbnail--"
Field Value
| Type | Description |
|---|---|
| string |
triggerUssClassName
The styling class of the zoom control, whichever mode it is in.
Declaration
public const string triggerUssClassName = "appui-zoomablethumbnail__trigger"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The ZoomableThumbnail main styling class.
Declaration
public const string ussClassName = "appui-zoomablethumbnail"
Field Value
| Type | Description |
|---|---|
| string |
Properties
alt
A textual description of the enlarged image. The thumbnail itself is decorative.
Declaration
[CreateProperty]
[UxmlAttribute("alt")]
[Header("Zoomable Thumbnail")]
public string alt { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
caption
Names the asset, in the zoom control's label and under the enlarged image.
Declaration
[CreateProperty]
[UxmlAttribute("caption")]
public string caption { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
fallback
Shown when there is no image, or it fails to resolve. Also handed to the viewer, so an enlarged image that never arrives shows the same thing.
Declaration
public VisualElement fallback { get; set; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
fullSrc
A larger image already known to the caller. Preferred over src when zoomed.
Declaration
[CreateProperty]
public Background fullSrc { get; set; }
Property Value
| Type | Description |
|---|---|
| Background |
hasImage
Whether the thumbnail has an image to paint.
Declaration
public bool hasImage { get; }
Property Value
| Type | Description |
|---|---|
| bool |
lightbox
The viewer this thumbnail opens. Exposed so a caller can style it or read what it is showing.
Declaration
public ImageLightbox lightbox { get; }
Property Value
| Type | Description |
|---|---|
| ImageLightbox |
loadFullSrc
Resolves a larger image lazily. Called at most once, on first open — never on mount.
Declaration
public FullImageResolver loadFullSrc { get; set; }
Property Value
| Type | Description |
|---|---|
| FullImageResolver |
src
The small image. Unset means there is nothing to show or zoom, and the fallback stands in.
Declaration
[CreateProperty]
public Background src { get; set; }
Property Value
| Type | Description |
|---|---|
| Background |
trigger
Whether the thumbnail offers the zoom control and the viewer at all.
Declaration
[CreateProperty]
[UxmlAttribute("trigger")]
public bool trigger { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
triggerButton
The zoom control. Exposed so a caller can drive it directly, or read the wording it uses.
Declaration
public ZoomTriggerButton triggerButton { get; }
Property Value
| Type | Description |
|---|---|
| ZoomTriggerButton |
triggerMode
Where the zoom control sits, and how much of the thumbnail it takes.
Declaration
[CreateProperty]
[UxmlAttribute("trigger-mode")]
public ZoomTriggerMode triggerMode { get; set; }
Property Value
| Type | Description |
|---|---|
| ZoomTriggerMode |
Methods
CloseZoom()
Dismiss the viewer, if it is open.
Declaration
public void CloseZoom()
GetTriggerModeUssClassName(ZoomTriggerMode)
Declaration
public static string GetTriggerModeUssClassName(ZoomTriggerMode enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ZoomTriggerMode | enumValue |
Returns
| Type | Description |
|---|---|
| string |
OpenZoom()
Open the viewer, resolving a larger image first if one has been promised.
Declaration
public void OpenZoom()