Skip to content

Components

A component is an .rml file whose root is <component>: markup you write once and import into a document with a <dc-import> element, with props for the values that differ and slots for the children the importer supplies. The component file lives in a content root, by convention under UI/Rml/ like a document. The Component sample imports one file, Card.rml, twice; the LocalState sample is below.

Define a component

Card.rml
<component>
    <prop name="title" default="Card"/>
    <prop name="accentColor" default="#3399ff"/>
    <div class="cp-card">
        <div class="cp-card-head" style:background-color="$accentColor">{{ $title }}</div>
        <div class="cp-card-body"><slot/></div>
        <div class="cp-card-foot"><slot name="footer"/></div>
    </div>
</component>
  • <prop name="title" default="Card"/> declares a prop and its default. A prop with no default and no value is empty text.
  • type is optional: string (the default when type is missing), number, bool or function, as in <prop name="count" type="number" default="0"/>. A static value or default that does not fit fails the compile: a number takes a decimal number, a bool takes true, false or nothing. A function prop names a view model function the component calls, as in call('model', $onPress). A {{ }} value is not checked. The type is used only while compiling and in the editor, where the prop row edits a bool with a checkbox, a number with a number field and a function with a function picker.
  • The body reads a prop as $title: in an expression, as in style:background-color="$accentColor", and inside {{ }}, as in {{ $title }}.
  • <slot/> receives the children of the import. <slot name="footer"/> receives only the direct children that carry slot="footer".

Where a component's styles go

A component file holds markup only. Put its styles in the style sheet of the importing document (Component.rcss here), or in an .rcss file with the component's name next to it (Card.rcss), which the compile links into every document that imports the component.

The sample takes the first way:

Component.rcss
.cp-card {
    margin: 8px 0;
    background-color: #303846;
    border-radius: 4px;
}

.cp-card-head {
    padding: 6px 12px;
    border-radius: 4px;
    color: #101418;
}

.cp-card-body {
    padding: 8px 12px;
}

.cp-card-foot {
    padding: 4px 12px 8px;
}

Import a component

Component.rml
<dc-import name="/ArcRmlUISamples/UI/Rml/Component/Card" title="Static title" accent-color="#ff9933">
    <p>The default slot: any children.</p>
    <p slot="footer">The footer slot.</p>
</dc-import>
<dc-import name="/ArcRmlUISamples/UI/Rml/Component/Card" title="{{ Title }}">
    <p>Pressed {{ card.Count }} times.</p>
    <button id="cp-press" slot="footer" class="cp-button" on:click="call('card', 'Increment')">Press</button>
</dc-import>

Props

  • name is the absolute package path of the component file, .rml optional, or an alias declared in the head (below). Any other name that does not start with / is a compile error, and no folder is searched.
  • A prop is an attribute of the import. A prop declared in camelCase is written in kebab-case: accent-color="#ff9933" sets accentColor. An attribute that names no prop is a compile error.
  • A prop value is static text (title="Static title") or one whole-value expression (title="{{ Title }}"); text and {{ }} cannot be mixed in one value. A bound value reads the fields of the model the import sits in, here Title of the view model.
  • The import must be inside a :model. The component's own reads and calls name their model in full, as the import's document does (the second import's Pressed {{ Count }} times and Press button above).
  • :for, :if, :model and :key on an import apply to the <div class="sc-host">, the wrapper element the plugin puts around each import, not to the component's content.

Alias in the head

A document can name a component once in its <head> and import it by that name. The Component sample declares Card:

Component.rml
<link rel="component" href="/ArcRmlUISamples/UI/Rml/Component/Card" as="Card"/>
Component.rml
<dc-import name="Card" title="{{ card.Title }}">
  • href is the full package path; a missing file is a compile error even when no import uses the alias. as is a letter followed by letters, digits, - and _. A missing href or as, a duplicate alias, and a component link outside <head> are compile errors; an unused alias is silent.
  • The alias belongs to the document that declares it. It does not reach a component body: inside a component, name is a full path.
  • The links are removed from the compiled document.

Slots

Children of the import without a slot attribute go to the default slot, and a child with slot="footer" goes to the slot of that name. A named slot with no children renders nothing. A slot name the component does not declare is a compile error. In the sample, the second import puts a button in the footer, and the button's call('card', 'Increment') runs on the document's view model:

Component/ArcRmlSamplesComponent.h
UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "Samples")
FText Title = INVTEXT("Bound title");

UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "Samples")
int32 Count = 0;

UFUNCTION(BlueprintCallable, Category = "Samples")
void Increment();

Local state

