Widgets and layout

The Miri widget set, how a frame is measured, arranged and painted, and how focus, keyboard shortcuts and gamepad navigation are routed.

Last updated Dec 4, 2026Version 1.1.0

Miri is a retained-mode widget framework in the Miri namespace. Widgets are C++ classes prefixed with M, built with a declarative MiriNew(...) syntax, and laid out in slots. This page lists the widget set, explains the three layout passes, and shows how focus decides where keyboard shortcuts and gamepad input go.

The widget set

Every widget derives from MWidget MWidget. The shipped widgets live under Miri/Widgets/, plus a few framework and docking widgets.

GroupWidgets
PanelsMHorizontalBox, MVerticalBox (both MBoxPanel), MOverlay, MGridPanel, MUniformGridPanel, MWrapPanel, MFlexBox, MScrollBox, MSplitter, MSplitBox, MBox, MBorder, MClipBox, MScaleBox, MDPIScaler, MWidgetSwitcher, MRetainerBox, MExpandableArea, MDrawer, MCard
TextMTextBlock, MRichTextBlock, MEditableTextBox, MMultiLineEditableTextBox, MSearchBox, MNumericField, MHyperlink
InputMButton, MCheckBox, MRadioButton, MToggleSwitch, MSlider, MComboBox, MSegmentedControl, MColorPicker, MKeyCap, MKeyCaptureField
DataMListView, MTreeView, MTileView, MTableView with MTableHeader, MLevelTable, MDetailsView
DisplayMImage, MIconGlyph, MProgressBar, MShape, MSpinner, MSkeleton, MBadge, MChip, MAvatar, MBanner, MEmptyState, MSpacer, MSeparator, MPerformanceOverlay
Navigation and chromeMBreadcrumb, MMenu, MMenuBar, MTabBar, MToolbar, MPopover, MWindowFrame
Editor-gradeMGraphEditor, MCurveEditor, MCurvePreview, MTimeline, MAssetPicker, MViewport

Two rules for fixed-size art: draw an icon glyph in a box with MIconGlyph, which centres the glyph's ink, not a text block with the icon font, which centres the line box and lands the glyph off-centre.

The full list with every member is in the Miri API reference. Game screens reach a subset of these through the MiriGraphics factory; see Game screens.

Shapes

MShape draws a radial meter, a ring, an ellipse or a regular polygon without a texture. Each shape is one distance-field quad, so a row of meters batches into a single draw call whatever their progress, colour or size, and the edge stays one device pixel wide at any scale. MShape takes part in retained painting.

KindWhat it draws
RingA full circle track plus a sweep of Progress around it, starting at twelve o'clock and running clockwise.
ArcThe same meter on a 270 degree gauge that opens at the bottom.
EllipseAn ellipse filling the widget, or an outline of Thickness drawn inside it.
PolygonA regular polygon of 3 to 12 sides with a vertex at the top, Rotation in radians and corners rounded by CornerRadius.

Thickness is the ring's or outline's width, TrackColor the unfilled part of a meter (transparent draws no track) and RoundCaps rounds the ends of the progress sweep. The renderer exposes the same shapes as DrawRing, DrawArc, DrawEllipse and DrawRegularPolygon, which take angles in radians clockwise from twelve o'clock. An arbitrary convex polygon does not fit the shape vertex and is not supported. An ellipse outline is measured with a first-order distance estimate, so its width stays within a few percent of Thickness on moderate aspect ratios and thins or thickens toward the tips of a very elongated ellipse; a filled ellipse covers its analytic area to within 2 percent. A renderer without the distance-field pipelines draws no shapes and logs one warning.

In a .ui file the node type is Shape:

Text
Shape Meter {
    shape: "arc"
    progress: 0.37
    thickness: 8
    shape_size: 64
    color: "accent"
    track_color: "surface3"
    round_caps: true
}

shape is ring, arc, ellipse or polygon; shape_size is one number or a vec2; sides, rotation (degrees) and corner_radius apply to polygons. progress and color can be bound and animated like the properties in Game screens.

Building a widget tree in C++

MiriNew(T) expands to a builder that takes named arguments and returns a shared pointer Engine/Source/UI/Miri/Api/Miri/Framework/MiriDeclarativeSyntax.h. Container widgets take children through slots: + MVerticalBox::Slot()...[ child ]. A box slot is either auto-sized to the child's desired size or fills a share of the remaining space, and every slot carries padding and horizontal and vertical alignment Engine/Source/UI/Miri/Api/Miri/Core/CSlot.h. MBox takes the same alignment arguments: with anything but Fill the child is sized to its desired size and placed inside the padded rect, and MImage honours its Sizing (Stretch, Fit, Fill, Original).

