Editor preview¶
A document can declare a view model whose data is a JSON file. The data stands in for the real view model, so a designer sees real-looking values without code, in the editor and in a game.
The declaration and the JSON¶
<viewmodel name="player" preview="Preview/EditorPreview.json"/>
The path is relative to the document. A preview declaration takes no class, no source attribute
(create, context, resolver, manual or path), no settable and no on-close.
{
"Name": "Aldric",
"Level": 7,
"Health": 0.8,
"Accent": { "$colour": "#3399ffff" },
"bLowHealth": false,
"Items": ["Stone axe", "Oak staff", "Iron shield"],
"$variants": {
"LowHealth": {
"Health": 0.15,
"Accent": { "$colour": "#e04040ff" },
"bLowHealth": true,
"Items": ["Stone axe"]
}
}
}
- The root is an object; each top-level key is a field of the model. Values are booleans, integers, numbers,
strings, arrays and objects.
nullis an error. - A colour is
{ "$colour": "#rrggbbaa" }, and$colouris the object's only member. $variantsis an object of named variants. A variant lists the fields it overrides; every other field keeps its base value. An overridden field is replaced as a whole, soItemsinLowHealthis the complete list. A variant can name only fields the base data has, else the file does not load and an error is logged.
The document reads these fields like any other model's: {{ Name }}, :if="bLowHealth",
:for="item : Items".
When the data shows¶
The data shows in the editor preview and in a game with a local player, when all of these hold:
- The build is not a Shipping build.
- The console variable
ArcRml.PreviewHiddenis 0. It applies to documents opened afterwards and does not exist in Shipping. - The JSON file exists.
Otherwise the model binds default values and its field ArcResolved is false. The sample shows a fallback line with it:
<p :if="!player.ArcResolved">No preview data is shown.</p>
Never make live behaviour depend on preview data. A function called on a preview model only logs, so a button that calls one does nothing except log.
Open the preview tab¶
In the Content Browser, double-click EditorPreview.rml: the preview tab opens and shows the sample with the base data,
"Aldric, level 7", a health bar and three items. Its toolbar, above all tabs, has Save (Ctrl+S; greyed when nothing is unsaved) and Browse (selects the
document in the Content Browser; greyed when it has no item there), then Resolution,
Variant (Base and the variants of the document's preview files), Theme, Background, Play, Open
in text editor and Reload. Left of the view is the Hierarchy, below it View Bindings, View State and Source (see Bind from the panels). Beside the view, the panels are Details, View Models, Preview Data, Diagnostics, Inspector and
Input:
- Details shows the selected element (Bind from the panels).
- View Models lists the document's view models as a tree of fields and functions with the places that use them, and adds and removes their
<viewmodel>declarations (see Bind from the panels). - Preview Data holds the preview values of each view model; for a preview model it edits the JSON data: add keys, rename or remove them, and override a value in the selected variant.
- Diagnostics lists the errors and warnings of the open document.
- Inspector shows the element you select: tree, box model and rules by selector (Debugging layout).
- Input lists the actions of the document's input mapping context for keyboard or gamepad. After you choose gamepad, the preview view takes focus, so a pad works at once.
- Source shows the document's text, coloured for RML tags, attributes, values, comments,
{{ }}expressions and the RCSS of<style>blocks, below the view with View Bindings. Edit it and pressCtrl+Sor Save: the file is written as you typed it, keeping its byte order mark and line endings, and the preview reloads. The tab reads "Source*" while it holds unsaved text; the panels that write the document are then read-only under "Save or discard the Source changes" and Discard reloads the file. A file that is not plain UTF-8 with one kind of line ending opens read-only. If the file changed on disk, Save asks whether to overwrite it, load it from disk or cancel; closing the window with unsaved text asks Save, Discard or Cancel. Line numbers run down the left side and the line with the cursor is highlighted. Selecting an element moves the cursor to its line, marks that line and highlights the element's start tag; the marks are not shown while the text has unsaved changes, come back after Save, Discard or undo, and show the start tag only when the file on disk is the one the preview was built from (read-only files show the line only).
Each panel is a dockable tab: drag it to another dock, or open a closed one from the window menu of the preview tab. One layout is saved and shared by all documents.
The Variant menu ends with Add variant..., which asks for a name and adds an empty variant to every JSON preview file of the document that lacks it. It is disabled when the document has no JSON preview file that loaded.
Bind from the panels¶
The panels write the document's .rml and .rcss files, so a binding needs no typing of binding attributes. Every
change is one edit of the file text at the element's own position: the rest of the file stays as you wrote it.
- Open the preview tab with Play off. Hover the view: the element under the pointer is outlined when it has a tag in a file. Click it to select it, or select its row in the Hierarchy or the Inspector tree. Details under the tabs shows the selection. Tick Play to use the document with the mouse instead.
- The Hierarchy lists those elements with badges Binding, Event, Text and Asset; "Only bindings and assets" hides
the rows without a badge. View Bindings lists the bindings,
:forlists and events of the elements, and their{{ }}text expressions (read-only; Edit text scrolls Details to its Text section). It shows the selected element only until you clear "Selected element only"; the search box filters by element, attribute or value. Change a value in its row, or press Add to add a row: pick the element (the selected one by default), the property, then its value. Details lists the element's attributes in the categories Content, Visibility, Form, Events, Classes, Attributes and Style (and Other for the rest). Every property the element can take has a row, set or not, with a value editor for the static value (keyword list, colour picker (hex,rgb,hsl,oklab,oklch), number and unit, checkbox, asset picker, font weight list, font family chips, token list forvar()andcalc(); emptying a text field removes the attribute) and a Bind button. Bind lists the fields of the document's view models that fit the property's type under Valid and the others under Invalid; a field the runtime would refuse is listed with its reason. A bound row shows the picked parts with Edit and Unbind. Advanced binding... in the Bind menu, or Edit, opens the binding editor under the row: the field, + Conversion (a transform whose input fits), and for a condition rows of value, operator (==,!=,<,>,<=,>=or "is true") and value joined by All or Any; the raw expression is only under Advanced. Above those categories Details shows design sections with plain names: Layout, Size, Spacing, Text, and Fill and Border. They write the same properties as the Style rows. A control that needs another property (Direction needs Row/Column layout) is greyed with a hint and, where one value fixes it, a button that sets it. The Style category is under Advanced (CSS), closed by default. Picking a member of a list's rows (for examplerows.Name) on an element that does not repeat asks whether to add a:forover that list to the element and writes both in one step. On a:forrow, Advanced: fields on the page (closed by default) lists each field of the row type and the places that read it, each a link that selects the element; a field nothing reads says "not shown". Thedata-actionpicker offers close (closes this screen), open (another screen; components are not listed) and custom (the value goes to the body view model'sHandleAction), each with a help line. - A text field writes on Enter or when you leave it; a pick from a list writes at once. The panel shows "Reloading…" until the preview has reloaded the document, and then selects the element again.
Each attribute row shows its name with a one-line meaning under it; hover for the attribute name and the meaning. An event row's mode
switch reads Call (writes call(), runs the function each time the event fires) or Call If (writes callIf(), runs it only when its condition is
true as the event fires). An argument that does not fit the function's parameter shows "'x' (string) does not fit parameter 'Value' (int32)."
under the row: a number fits any numeric parameter (int and float both ways), a string fits string, name and text parameters, a bool fits a bool, and
an argument whose type the editor cannot tell (an expression, a loop item) always fits. The function list greys a function whose parameters do not
fit the current arguments and says why. The runtime stays lenient; this is the check the validator makes too (Validation).
If a write is refused, for example because the file changed on disk since the preview compiled it, the panel shows the
reason and writes nothing. A write is one undo step (Ctrl+Z), and with source control enabled the file is checked out
first.
On a component instance (a dc-import) the panel shows the props of the component. Edit in component switches to the
component's own tag, which every instance shares; Open component opens a preview tab of the component file, which shows the component alone with each prop at its
declared default; a double-click on an import row in the Hierarchy does the same. Open in text editor in that
tab opens the text.
For an element that comes from a component or view, Details starts with one line, "From
Panel.rml placed in CartPanel.rml placed in VendorScreen.rml" (the component, the view, the document); each file name opens its preview tab.
On the instance, Details shows only the style the import keeps (position, left, right, top, bottom, inset, width, height, z-index, transform). Other declarations on the dc-import tag are listed as ignored, each with a remove button, and Bind offers no style: binding there; edit the component's own look with Edit in component.
Each prop row's tooltip gives the prop's type, its default and the lines where the component reads it ("disabled on div.dk-button (line 14)"),
or says "Not read by the component."; each listed use is a link that opens the component at that line. A prop's type (type on its <prop>, see Components)
sets the editor: a checkbox for bool, a number field for number, the function list for function, text otherwise.
The Hierarchy hides the elements a component brings from its own file; tick Show component internals (per preview tab)
to list them greyed under the import. The Asset badge of an import row covers only asset attributes on the dc-import
tag itself.
View State lists on the left the <state> declarations of the document (name, type String, Bool or Number, default) with Add, edit and remove,
and on the right the bindings that read or write only state.*; Details and View Bindings do not list those. A state can carry named values (values="0:All, 1:Common", editor metadata only); condition rows then show the name ("tabsActive = Common"), and Fill from buttons proposes names from the buttons that assign the state.
The View Models tab does the same for the head of the document. Each view model is a tree node: Browse and Open select a Blueprint model in the Content Browser or open its editor, and open a C++ model's class in your code editor; Fields and Functions list the members with a type icon. A member the document uses shows "N uses", and expanding it lists each place (element, attribute, expression); click one to select its line. + Viewmodel adds a <viewmodel> declaration: pick
the class, the name and the creation type. Click a view model to edit its class and creation type in Details; with nothing
selected, Details shows Head metas (layer, input mode, frame, input mapping and the flags). While the document cannot be written, the tree, Browse and Open still work; Remove and + Viewmodel are greyed. Broken references below the tree shows what the validator found in the document; click an entry to select its element.
In a game¶
In a running game, open the console and type:
ArcRml.Preview /ArcRmlUISamples/UI/Rml/EditorPreview/EditorPreview.rml LowHealth
ArcRml.Preview <Path> [Variant] opens the document with a variant and reopens it when it is open. <Path> is the
document's package path. Leave out the variant for the base data.
You should see the sample panel in the game with "Aldric, level 7", the line "Health is low." and the one item
"Stone axe".
ArcRml.Close /ArcRmlUISamples/UI/Rml/EditorPreview/EditorPreview.rml or the sample's Close button closes it.