Skip to content

Images

A document draws an image from a file, from a part of a file, from a sprite sheet, from an SVG, or from a texture asset, and a view model can choose which one. The Images sample shows each way with a caption and swaps two bound images. Run it by choosing Images in the samples list in the map L_ArcRmlSamples (Samples).

The Images sample: captioned cells, one for each way to draw an image

Image files

Images.rml
<img class="im-box" src="Images/Picture.png" width="64" height="64"/>
<img class="im-box" src="Images/Sprites.png" rect="32 0 32 32" width="64" height="64"/>
  • src is a png file; an SVG file is drawn with <svg>. A path that starts with / is a package path, any other path is relative to the document (Coming from HTML and CSS).
  • rect="x y w h" draws that part of the file, in the file's pixels. Any other count of numbers logs a warning and the whole file is drawn.
  • Give every image a width and a height, or the layout jumps when the file loads: without both, the image is 0 by 0 until the file is decoded, and the layout runs again.

Sprite sheets

Images.rcss
@spritesheet im-sprites {
    src: Images/Sprites.png;
    im-circle: 0px 0px 32px 32px;
    im-square: 32px 0px 32px 32px;
    im-diamond: 0px 32px 32px 32px;
    im-cross: 32px 32px 32px 32px;
}
Images.rml
<img class="im-sprite" sprite="im-circle"/>

@spritesheet names the file, then each sprite as name: x y w h. sprite wins over src and rect.

RmlUi only

@spritesheet and sprite have no counterpart in a browser. A sprite name that the document's style sheets do not declare draws nothing and logs Could not find sprite.

SVG

Images.rml
<svg class="im-box" src="Images/Star.svg" width="64" height="64"/>
<svg class="im-inline im-inline-blue" viewBox="0 0 24 24" width="64" height="64"><path d="M12 2 L22 21 L2 21 Z" fill="currentColor"/></svg>
  • <svg src="..."> draws an SVG file, sharp at any size.
  • An <svg> without src draws its own content.
  • currentColor takes the element's CSS color, so one shape serves every colour: .im-inline-blue sets color: #3a86ff and .im-inline-green sets color: #3ccf6e. This applies when the SVG text contains currentColor (case-sensitive) and the <svg> has no color attribute.
  • stroke-width on the <svg> replaces the stroke width of the SVG's root, so one line icon can be drawn thinner or bolder.
  • width and height set the size; without them the size comes from the SVG. viewBox and preserveAspectRatio work as in a browser, and so do object-fit and object-position. The SVG is converted to pixels at the size it is drawn, and again when that size or its colour changes.
  • The svg decorator draws an SVG file in an element's box: decorator: svg(Images/Star.svg), or svg(Images/Star.svg crop-to-content) to draw only the part of the drawing that has content.
  • <img>, url(), image(), masks and @spritesheet do not read SVG: the file draws nothing and the log says has an unsupported image format.

What an SVG can contain

SVG files and inline <svg> content are drawn by lunasvg.

  • Drawn: shapes and paths, groups, use and symbol, linear and radial gradients, patterns, clip paths, masks, markers, opacity, and a <style> element inside the SVG with type, class, id and attribute selectors.
  • Not drawn: filters, animation (animate, set), foreignObject, switch and textPath. An element of a kind that is not drawn is skipped with everything inside it.
  • use names an element of the same SVG (href="#id"), not one in another file. An <image> inside an SVG draws an embedded data: image; a path to another file is not resolved against the document and does not ship.
  • <text> takes its font from the operating system's font folder, not from the plugin's font sheets, so the text can look different or be missing on another machine or platform. Convert text to paths before saving the SVG.
  • The document's style sheets do not reach the shapes inside an inline <svg>; color reaches them through currentColor.

Texture assets

Images.rml
<img class="im-box" src="asset:/ArcRmlUISamples/UI/Rml/Images/T_Sample_Picture.T_Sample_Picture" width="64" height="64"/>

src="asset:/Package/Path.Object" draws a Texture2D asset, for a picture that should be cooked and compressed like any other texture. The document compile reports an asset: that names a missing asset, another class, or a texture with Virtual Texture Streaming on. A runtime warning is logged for an asset that could not be loaded, loads as another class, has no GPU resource or has no size.

A value that holds {{ }} or var() is not checked by the compile; only the runtime warnings report it.

Images from a view model

Images.rml
<svg id="im-bound-icon" class="im-box" attr:src="images.Icon" width="64" height="64"/>
<img id="im-bound-picture" class="im-box" attr:src="images.Picture" width="64" height="64"/>
Images/ArcRmlSamplesImages.h
UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "Samples")
FArcRmlImageRef Icon;

UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "Samples")
TSoftObjectPtr<UTexture2D> Picture;
Field type src becomes
FArcRmlImageRef Its Path, the package path of an image file. The property editor's picker lists .svg files.
TSoftObjectPtr, FSoftObjectPath, UTexture* asset:<path>; empty when nothing is set.
FString The text as it is.

The sample's Swap function sets both fields, and the document follows the change (Data binding). The four values (FirstIcon, SecondIcon, FirstPicture, SecondPicture) are defaults of a Blueprint subclass of the view model, BP_ImagesVM, which the document names in its head. Set the image paths in a Blueprint subclass of your own view model the same way, and no path is written in C++.

The validator checks a literal src, not a attr:src (Validation); a bound image that is not found is reported only at run time.

What a packaged build ships

  • Package Everything on (the default): every png and svg file under a content root ships, except under UI/Rml/Test/ (Packaging).
  • Package Everything off: the images that a shipped document or style sheet names literally ship, and so do the FArcRmlImageRef values that the cook finds in Blueprint class defaults and graph pins, data assets and data tables (Project setup).
  • An SVG named only in a decorator: svg(...) value is not found by the cook: with Package Everything off, list its folder in Paths to Package.
  • A literal asset: texture in a shipped document or style sheet is cooked with it. A texture that a view model field references is an ordinary asset reference of the Blueprint or data asset that holds it.

An image path that only runtime data holds is not shipped when Package Everything is off: a plain FString field, in a Blueprint's class defaults or set from C++. Use FArcRmlImageRef or a texture reference, or name the image in a document.

Drawing is asynchronous

A file image (<img>, fill-image, an image in a decorator property, a sprite sheet) is decoded in the background and draws nothing until it is ready, typically within one or two drawn frames. An SVG is converted to pixels the same way and keeps the last image while a new size or colour is converted. A file that cannot be decoded logs Could not load texture once.