MainMenu.cpp
#include <Miri/Widgets/MBoxPanel.h>
#include <Miri/Widgets/MButton.h>
#include <Miri/Widgets/MTextBlock.h>
#include <Miri/Mowo/MiriMowoStyle.gen.h>

Miri::COnClicked onPlay;
onPlay.Bind([]() {});

Miri::TSharedPtr<Miri::MWidget> title = MiriNew(Miri::MTextBlock).Text(Miri::CText::FromString("Main menu")).ColorAndOpacity(Miri::Mowo::MowoColors::TextBright);
Miri::TSharedPtr<Miri::MWidget> play = MiriNew(Miri::MButton).OnClicked(onPlay).CornerRadius(3.0f);

Miri::TSharedPtr<Miri::MWidget> menu = MiriNew(Miri::MVerticalBox)
	+ Miri::MVerticalBox::Slot().AutoHeight().Padding(16.0f)[title]
	+ Miri::MVerticalBox::Slot().AutoHeight().Padding(16.0f, 4.0f)[play];

Widget arguments come in three kinds, declared in each widget's MIRI_WIDGET_ARGS block: MIRI_ATTR for attributes that can hold a value or a bound getter, MIRI_ARG for plain values, and MIRI_EVENT for delegates MTextBlock Engine/Source/UI/Miri/Api/Miri/Widgets/MButton.h.

Visibility

EVisibility has five values EVisibility:

ValuePaintedTakes spaceHit-testable
Visibleyesyesyes
Hiddennoyesno
Collapsednonono
HitTestInvisibleyesyesno, and nor are its children
SelfHitTestInvisibleyesyeschildren only

How layout works

Miri lays out a frame in three passes, the same shape Slate uses.

  1. Measure (bottom-up)
  2. Arrange (top-down)
  3. Paint (top-down)
Each pass has its own cache, so an unchanged tree measures and arranges nothing.
  1. Measure. Each widget reports its desired size from ComputeDesiredSize. Leaves measure their content; containers add up their children MWidget.
  2. Arrange. Each parent gives every child a rect in ArrangeChildren MWidget.
  3. Paint. OnPaint draws from the arranged geometry MWidget.

The desired-size cache

Measure always runs through CacheDesiredSize(scale), which decides whether measuring is needed at all MWidget. When you write a container, read child sizes through the cache:

C++
child->CacheDesiredSize(geo.GetScale());
const Miri::MiriVec2 size = child->GetDesiredSize();

Calling ComputeDesiredSize on a child by hand re-measures that child's whole subtree every time. Pass the geometry's scale, not 1.0f: a different scale counts as a scale change and forces a re-measure.

A widget opts into the cache by returning true from CanCacheDesiredSize(). The default is false MWidget. The rule for opting in: the desired size must depend only on the widget's own attributes and its children's cached sizes, and every input that can change must call Invalidate() MWidget. Things that disqualify a widget:

  • a bound attribute the widget does not poll, because a getter can change without a write;
  • measure that depends on arrange, like text that elides against its arranged width;
  • children generated during arrange;
  • external state such as a font atlas or a texture that can change under the widget.

A widget whose size never depends on its children (scroll boxes, list, tree and table views, viewports) can also return false from DesiredSizeDependsOnChildren(), which stops the measure pass from walking below it MWidget.

Change only what is painted (hover, check state, a swatch color) without calling Invalidate(). That split is what keeps hover effects from re-running layout.

MWidget::InvalidateAllWidgets() drops every cached size at once. It is used for changes no single widget can see, such as a style-set swap or an application scale change MWidget.

The arrange skip

Arrange has its own cache. A widget opts in with CanSkipArrange(). The default is "skippable only when it has no children", so any widget that overrides ArrangeChildren must answer for itself MWidget. A skip is safe only when the arrange is a pure function of the allotted geometry, the widget's attributes and its children's cached sizes. Scroll offsets, animation clocks and virtualized row windows disqualify a widget.

If you suspect a stale-layout bug, MWidget::SetArrangeSkipEnabled(false) turns the arrange skip off in-process MWidget.

Skipping unchanged windows

A window whose widgets raised no invalidation, received no input and drew the same picture on its last two paints skips its layout, paint and upload, and shows its last batch again (miri.SkipUnchangedWindows). Every few skipped frames it paints anyway and compares; a difference makes it paint every frame for a while.

A widget whose picture changes with the clock, with nothing written that the window could see, has to tell the window:

CallWhenEffect
MWidget::NoteLivePaint()The picture changes on every frame (a fade, a scroll animation)The window paints every frame while the widget keeps calling it
MWidget::NoteRepaintIn(seconds)The picture changes at one known moment (a caret's next blink, the end of a scroll bar's hide delay)The window may skip until then and paints again at that moment

