Buttons and built-in controls
Unity's own controls take the theme in a workspace: Button, Toggle, RadioButtonGroup, Slider, MinMaxSlider, TextField, DropdownField, Foldout, ProgressBar, ToggleButtonGroup and GroupBox. This page lists the classes that you add to a Button or a GroupBox, and the built-in controls that have their own rules. The ButtonsDemo and Styles example scenes show them in a workspace.
The classes are USS classes, so they work in UXML and in code. ButtonStyle has a constant for each class.
Button variants
A Button with no class has the surface color. A variant class changes its meaning:
<ui:Button text="Default" />
<ui:Button text="Save" class="tb-button--primary" />
<ui:Button text="Delete" class="tb-button--danger" />
<ui:Button text="Cancel" class="tb-button--outline" />
<ui:Button text="More" class="tb-button--ghost" />
<ui:Button text="Read the terms" class="tb-button--link" />
save.AddToClassList(ButtonStyle.PRIMARY_CLASS);
| Class | Constant | Look |
|---|---|---|
tb-button--primary |
ButtonStyle.PRIMARY_CLASS |
The main action: --tb-color-accent with --tb-color-accent-text. |
tb-button--danger |
ButtonStyle.DANGER_CLASS |
An action that deletes or loses something: --tb-color-danger with --tb-color-danger-text. |
tb-button--outline |
ButtonStyle.OUTLINE_CLASS |
No fill, a border in --tb-color-border. |
tb-button--ghost |
ButtonStyle.GHOST_CLASS |
No fill and no border. The fill shows under the pointer. |
tb-button--link |
ButtonStyle.LINK_CLASS |
Text in --tb-color-accent, no fill and no border. |
- Under the pointer, a primary or danger button becomes a little transparent. An outline or ghost button gets
--tb-color-surface-hover. A link gets--tb-color-text. - The focused button has a border:
--tb-color-texton a primary or danger button, and--tb-color-accenton the others. - A disabled primary or danger button keeps its color at half opacity. The others get
--tb-color-text-disabled. - Use one variant class on a button. Use one primary button in a dialog or a form.
Button sizes
<ui:Button text="Small" class="tb-button--sm" />
<ui:Button text="Default" />
<ui:Button text="Large" class="tb-button--lg tb-button--primary" />
<ui:Button text="+" class="tb-button--icon" />
<ui:Button text="+" class="tb-button--icon tb-button--lg" />
| Class | Constant | Look |
|---|---|---|
tb-button--sm |
ButtonStyle.SMALL_CLASS |
At least 18 px high, with --tb-font-size-sm. |
tb-button--lg |
ButtonStyle.LARGE_CLASS |
At least 44 px high, with --tb-font-size-lg. |
tb-button--icon |
ButtonStyle.ICON_CLASS |
A square of 24 px for one icon or one character. With tb-button--sm it is 18 px, and with tb-button--lg it is 32 px. |
A size class works with each variant class, and on a ToggleButton. For a picture, set iconImage of the button and leave the text empty.
Loading state
ButtonStyle.SetLoading shows a button as busy. The button is disabled and shows a spinner in front of its text:
ButtonStyle.SetLoading(save, true);
await SaveAsync();
ButtonStyle.SetLoading(save, false);
| Member | Description |
|---|---|
ButtonStyle.SetLoading(button, loading) |
True disables the button and shows the spinner. False enables it and takes the spinner away. |
ButtonStyle.IsLoading(button) |
True while the button shows the spinner. |
| Class | Element |
|---|---|
tb-button--loading |
On the button while it loads. |
tb-button__spinner |
The spinner, a 12 px ProgressRing with no fixed value. It has the text color of the variant. |
tb-button__text |
The text of the button while it loads. |
- The end of the loading state enables the button. If the button was disabled for another reason, disable it again.
- Do not change
textwhile the button loads. Change it afterSetLoading(button, false).
Button set
A container with the class tb-button-set joins its buttons in one frame. The frame has the border and the round corners, and a line shows between two buttons:
<ui:VisualElement class="tb-button-set">
<ui:Button text="Left" />
<ui:Button text="Center" />
<ui:Button text="Right" />
</ui:VisualElement>
<ui:VisualElement class="tb-button-set tb-button-set--vertical">
<ui:Button text="Top" />
<ui:Button text="Bottom" />
</ui:VisualElement>
| Class | Constant | Element |
|---|---|---|
tb-button-set |
ButtonStyle.SET_CLASS |
The container. Its buttons are in a row. |
tb-button-set--vertical |
ButtonStyle.SET_VERTICAL_CLASS |
Also on the container: the buttons are in a column. |
- The set has the margin and the height of one button, so it lines up with the buttons of its row.
- The set is as wide as its buttons. Put only buttons in it:
Button, ToggleButton or a button with a variant class. - The focused button shows its border in the set.
- A SplitButton is a button set with a main part and an arrow.
- The class
tb-button-groupis not a button set. It is the row of the window buttons in a title bar.
ToggleButtonGroup
Unity's ToggleButtonGroup shows a row of buttons where one or more are on. In a workspace, the button that is on has the accent color:
<ui:ToggleButtonGroup label="View" name="view">
<ui:Button text="List" />
<ui:Button text="Icons" />
<ui:Button text="Details" />
</ui:ToggleButtonGroup>
var view = root.Q<ToggleButtonGroup>("view");
view.RegisterValueChangedCallback(evt => ShowList(evt.newValue[0]));
| Unity class | Look in a workspace |
|---|---|
unity-button-group__button |
A button of the group: --tb-color-surface-alt, and --tb-color-surface-hover under the pointer. |
unity-button-group__button:checked |
A button that is on: --tb-color-accent with --tb-color-accent-text. |
unity-toggle-button-group__empty-label |
The text of a group with no buttons: --tb-color-text-muted. |
For one button that is on or off, use a ToggleButton.
MinMaxSlider
Unity's MinMaxSlider picks a range with two thumbs. In a workspace, the track and the thumbs match the Slider, and the range between the thumbs has the accent color:
<ui:MinMaxSlider label="Price" low-limit="0" high-limit="100" min-value="20" max-value="60" />
| Unity class | Look in a workspace |
|---|---|
unity-min-max-slider__tracker |
The track: --tb-color-surface-alt with a border in --tb-color-border. The border is --tb-color-accent while the slider has the focus from a key or a gamepad. |
unity-min-max-slider__dragger |
The range between the thumbs: --tb-color-accent. |
unity-min-max-slider__min-thumb, __max-thumb |
The thumbs: --tb-color-border, and --tb-color-surface-hover under the pointer. |
GroupBox
Add the class tb-group-box to a Unity GroupBox for a border with the title on its top line:
<ui:GroupBox text="Audio" class="tb-group-box">
<ui:Slider label="Music" low-value="0" high-value="100" />
<ui:Slider label="Effects" low-value="0" high-value="100" />
</ui:GroupBox>
| Class | Look |
|---|---|
tb-group-box |
A --tb-color-border border with --tb-radius-md corners, and a margin on top for the title. |
tb-group-box > .unity-group-box__label |
The title, bold, on the top line. Its background is --tb-color-surface, the color of a window, so the line stops under the title. |
On a panel with another background, give the title the same background:
.my-panel .tb-group-box > .unity-group-box__label { background-color: var(--tb-color-surface-alt); }
For a group of form fields with the title inside the border, use the class tb-field-set of FormField.
Change the look
Write the rule with .unity-button in front of the class, so it wins over the rule of the control library. Put the sheet after the theme sheet.
/* Round primary buttons */
.unity-button.tb-button--primary { border-radius: 12px; }
/* A wider large button */
.unity-button.tb-button--lg { padding-left: 24px; padding-right: 24px; }
/* The range of a MinMaxSlider in the success color */
.tb-workspace .unity-min-max-slider__dragger { background-color: var(--tb-color-success); }
For the rules of the other Unity controls, see Unity controls in the workspace.