A component keeps a value of its own with <state>, written beside its props. Its body reads it as state.<name> in any binding (:if, class:*, {{ }}, :value) and writes it with a plain assignment in an event. The LocalState sample's accordion opens and closes itself:

Accordion.rml
<component>
    <prop name="title" default="Section"/>
    <state name="open" type="bool" default="false"/>
    <div class="lc-acc">
        <button class="lc-button lc-acc-head" on:click="state.open = !state.open">{{ $title }} {{ state.open ? '-' : '+' }}</button>
        <div class="lc-acc-body" :if="state.open"><slot/></div>
    </div>
</component>
  • <state name="open" type="bool" default="false"/> must be self-closing and sit in the component header, before the body. name is letters, digits and _, starting with a letter. type is bool, number or string (the default); default is a literal of that type or one whole {{ expression }} reading props ({{ $start }}) and full model paths. A bad name, a duplicate, an unknown type or a default that does not fit fails the compile.
  • Every placed copy has its own value: the three accordions and the one per :for row open independently.
  • A state write is never sent to the game.
  • state is reserved. A :for iterator or a <viewmodel> named state is a validator error, and state.x that no <state> declares fails the compile. Only state as the first name of a path is state: vendor.state.x is a field of vendor.
  • Slot content means the state of the component whose file wrote it, not of the component it is placed in. In the sample's Panel.rml, which declares pinned, the toggle sits in the slot of an Accordion, yet it changes the Panel's pin mark:
Panel.rml
<component>
    <prop name="title" default="Panel"/>
    <state name="pinned" type="bool" default="false"/>
    <div class="lc-box">
        <div class="lc-box-head">{{ $title }}: {{ state.pinned ? 'pinned' : 'not pinned' }}</div>
        <dc-import name="/ArcRmlUISamples/UI/Rml/LocalState/Accordion" title="Pin from the slot">
            <p>The Panel is {{ state.pinned ? 'pinned' : 'not pinned' }}.</p>
            <button class="lc-button" on:click="state.pinned = !state.pinned">Toggle pin</button>
        </dc-import>
    </div>
</component>
  • A state returns to its default when its element is rebuilt: a :if that turns false and true again, a keyed :for row rebuilt out of order, a virtual list row that leaves the window. It is not kept across a document reload.
  • A view or screen (a document with <head>) declares <state> in its <head>, next to <viewmodel>, with the same attributes; its {{ }} default reads only full model paths (a view has no props). Each placement of a view and each :for row has its own value. A screen whose <body> has no :model needs nothing more: the state works without a model of your own.

Place a view

A view can be placed in another document with dc-import: a file with <rml> as its root and a <head>, the kind of file you open as a screen. Its <body> children go inside the sc-host wrapper, and the same file still opens alone. The EmbeddedViews sample places two views in one screen:

EmbeddedViews.rml
<dc-import name="/ArcRmlUISamples/UI/Rml/EmbeddedViews/PartyHeader"/>
<dc-import name="/ArcRmlUISamples/UI/Rml/EmbeddedViews/MemberCard" :for="m : party.Children" member="{{ m }}"/>
  • A shared model. A <viewmodel> of the view that is not manual joins the document's models. The same name with the same declaration (class, creation, path or resolver, OnClose, preview) is one shared model; the same name with a different declaration is a compile error. The header in the sample declares party as the screen does, so both read one object.
  • A given model. A manual model of the view is given by an attribute of the import that is named like the model and holds one whole-value {{ path }}: member="{{ m }}". Each placed copy reads and calls its own object, so each row's call('member', 'AddPoint') reaches only that row's member. A manual model without such an attribute is a compile error. A given model does not join the document's models; inside the view, :model and :for cannot use its name.
  • Attributes. :for, :if, :key and :virtual act on the wrapper as on a component, so the import needs a :model around it. A view has no props or slots: any other attribute, or any child of the import, is a compile error.
  • Head. The view's <link type="text/rcss"> and <style> join the document with no isolation; its <link rel="component"> aliases work inside that view only. Its <meta>, <title>, <script> and other head tags are ignored, and so are the attributes of its <body> except :model.
  • A view can place components and other views; a view that places itself is a compile error.

When components expand

Imports, views included, are expanded when the document is compiled, into its .rmlc file, the compiled copy the plugin runs (Concepts). A mistake in an import or a component, such as an unknown prop or slot name, is reported then (Validation), not while the game runs.

Run it

Play in the map L_ArcRmlSamples and choose Component in the samples list (Samples); the console command is ArcRmlSamples.Open Component.

The Component sample: two Card components, one with a static orange title and default and footer slots, one with a bound blue title and a Press button

Next