Class SplitButton
One bordered control in two parts, [main | caret]. The main part is a button, or a toggle
when the caller drives selected; the caret opens that control's options.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class SplitButton : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, ISizeableElement, ISelectableElement, IPressable
Remarks
The two parts are separate press targets inside one rim, so a click on the main part runs the
action and a click on the caret only offers the alternatives. The caret is not wired to anything
on its own: build a Popover or a menu against caretElement from
caretClicked, and the caret carries is-open for as long as it is showing.
The chrome is the secondary Button's, so a row of plain buttons and split buttons reads as one row. It is one control with an options caret rather than a set of choices, so it takes no group or selector role: ActionGroup is the element for a segmented selector.
Examples
A split button whose caret opens a menu of the other things it could do.
<UXML xmlns:ui="Unity.AppUI.UI">
<ui:SplitButton label="Play" icon="play" caret-tooltip="Play options" />
</UXML>
splitButton.clicked += Play;
splitButton.caretClicked += () => ShowPlayOptions(splitButton.caretElement);
Constructors
SplitButton()
Initializes a new instance of the SplitButton class.
Declaration
public SplitButton()
SplitButton(Action)
Initializes a new instance of the SplitButton class, with the action its main part runs when clicked.
Declaration
public SplitButton(Action clickEvent)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | clickEvent | The action triggered by the main part. |
Fields
caretIconUssClassName
The styling class of the glyph inside the SplitButton's caret part.
Declaration
public const string caretIconUssClassName = "appui-split-button__caret-icon"
Field Value
| Type | Description |
|---|---|
| string |
caretUssClassName
The styling class of the SplitButton's caret part.
Declaration
public const string caretUssClassName = "appui-split-button__caret"
Field Value
| Type | Description |
|---|---|
| string |
iconAndLabelUssClassName
The SplitButton styling class applied when its main part carries both an icon and a label.
Declaration
public const string iconAndLabelUssClassName = "appui-split-button--icon-and-label"
Field Value
| Type | Description |
|---|---|
| string |
iconOnlyUssClassName
The SplitButton styling class applied when its main part carries an icon and no label.
Declaration
public const string iconOnlyUssClassName = "appui-split-button--icon-only"
Field Value
| Type | Description |
|---|---|
| string |
iconUssClassName
The styling class of the leading icon inside the SplitButton's main part.
Declaration
public const string iconUssClassName = "appui-split-button__icon"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The styling class of the label inside the SplitButton's main part.
Declaration
public const string labelUssClassName = "appui-split-button__label"
Field Value
| Type | Description |
|---|---|
| string |
mainUssClassName
The styling class of the SplitButton's main part.
Declaration
public const string mainUssClassName = "appui-split-button__main"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The SplitButton size styling class.
Declaration
public const string sizeUssClassName = "appui-split-button--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The SplitButton main styling class.
Declaration
public const string ussClassName = "appui-split-button"
Field Value
| Type | Description |
|---|---|
| string |
Properties
caretClickable
The Pressable manipulator of the caret part.
Declaration
[CreateProperty]
public Pressable caretClickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
caretElement
The caret part of the SplitButton. This is the element to anchor a menu or a Popover to.
Declaration
public VisualElement caretElement { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
caretIconElement
The glyph element inside the caret part, for a caller that wants a different glyph.
Declaration
public Icon caretIconElement { get; }
Property Value
| Type | Description |
|---|---|
| Icon |
caretTooltip
The tooltip of the caret part. The caret has no visible text, so this is what says what its options are for.
Declaration
[CreateProperty]
[UxmlAttribute]
public string caretTooltip { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
clickable
The Pressable manipulator of the main part.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
icon
The name of the leading icon of the SplitButton's main part. Null or empty hides it.
Declaration
[CreateProperty]
[UxmlAttribute]
public string icon { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
iconElement
The leading icon element of the SplitButton's main part.
Declaration
public Icon iconElement { get; }
Property Value
| Type | Description |
|---|---|
| Icon |
label
The label of the SplitButton's main part. Null or empty leaves an icon-only main part.
Declaration
[CreateProperty]
[UxmlAttribute]
public string label { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
labelElement
The label element of the SplitButton's main part.
Declaration
public LocalizedTextElement labelElement { get; }
Property Value
| Type | Description |
|---|---|
| LocalizedTextElement |
mainElement
The main part of the SplitButton. Exposed so a caller can set an accessible tooltip or a USS class of its own on the part that carries the action.
Declaration
public VisualElement mainElement { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
selected
The selected state of the SplitButton's main part, which is what makes the main part read as a toggle rather than a plain button. The control does not flip it on its own: set it from clicked, so the state stays the caller's.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool selected { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The size of the SplitButton. Both parts take their height from the control-sizing alias for this step, so a split button lines up with any other control of the same size.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
SetSelectedWithoutNotify(bool)
Sets the selected state without sending an event through the visual tree.
Declaration
public void SetSelectedWithoutNotify(bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | newValue | The new selected state. |
Events
caretClicked
Event triggered when the caret part has been clicked: the caller's cue to show the options.
Declaration
public event Action caretClicked
Event Type
| Type | Description |
|---|---|
| Action |
clicked
Event triggered when the main part has been clicked.
Declaration
public event Action clicked
Event Type
| Type | Description |
|---|---|
| Action |