Skip to content

Styling

Use custom properties to switch a screen between colour sets, and transitions and animations to fade it or draw the eye to a changed value.

A document links each style sheet (.rcss) with <link type="text/rcss" href="..."/> in its head (Documents). What CSS is supported is in CSS support; what differs from a browser is in Coming from HTML and CSS, and Tailwind classes in Tailwind CSS. This page covers themes and animation.

Two samples show the style features a screen uses most. Themes switches colour sets with custom properties, and Animations fades a screen in and out and flashes a value when it changes. Run them by choosing Themes and Animations in the samples list in the map L_ArcRmlSamples (Samples).

Themes

The colours are custom properties on :root. A class on body declares them again, and every element below the body reads the new values through var(), so no other rule changes.

The Themes sample: a panel with Default, Dark and High contrast buttons

Themes.rcss
:root {
    --panel: #2c3a52;
    --text: #e8e8e8;
    --accent: #2f6fb0;
    --button: #3a4456;
}

body.theme-dark {
    --panel: #0c0e14;
    --text: #b8c0d0;
    --accent: #7a4fd0;
    --button: #1c212c;
}
Themes.rml
<body :model="themes" class:theme-dark="themes.Theme == 'dark'" class:theme-contrast="themes.Theme == 'contrast'">
Themes.rml
<button id="th-dark" class="th-button" on:click="call('themes', 'SetTheme', 'dark')">Dark</button>

SetTheme is a function of the sample's view model; the button's call runs it:

Themes/ArcRmlSamplesThemes.cpp
void UArcRmlSamplesThemesViewModel::SetTheme(const FString& Name)
{
    UE_MVVM_SET_PROPERTY_VALUE(Theme, Name);
}
  • class:theme-dark="Theme == 'dark'": the class is on while the expression is true. The default theme has no class.
  • class:theme-contrast="Theme == 'contrast'" does the same for the High contrast button, with body.theme-contrast declared in Themes.rcss.
  • var(--muted, #9aa6ba) uses #9aa6ba when --muted has no value; the sample gives it a value only in body.theme-contrast. A var() with no fallback and no value makes the property invalid, so it takes its inherited or initial value.
  • @property gives a custom property a type and an initial value; the sample does not use it.

Enter and leave

The host puts the class enter on body when the document is shown and leave when it closes. A rule on body.enter or body.leave starts the animation.

Animations.rcss
body.enter {
    animation: an-enter 0.4s linear forwards;
}

body.leave {
    animation: an-leave 0.3s linear forwards;
}
  • The leave ends when the body's animation or transition ends, at the latest after Leave Timeout Seconds (default 0.5 s, Project Settings > Game > ArcRmlUI > Transitions); then the document is removed. A leave animation longer than that is cut off. forwards holds the last frame until the document goes.
  • To see why a leave ended early, run log LogArcRmlUI Verbose in the console (Open the console). The log then shows leave started (timeout <s> s) and leave finished by <reason> after <ms> ms.
  • @starting-style is not supported: its rules are dropped. Use a @keyframes animation on body.enter for an entrance.

Pulse

pulse:<class>="Expr" adds the class to the element each time the value changes, so an animation that the class starts runs again.

Animations.rml
<p id="an-hits" class="an-hits" pulse:flash="animations.Hits">Hits: {{ animations.Hits }}</p>
Animations.rcss
.an-hits.flash {
    animation: an-flash 0.6s linear forwards;
}

Each change of Hits removes the class flash and adds it back in the same UI update, and the class stays until the next change. The <class> is the part of the attribute name after pulse:.

Limits

  • The first value never pulses, and several changes before one UI update give one pulse.
  • A view created in the update that changes the value (a :if branch, a new row) does not pulse.
  • An unkeyed :for row reads whichever item sits at its index, so an insert or a removal pulses it. Put pulses in keyed rows (Data binding).