Toggles are used to allow a user to make binary choices by selecting a box.
Toolbar toggles are toggles with button style applied to it and are used inside window toolbars.
IMGUI
A toggle is a simple on/off boolean control and its generic expression is a checkbox. However in certain conditions the control needs to be placed in a container as a toggle button.
Use a toggle when:
Use a toggle button when:
Toggles are displayed as checkboxes because they are the default display for a boolean (binary) choice between on and off.
A toggle should always show a checkmark for its checked state, a dash for its indeterminate (or mixed) state and be empty for its unchecked state.
A toggle consists of the box, an active glyph, and a label (or two labels where applicable). The “active” glyph indicates whether the choice is true or false, only appearing when the “true” condition is met or enabled.
Toggles should be visually consistent regardless of where they appear. They appear in many interfaces throughout the editor and can even be user-generated in areas of the interface like the Inspector. A consistent visual representation of toggles assures that the functionality works as expected.
Toggles can be enabled / disabled via their handle to give a wider area to interact with the element.
Toggles can be:
Toggle states can be:
Go to Window > UI Toolkit > Samples to view code samples in C# / USS / UXML.
IMGUI
Unity - Scripting API:
EditorGUILayout.Toggle