ToggleButton
A ToggleButton is a Button that stays pressed, such as "Bold" or "Mute". A click turns value on, and the next click turns it off.

<tb:ToggleButton text="Bold" value="true" />
<tb:ToggleButton text="Mute" name="mute" />
var mute = root.Q<ToggleButton>("mute");
mute.RegisterValueChangedCallback<bool>(evt => AudioListener.pause = evt.newValue);
| Member | Description |
|---|---|
value (value) |
True while the button is pressed. A change sends a ChangeEvent<bool>. |
SetValueWithoutNotify(value) |
Sets the value and sends no event. |
text, iconImage, clicked |
From Button. clicked runs on each click, before the value changes. |
- A click, Enter, Space or the submit button of a gamepad on the focused button changes the value.
- A disabled button keeps its value and does not change.
- Write the type in
RegisterValueChangedCallback<bool>. AButtonalso has a text value, so the compiler cannot find the type itself.
Tips:
- Use a
ToggleButtonfor one option that is on or off and has an effect at once. For a setting with a label, use a Switch or aToggle. - For a set where one button is on, such as List, Icons and Details, use Unity's
ToggleButtonGroup. It takes the theme colors. See Buttons and built-in controls. - Put toggle buttons in a container with the class
tb-button-setto join them in one frame. - The size classes
tb-button--sm,tb-button--lgandtb-button--iconwork on a toggle button.
Styling
| Class | Element |
|---|---|
tb-toggle-button |
The button: --tb-color-surface-alt, with --tb-color-surface-hover under the pointer. The unity-button classes also apply. |
tb-toggle-button--pressed |
On the button while value is true: --tb-color-accent with --tb-color-accent-text. |
To show a pressed button with a line and no fill:
.unity-button.tb-toggle-button--pressed {
background-color: var(--tb-color-surface-alt);
color: var(--tb-color-text);
border-bottom-color: var(--tb-color-accent);
border-bottom-width: 2px;
}