Tab groups and dock zones
The user makes a tab group by dragging a window onto another window. From code, workspace.GroupAsTabs(windows) puts windows in one new tab group. The TabsDemo.unity example shows window tabs and tabs inside a window. Its chat tab group is in a small workspace inside the Preview, see A workspace inside a window. The Declarative.unity example docks, tabs and floats the windows of a starship bridge.


Video tutorial: Docking. All videos: Video tutorials.
Merge and the no-merge key
- During the drag, the window below the pointer shows a border in
--tb-color-drop-target. A drop there makes the two windows tabs of one group. - A drag of a tab out of its strip makes a standalone window again.
- A strip too narrow for its tabs shows no scroll bar. The mouse wheel scrolls the tabs sideways, and a selected tab scrolls into view. A tab is at least 80 pixels wide, so a group of four tabs needs a window about 370 pixels wide to show them all.
- Hold Shift during the drag to stop the merge. The border does not show, and the window lands on top of the other window. The key also stops a drop into a tab group or a dock zone.
no-merge-modifieron the workspace sets the key:Shift(default),Control,AltorNone(no key).
<tb:Workspace no-merge-modifier="Alt" />
workspace.NoMergeModifier = EventModifiers.Control;
Turn merging off
allow-merge on the workspace is true by default. With false, no window is a merge zone: the drag shows no border, and a dropped window lands on top of the window below it. A tab dragged from a group lands on the workspace and tears off. A drop into a tab group or a dock zone is off too. The no-merge key still works when merging is on.
allow-merge on a window is Inherit (default), Allow or Deny. A window that cannot merge is neither a merge source nor a merge target, so the user cannot drop it into a group and cannot drop another window on it. A merge needs both windows to allow it. Allow on a window works under a workspace that denies merging.
<tb:Workspace allow-merge="false">
<tb:Window id="settings" title="Settings" allow-merge="Allow" />
</tb:Workspace>
workspace.AllowMerge = false;
// on the WindowDescriptor; CanMerge is the result
window.AllowMerge = WindowMergeOverride.Deny;
Code that groups windows, such as workspace.GroupAsTabs(windows), and tabs that are in a group already are not changed by this setting.
Snap and the snap keys
During a drag or a resize, an edge of the window snaps to the edge of a window next to it and to the edges of the workspace. Three keys change a drag. Each key is a setting on the workspace, and None turns the key off.
| Key | Attribute | Property | Effect |
|---|---|---|---|
| Shift | no-merge-modifier |
NoMergeModifier |
No merge and no drop into a tab group or a dock zone. |
| Alt | no-snap-modifier |
NoSnapModifier |
No snap: the window follows the pointer. It stays in the workspace. |
| Ctrl | align-snap-modifier |
AlignSnapModifier |
The window also snaps to the edge lines of windows that are far away, so two windows that do not touch can be in one line, horizontal or vertical. |
- The keys work together: Shift with Alt gives a drag with no merge and no snap.
- Alt wins over Ctrl.
- Each key can be
Shift,Control,AltorNone. Give each function a different key.
<tb:Workspace no-snap-modifier="Control" align-snap-modifier="None" />
// the snap is always on
workspace.NoSnapModifier = EventModifiers.None;
workspace.AlignSnapModifier = EventModifiers.Shift;
To turn the snap off for all drags and resizes, set snap to false. The windows then follow the pointer and stay in the workspace, as with the no-snap key. The RetroPC example does this for its desktop.
<tb:Workspace snap="false" />
Tab attention, badge and color
A window in a tab group can ask for the attention of the user. Its tab flashes, shows a badge, or has a look of its own.
var chat = workspace.GetWindow("chat");
// the tab flashes and shows the badge "3"
chat.RequestAttention("3");
chat.TabBadgeTone = BadgeTone.Error; // a red badge
chat.TabClass = "tab--boss"; // a USS class on the tab
chat.TabBadge = ""; // removes the badge
Member of WindowDescriptor |
Description |
|---|---|
NeedsAttention |
True makes the tab flash. The selection of the tab sets it to false. |
RequestAttention(badge) |
Sets NeedsAttention. A text also sets TabBadge. |
TabBadge |
A short text on the tab, such as a count. An empty text removes the badge. |
TabBadgeTone |
The color of the badge: Neutral, Accent (default), Success, Warning or Error. |
TabClass |
A USS class on the tab. |
AttentionChanged |
Fired after one of these members changes. |
- The selected tab does not flash, because the user already looks at it. A window without a tab does not flash.
- The badge stays when the user selects the tab. Remove it when the user has read the content, for example in
FocusChanged. - The flash color is
--tb-tab-attention-color(default--tb-color-warning), and the text during the flash is--tb-tab-attention-text. Set them in the rule of yourTabClass.
.tab--boss {
--tb-tab-attention-color: var(--tb-color-danger);
border-top-color: var(--tb-color-danger);
}
| Class | Element |
|---|---|
tb-tab |
A tab. tb-tab--active is the selected tab, tb-tab--pinned a pinned tab. |
tb-attention |
A tab while it flashes. tb-attention--on goes on and off. |
tb-tab-badge |
The badge. It is a Badge, so the tb-badge classes apply. |
AttentionFlash.Set(element, true) in UIToolbox gives the same two classes to an element of your own, such as a button that waits for a click. AttentionFlash.IntervalMs is the time of each half of a flash (default 500).
Dock zones
A dock zone is a persistent tab group at an edge of the workspace. Declare it in UXML:
<tb:Workspace>
<tb:DockZone position="left" size="250" />
<tb:DockZone position="right" size="300" />
</tb:Workspace>
| Attribute | Default | Meaning |
|---|---|---|
position |
left |
A DockSide: left, right, top or bottom. |
size |
200 | Width (left, right) or height (top, bottom) in pixels. |
dock-enabled |
true | If false, no dock zone is created. |
In UI Builder, a dock zone draws an empty dock at its edge. It creates the dock window only in Play mode.
A dock zone has the id Dock_{position}. It uses DockPanelTemplate.uxml. It cannot be moved, focused or resized, and it stays open when it is empty. The arrange and tile methods do not move it. When the workspace changes its size, or a toolbar changes its height, the dock stays along its edge with the full height or width of the free area. A new window with automatic placement opens between the docks.
Start a window docked
A window inside a dock zone opens at start as a tab of that dock, whatever its initial-window-state. In the UI Builder, drop the Window on the DockZone row in the Hierarchy. The canvas shows the window inside the dock.
<tb:Workspace>
<tb:DockZone position="left">
<tb:Window id="Map" title="Map" />
</tb:DockZone>
</tb:Workspace>
From code, workspace.DockWindow("Map", DockSide.Left) puts a window in a dock. A closed window opens there, and a window in another group or dock moves. It returns false when the workspace has no window with the id or no dock zone at the edge.
The user drags the tab out of the dock to make a floating window, and drops a window on the dock to dock it again.
A workspace inside a window
A Workspace can be inside the content of a window, for example to show a tab group in a preview or a small desktop in a game screen. A Window registers with the nearest workspace above it, so the windows inside belong to the inner workspace: get them with its GetWindow, and group them with its GroupAsTabs. They move, merge and tear off inside the inner workspace.
<tb:Window id="tabsControl" title="Tabs">
<tb:Workspace name="chatWorkspace" background-opacity="0"
keyboard-shortcuts="false" remember-window-states="false">
<tb:Window id="chatGuild" title="Guild" width="320" height="280" />
<tb:Window id="chatParty" title="Party" width="320" height="280" />
</tb:Workspace>
</tb:Window>
var chats = content.Q<Workspace>("chatWorkspace");
chats.GroupAsTabs(
new[] { chats.GetWindow("chatGuild"),
chats.GetWindow("chatParty") });
keyboard-shortcuts="false"on the inner workspace leaves the window keys to the outer one, so a key runs one command.background-opacity="0"shows the window content behind the inner windows.remember-window-states="false", or alayout-nameof its own, keeps the inner layout apart from the saved layout of the outer workspace.- The inner workspace shows its own tooltips. Give it no
WorkspaceToolbar, so the header of the screen stays in the outer workspace.