UI Toolbox logoUI Toolbox
Support

SplitPanel

SplitPanel in UIToolbox puts its children side by side, or one above the other, with a splitter between each two. The native TwoPaneSplitView takes exactly two panes and does not give its sizes back. SplitPanel takes any number of panes, and a focused splitter moves with the arrow keys and the gamepad directions. A pane can have its own smallest and largest size, and a pane can collapse.

Files, editor and inspector panes with a grip on each splitterFiles, editor and inspector panes with a grip on each splitter

<tb:SplitPanel
    name="editor"
    class="tb-split-panel--grip"
    style="height: 400px;">
    <ui:VisualElement
        name="files"
        class="tb-split-panel__pane--collapsible"
        style="min-width: 120px; max-width: 320px;" />
    <tb:SplitPanel vertical="true">
        <ui:VisualElement name="code" />
        <ui:VisualElement name="console" style="min-height: 60px;" />
    </tb:SplitPanel>
</tb:SplitPanel>
var split = root.Q<SplitPanel>("editor");
split.Sizes = saved ?? new[] { 1f, 3f };
split.SizesChanged += sizes => saved = sizes;

split.PaneCollapsedChanged += (pane, collapsed) =>
    filesButton.value = !collapsed;
split.CollapsePane(0);
split.ExpandPane(0);
Member Description
vertical (Vertical) True puts the panes one above the other.
min-pane-size (MinPaneSize) The smallest size in pixels that a drag or a key leaves each pane. Default 32.
key-step (KeyStep) The pixels that one arrow key or gamepad direction moves a focused splitter. Default 16.
Sizes The part of the space that each pane takes; the parts add up to 1. Set it to restore saved sizes, or set ratios such as 1, 3. A collapsed pane has the part 0, and a part of 0 collapses its pane.
SizesChanged A drag, a key, a gamepad direction, MoveSplitter, CollapsePane or ExpandPane changed the sizes. Not raised when code sets Sizes. Each event gets its own array, and nothing is built when no handler listens.
MoveSplitter(index, pixels) Moves the edge after pane index. It keeps the two panes inside their limits. Returns false when nothing moved.
CollapsePane(index) Collapses a pane to zero. The pane after it takes the space (the pane before it, for the last pane). Returns false when nothing changed.
ExpandPane(index) Gives a collapsed pane the size that it had, but at least its smallest size. Returns false when nothing changed.
IsPaneCollapsed(index) True when the pane is collapsed.
PaneCollapsedChanged(index, collapsed) A pane collapsed or expanded. Not raised when code sets Sizes.
Panes, GetSplitter(index) The panes in order (a copy, so a loop can remove panes), and the splitter after pane index.
Refresh() Styles the panes and puts a splitter between each two. Each layout change runs it; call it to see the splitters in the same frame as an added pane.

Smallest and largest size of a pane

Set min-width and max-width on a pane (min-height and max-height in a vertical panel), inline or in USS. A drag, a key and a gamepad direction stop at these limits. The layout keeps them too when the panel changes its size.

MinPaneSize is the smallest size for the panes that have no larger min-width of their own. It limits only a drag and the keys.

When the two panes of a splitter have no room for both limits, the splitter does not move.

Collapsible panes

Add the class tb-split-panel__pane--collapsible to a pane. Then:

CollapsePane and ExpandPane work on each pane, with or without the class. A collapsed pane has the class tb-split-panel__pane--collapsed and no margin, padding or border. The other pane of the splitter takes the space. A pane does not collapse when that other pane has a max-width that is too small for the space.

The grip

Add the class tb-split-panel--grip to the panel to show a grip in the middle of each splitter. The class works on the splitters of that panel only, not on a nested panel.

Tips

In the examples

Styling

Class Element
tb-split-panel The panel (grows). The variable --tb-split-panel-thickness on it is the width of the splitter (default 4px). Its child selector .tb-split-panel > * gives each pane an equal flex-grow: UI Toolkit matches a child against its logical parent, so a selector on the inner row does not reach the panes.
tb-split-panel--vertical The panes are one above the other.
tb-split-panel--grip You add it: the splitters show their grip.
tb-split-panel__panes The row (or column) of panes.
tb-split-panel__pane A pane. The panel adds it; it has no look of its own.
tb-split-panel__pane--collapsible You add it to a pane that the user can collapse.
tb-split-panel__pane--collapsed A collapsed pane (no margin, padding or border).
tb-split-panel__splitters The layer over the panes that holds the splitters.
tb-split-panel__splitter A splitter. It lies over the edge between two panes, half on each. Border color; accent color on hover and focus.
tb-split-panel__splitter--dragging The splitter during a drag (accent color).
tb-split-panel__grip The grip in a splitter: a pill of 8 by 28 pixels (surface-alt background, border; accent border on hover, focus and drag). Hidden without tb-split-panel--grip.

The SplitPanelDemo scene shows a codex with a list and an entry, a level editor with side panes that collapse, a game view over a chat that saves and restores its sizes, and a crafting bench in a game skin of wood and parchment.

The splitter and the grip show the themed resize cursors. See Cursors.