Prefer NoteRepaintIn whenever the change is a single step: a focused text field and a scroll bar waiting to hide used to repaint the whole window on every frame of the wait MWidget. A widget that advances its own timer from the paint's frame delta must measure real elapsed time instead, because the frames in between may have been skipped.

Flex layout

MFlexBox lays children out along one axis the way CSS flexbox does Engine/Source/UI/Miri/Api/Miri/Widgets/MFlexBox.h. Use it when children should share leftover space by weight, shrink together when the row is too narrow, or wrap onto further lines. Set the container's SetDirection (row, row-reverse, column, column-reverse), SetJustify (how leftover main-axis space is spread: start, end, center, space-between, space-around, space-evenly), SetAlignItems (placement on the cross axis; stretch by default), SetWrap, SetAlignContent (how wrapped lines share the cross axis) and the SetGap and SetCrossGap spacing. SetFlowDirection(EFlowDirection::RightToLeft) mirrors a row, as it does for MBoxPanel.

Each child's CFlexSlot carries Grow (default 0), Shrink (default 1), Basis (-1 uses the child's desired size), minimum and maximum width and height, AspectRatio (width over height; the cross size follows the main size) and AlignSelf. Free space is shared by the grow weights, or removed by the shrink weights scaled by each child's basis; a child that hits its minimum or maximum is frozen at that size and the rest share what is left. The slot padding is the child's margin. A collapsed child takes no space; a hidden one keeps its space, and switching between the two re-lays the box out.

SetAlignContent accepts start, end, center, stretch, space-between, space-around and space-evenly; with a single line (no wrap) the line fills the cross axis.

Free space. When the children are larger than the container (shrink 0, or minimums that stop them shrinking) the leftover is negative and follows CSS: end overflows toward the start, center overflows equally on both sides, start overflows toward the end, and space-between falls back to start while space-around and space-evenly fall back to center. The same applies to the lines of a wrapped box under SetAlignContent; stretch adds nothing when the lines already overflow.

Where this differs from CSS. These are deliberate.

  • There is no automatic minimum size: an item with no minimum width or height can shrink below its content, so a single item wider than a line shrinks to the line instead of overflowing it. Set a minimum on the slot to stop that.
  • SetAlignContent defaults to start, not stretch, so wrapped lines pack at the start of the cross axis unless you ask otherwise. Existing screens rely on this, so the default stays.
  • Slot padding is logical: in a right-to-left flow the start side of the padding is the right side, matching MBoxPanel.
  • When a wrapping box changes the width it wraps at, it asks for a new layout, and an auto-height parent follows within a frame or two.

