ImageView

EntityVisualQuadLayerViewceramic.ImageView (Class)
Implements: tracker.Observable

A view component for displaying and laying out images with flexible scaling options.

ImageView provides automatic image loading from asset IDs and supports multiple scaling modes to fit images within their container. It handles texture management and cleanup automatically.

Features:

  • Automatic asset loading from image paths or asset IDs
  • Multiple scaling modes (FIT, FILL, CUSTOM)
  • Proper texture lifecycle management
  • Reactive updates when image or scaling properties change
var imageView = new ImageView();
imageView.size(200, 150);
imageView.image = "hero.png";
imageView.scaling = FIT; // Scale to fit within bounds

// Or use FILL to cover the entire area
imageView.scaling = FILL;

// Or use custom scaling
imageView.scaling = CUSTOM;
imageView.imageScale = 2.0;

Instance Members

ui
observedDirty: Bool

Default is false, automatically set to true when any of this instance's observable variables has changed.


ui
imageScale: Float

Custom scale factor for the image. Only applied when scaling mode is set to CUSTOM. Default is 1.0 (original size).


ui
scaling: Anonymous

Determines how the image is scaled within the view bounds.

  • FIT: Scale to fit within bounds while maintaining aspect ratio
  • FILL: Scale to fill the entire bounds, cropping if necessary
  • CUSTOM: Use the imageScale value Default is FIT.

ui
image: AssetId<String>

The image to display, specified as an asset ID or path. Setting this will automatically load the image texture. Set to null to clear the image.


ui
imageQuadInheritsAlpha: Bool

Whether the internal image quad inherits the view's alpha value. When true, the image opacity is multiplied by the view's alpha. Default follows the quad's inheritAlpha setting.


ui
invalidateImageScale(): Void

ui
invalidateScaling(): Void

ui
invalidateImage(): Void

ui
setImageTexture(texture: Texture): Void

Directly sets the image texture without going through asset loading. Useful when you already have a texture reference. Handles cleanup of previously loaded textures.

Name Type Description
texture Texture The texture to display, or null to clear

ui
destroy(): Void

ui
computeSize(parentWidth: Float, parentHeight: Float, layoutMask: ViewLayoutMask, persist: Bool): Void

Computes the view size based on the image dimensions and constraints. Calculates the appropriate scale factor for FIT mode.

Name Type
parentWidth Float
parentHeight Float
layoutMask ViewLayoutMask
persist Bool

ui
new(): Void

Creates a new ImageView with default settings. The view is transparent by default and contains a centered image quad.

Private Members

ui
unobservedImageScale: Float

ui
unobservedScaling: Anonymous

ui
unobservedImage: AssetId<String>

ui
imageQuad: Quad

The internal quad used to render the image texture.


ui
computedImageScale: Float

The computed scale factor based on FIT scaling mode.


ui
loadedTexture: Texture

Reference to the currently loaded texture for lifecycle management.


ui
emitObservedDirty(instance: ImageView, fromSerializedField: Bool): Void

Event when any observable value as changed on this instance.

Name Type
instance ImageView
fromSerializedField Bool

ui
emitImageScaleChange(current: Float, previous: Float): Void

Event when imageScale field changes.

Name Type
current Float
previous Float

ui
emitScalingChange(current: Anonymous, previous: Anonymous): Void

Event when scaling field changes.

Name Type
current Anonymous
previous Anonymous

ui
emitImageChange(current: AssetId<String>, previous: AssetId<String>): Void

Event when image field changes.

Name Type
current AssetId<String>
previous AssetId<String>

ui
updateImageScale(): Void

Updates the image quad scale based on the current scaling mode. Called automatically when scaling or imageScale properties change.


ui
updateImage(): Void

Loads and sets the image texture based on the current image property. Handles asset loading, texture management, and cleanup of previous textures.


ui
layout(): Void

Positions and sizes the image quad within the view bounds. Handles different scaling modes including cropping for FILL mode.

Metadata

Name Parameters
:build tracker.macros.ObservableMacro.build()
:autoBuild tracker.macros.ObservableMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()