Class Toggle
A control that allows users to switch between two states: on (checked) and off (unchecked).
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Toggle : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<bool>, IValidatableElement<bool>, INotifyValueChanged<bool>, IPressable
Remarks
The Toggle component is a user interface element that allows users to switch between two states. It's commonly used for enabling or disabling options, features, or settings within an application.
Toggles are best used when you need to:
- Present a binary choice, such as on/off or true/false
- Immediately apply state changes
- Show the current state clearly through visual feedback
The component consists of a box containing a checkmark that indicates the selected state, and an optional label that describes the toggle's purpose.
When clicked or activated via keyboard, the toggle switches its state and triggers a change event that can be handled by the application.
Constructors
Toggle()
Default constructor.
Declaration
public Toggle()
Fields
boxUssClassName
The Toggle box styling class.
Declaration
public const string boxUssClassName = "appui-toggle__box"
Field Value
| Type | Description |
|---|---|
| string |
checkmarkContainerUssClassName
The Toggle checkmark container styling class.
Declaration
public const string checkmarkContainerUssClassName = "appui-toggle__checkmarkcontainer"
Field Value
| Type | Description |
|---|---|
| string |
checkmarkUssClassName
The Toggle checkmark styling class.
Declaration
public const string checkmarkUssClassName = "appui-toggle__checkmark"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The Toggle label styling class.
Declaration
public const string labelUssClassName = "appui-toggle__label"
Field Value
| Type | Description |
|---|---|
| string |
paddedBoxUssClassName
The Toggle box padded styling class.
Declaration
public const string paddedBoxUssClassName = "appui-toggle__boxpadded"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The Toggle size styling class.
Declaration
public const string sizeUssClassName = "appui-toggle--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Toggle main styling class.
Declaration
public const string ussClassName = "appui-toggle"
Field Value
| Type | Description |
|---|---|
| string |
Properties
clickable
Clickable Manipulator for this Toggle.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
invalid
The invalid state of the Toggle.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
label
The Toggle label.
Declaration
[CreateProperty]
[UxmlAttribute]
public string label { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
validateValue
The validation function for the Toggle.
Declaration
[CreateProperty]
public Func<bool, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<bool, bool> |
value
The Toggle value.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool value { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
SetValueWithoutNotify(bool)
Set the Toggle value without notifying the change.
Declaration
public void SetValueWithoutNotify(bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | newValue | The new value. |