UI Toolbox logoUI Toolbox

SplitButton

A SplitButton is a button with a main action and an arrow that opens a list of more actions, such as "Save" with "Save as" and "Save all".

A Save split button with its arrow

<tb:SplitButton name="save" text="Save" choices="Save as,Save all,Export" />
var save = root.Q<SplitButton>("save");
save.Clicked += SaveFile;
save.ItemPicked += item =>
{
    if (item.Text == "Save as") SaveFileAs();
};

For an icon, a detail text, a group or a disabled action, set Items:

save.Items = new List<ChoiceItem>
{
    new ChoiceItem("Save as", "Ctrl+Shift+S"),
    new ChoiceItem("Save all"),
    new ChoiceItem("Export", enabled: false),
};
Member Description
Text (text) The text of the main part.
Choices (choices) The actions of the list, as text. Setting it replaces Items.
Items The actions of the list, as choice items.
Clicked Raised by a click or a submit on the main part.
ItemPicked Raised with the item that the user picked in the list.
Open(), Close(), Toggle(), IsOpen Shows the list under the button, hides it, shows or hides it, and tells if it shows.

Tips:

Styling

Class Element
tb-split-button The control. It also has tb-button-set, which joins the two parts in one frame.
tb-split-button__main The main part, a Button.
tb-split-button__arrow The arrow, a Button. It is at least 24 px wide. The control is as high as a Button and lines up with the buttons of its row.
tb-split-button--open On the control while the list shows. The arrow gets --tb-color-surface-hover.
tb-split-button__popup The list, with the tb-choice-list classes. It is at least 140 px wide.

To make the list as wide as a long action text needs, and the arrow wider:

.tb-split-button__popup { min-width: 220px; }
.tb-split-button > .tb-split-button__arrow { padding-left: 10px; padding-right: 10px; }