Properties of the box: Direction, Justify, AlignItems, AlignContent, Wrap, Gap, CrossGap and FlowDirection, each with a setter and getter. AddSlot appends a CFlexSlot and ClearSlots removes them all. The slot fields are Grow, Shrink, Basis, MinWidth, MaxWidth, MinHeight, MaxHeight (0 means no maximum), AspectRatio and AlignSelf (auto uses the box's align-items), each with a chained setter.

A wrapping box measures against the width it was last arranged in, so it does not cache its desired size; a single-line box does.

Focus and keyboard routing

A widget that can take keyboard focus returns true from IsFocusable() MWidget. Focus moves with a click, with CReply::SetUserFocus, or with Tab: the input processor's FocusAdjacentWidget focuses the next or previous focusable widget in paint order Engine/Source/UI/Miri/Api/Miri/Input/CMiriInputProcessor.h.

Key events walk the focus path first. A widget that handles a key in its own OnKeyDown wins outright. Only when every widget on the path declines does the key reach the command system.

Focus scopes

The same shortcut can mean different things in different panels. Ctrl+D duplicates an actor in the Outliner and an array element in the Details panel. Miri decides by focus, not by where the mouse is.

A subtree becomes a focus scope by stamping its root with a scope id. Each CMiriFocusScope owns its own command list CMiriFocusScope:

MyPanel.cpp
m_focusScope.SetId(Miri::CName("mygame.inventory"));
m_focusScope.AddRootWidget(m_root);
m_focusScope.GetCommandList().MapAction(Miri::CName("inventory.drop"), [this]() { DropSelected(); }, [this]() { return HasSelection(); });

When a command fires, CMiriCommandSystem::ExecuteCommand tries, in order:

  1. The focus path

    Scopes on the path from the focused widget to the root, innermost first.

  2. Pushed command lists

    Lists added with PushCommandList, most recent first.

  3. The global command list

    The fallback for application-wide shortcuts.

A scope that binds a command but whose canExecute callback returns false falls through like an unbound one, so coarser contexts still get their turn CMiriCommandSystem.

OwnsInput(pointerFallback) is the guard editor panels use: focus decides whenever any scope owns it, and the pointer-hover answer is used only when nothing is focused CMiriFocusScope. That keeps shortcuts working for a user who never clicked into a panel.

While an MComboBox popup is open, it counts as text input, so plain letters go to the dropdown instead of the panel's shortcuts. A list at or above SearchThreshold entries grows a filter field; shorter lists use type-ahead. MaxVisibleItems caps the popup height MComboBox.

Gamepad navigation in game screens

Game screens add directional navigation on top of Miri focus. CMiriGraphicsScreenStack provides CMiriGraphicsScreenStack:

CallWhat it does
HandleDirectional(dx, dy)Picks the nearest focusable widget in the pressed direction. Falls back to a linear cycle only when the tree has no geometry (headless).
HandleAccept()Activates the focused widget directly: click, toggle or open. It does not synthesize mouse events.
HandleBack()Runs the back handler set with SetBackHandler, then pops the top code-pushed screen.
NotifyInputDevice(device)Switching to Gamepad shows the focus highlight; switching to MouseKeyboard hides it.

A modal screen keeps focus inside itself until it is popped. See Game screens.

The Particles widget draws a UI particle emitter in one batch; see Particles. The RenderTargetImage widget shows the live output of a scene capture; see Showing a scene capture. The ActionButton widget shows the glyph of an input action for the device in use and fires with that action, so a hint such as "B Back" is also the control. See Glyphs and action buttons.

Each .ui node can override directional navigation with nav_up, nav_down, nav_left and nav_right: inherit, escape, stop, wrap or explicit, with nav_<dir>_target naming the widget an explicit rule goes to. Rules inherit down the tree. clip_to_bounds clips a container's paint and hit test, and flow_direction (inherit, ltr, rtl) mirrors the horizontal layout of a container and everything in it. A stack created under a right-to-left culture starts mirrored.

Text input

MEditableTextBox (single line), MMultiLineEditableTextBox, MSearchBox and MNumericField share one editing core, CMiriTextEditing CMiriTextEditing:

  • The caret, Backspace and Delete move by grapheme cluster, so an emoji sequence, a flag or a letter with combining accents is one step.
  • Ctrl+arrow keys and Ctrl+Backspace move by word. By default a full stop between letters is a word boundary, so foo.bar/baz stops at the dot and the slash; pass EMiriWordTailoring::Unicode for plain Unicode words. A double-click selects the word under the pointer.
  • A single-line field scrolls to keep the caret in view, and a paste turns every line break into a space.
  • Copy and cut with nothing selected do nothing.
  • IsReadOnly(true) allows selecting and copying only, and declines editing keys so a panel's own shortcuts still receive them. IsPassword(true) masks the text MEditableTextBox.
  • The caret blinks at the operating system's rate, and stays solid when blinking is turned off in the OS.

Engine sources

This page describes behavior implemented in these files of the engine repository, checked against commit 672ba079b.

  • Engine/Source/UI/Miri/Api/Miri/Framework/MWidget.h
  • Engine/Source/UI/Miri/Api/Miri/Framework/MiriDeclarativeSyntax.h
  • Engine/Source/UI/Miri/Api/Miri/Core/CSlot.h
  • Engine/Source/UI/Miri/Api/Miri/Core/MiriTypes.h
  • Engine/Source/UI/Miri/Api/Miri/Core/MiriDelegate.h
  • Engine/Source/UI/Miri/Api/Miri/Widgets/MBoxPanel.h
  • Engine/Source/UI/Miri/Api/Miri/Widgets/MButton.h
  • Engine/Source/UI/Miri/Api/Miri/Widgets/MTextBlock.h
  • Engine/Source/UI/Miri/Api/Miri/Widgets/MComboBox.h
  • Engine/Source/UI/Miri/Api/Miri/Widgets/MShape.h
  • Engine/Source/UI/Miri/Api/Miri/Framework/CMiriFocusScope.h
  • Engine/Source/UI/Miri/Api/Miri/Commands/CMiriCommandSystem.h
  • Engine/Source/UI/Miri/Api/Miri/Input/CMiriInputProcessor.h
  • Engine/Source/Gameplay/MiriGraphics/Api/MiriGraphics/CMiriGraphicsScreenStack.h
  • Engine/Source/UI/Miri/Api/Miri/Widgets/MEditableTextBox.h
  • Engine/Source/UI/Miri/Api/Miri/Text/CMiriTextEditing.h
  • Engine/Source/UI/Miri/Api/Miri/Widgets/CMiriCaretBlink.h

Page feedback

Was this page helpful?