Layout and Rendering Notes

RmlUi follows CSS closely, but not completely, and this integration has a few properties of its own. These are the differences that cost time when they are not known.

Layout

  • A width is not derived from left and right. An absolutely positioned element given both has no width of its own, and its children shrink-wrap; inside a scrolling container that collapses a whole panel to one character wide. Give it width: 100%, or make it a flex item.

  • box-sizing is content-box: width: 100% plus padding overflows the parent.

  • float: right only works beside something that shrink-wraps, such as an inline-block; beside a block it lands on the next line. Inside a white-space: nowrap row it also drops to the line below – size the row’s cells as inline-blocks in source order instead.

  • A display: block child of such a row resolves width: 100% wider than the row; leave it auto.

  • Bare text directly inside a display: flex element does not draw. Wrap a caption in a block, and centre it with padding or line-height.

  • A style rule for div does not match <section>; RCSS matches tag names literally.

  • An unstyled scrollbar collapses its box. The moment an overflow-y: auto element overflows, RmlUi creates a scrollbarvertical element inside it; with no rule giving that element a width, the content is laid out at zero width and every child collapses to one word per line, whatever width it declares. It looks like a flex or percentage bug and is neither. Give the scrollbar a width and a colour:

    scrollbarvertical { width: 6dp; }
    scrollbarvertical sliderbar { background-color: #888; }
    

    and the content lays out at the box’s width minus the bar.

Rendering

  • Filters, backdrop-filter, mask-image, box-shadow and gradients need GLSL 1.50. On macOS that takes a core-profile context (gl-version 3 2); without one these effects draw wrong or not at all, while plain boxes, text and images still render.

  • An element with a filter, a backdrop-filter or a mask-image is drawn into a window-sized offscreen layer and composited back; layers nest, one per such element on the way down the tree. The region makes rmlui-layer-pool-size layer buffers ready (8 by default). A buffer takes GPU memory only once it has been drawn to, and keeps it afterwards. A frame that needs more buffers than there are draws the extra layers unfiltered once, logs a warning, and has them from the next frame on.

  • A rounded overflow clip (border-radius with overflow: hidden), and clipping under a transform, use the stencil buffer and hold across layers: a filtered child of a rounded panel is clipped by the rounding like its siblings. The window needs stencil bits for this (framebuffer-stencil true).

  • blur(<length>) takes the standard deviation, as in CSS; the blur radius of a box-shadow or a drop-shadow is twice its standard deviation. The kernel reaches three standard deviations and is exact up to a deviation of 21 pixels; wider blurs are sampled more coarsely.

  • A box-shadow is rendered once and kept as a texture the size of the shadow, until the element’s box or shadow changes.

  • The 2D scene graph (aspect2d, render2d) draws over the RmlUi region. Anything parented there has to be hidden together with the screen it belongs to.

  • Colours are display (sRGB) values, as in a browser: a #808080 box is byte 128 on screen, gradients and alpha blending mix the encoded values, and filters work on them. On a window with an sRGB framebuffer (framebuffer-srgb true, which a linear 3-D scene needs) the region writes them unencoded – DisplayRegion.framebuffer_srgb is false on every RmlRegion – so the interface looks the same as on a plain window, while the 3-D regions of the same window are still encoded. Set it back to true only for a page whose colours are linear.

Files

  • The files a document names (style sheets, fonts, images, templates) are opened through the virtual file system: as given if that names a file, otherwise searched along the model-path. An absolute path and .. are allowed, as they are for models and textures.

  • When loading RML the game did not ship – a mod, UI sent by a server – set rmlui-restrict-to-model-path true: a file outside the model-path directories is then refused, with an error in the rmlui category. The check compares names; symbolic links are not resolved.

  • An image is read from its file for the UI, not shared with the texture pool: the same file used on a model is a second texture.

Threads

RmlUi is not thread-safe, and the region does not lock. The context is updated during the cull stage and drawn during the draw stage of the frame; with a threading-model that moves either stage to another thread, those run at the same time as the application’s calls on the context, its documents, elements and data models. Use the default single-threaded model with RmlRegion; the region logs a warning otherwise. Loading documents and changing elements from a task or an event handler on the main thread is always safe.

Contexts

  • The font engine keeps a context’s glyph atlases after the context is destroyed (a few textures per context; a later context on the same address reuses them). This is bounded, but it is a reason to create a context once per process where possible and to load and unload documents, not contexts, when screens change.

  • A destroyed context’s name is released only once its region is gone. When a region is replaced within a frame, give the new one a fresh name.

Debugging

RmlRegion.init_debugger() installs RmlUi’s inspector on the region; RmlRegion.debugger_visible shows it. Log messages from the library go to the rmlui notify category, so notify-level-rmlui debug in a prc file reports context creation, document loading and every RCSS error.