Toggle#

class Toggle#

A control that is either checked or not. Added to a Canvas or a Panel.

Note

On its own a toggle is a check box. Put several of them in the same ToggleGroup and they become radio buttons, as only one toggle in a group can be checked at a time.

RectTransform rect_transform()#

The rect transform for the UI object.

LayoutElement layout_element()#

How much space the UI object asks a layout for.

Note

Only has an effect when the object is in a panel that has a layout. A canvas is not inside a layout and does not have one.

bool visible()#
void set_visible(bool value)#

Whether the UI object is visible.

Note

This is the object’s own setting, which is what it was last set to. An object is only drawn when everything it is inside is visible as well, so an interface can be built with its parts visible, inside a panel that is not, and shown all at once by making that panel visible.

Text text()#

The text for the toggle.

bool checked()#
void set_checked(bool value)#

Whether the toggle is checked.

Note

Checking a toggle that belongs to a ToggleGroup unchecks the rest of that group, whether or not it is on the screen.

std::optional<ToggleGroup> group()#
void set_group(std::optional<ToggleGroup> value)#

The group that the toggle belongs to, or NULL if it does not belong to one.

Note

Only one toggle in a group can be checked at a time, so a group turns a set of toggles into radio buttons. A group does not have to contain the toggles, so they can be grouped independently of how they are laid out.

bool changed()#
void set_changed(bool value)#

Whether the toggle has been changed.

Note

This property is set to true when the user changes the toggle, and not when a client checks or unchecks it. A client script should reset the property to false in order to detect subsequent changes.

bool interactable()#
void set_interactable(bool value)#

Whether the control responds to the user.

Note

A control that is not interactable is drawn grayed out and ignores the user, but is still visible. Set its visibility to false to hide it instead.

StdLib::ColorRGBA color()#
void set_color(StdLib::ColorRGBA value)#

The color the control is tinted with. White, the default, leaves the control drawn as the skin has it.

Note

The tint multiplies the sprite the control is drawn with, in every state, so a control can show a state of its own, an engaged autopilot for instance, by color. It is applied to the part of the control that responds to the user: the body of a button, dropdown or input field, the box of a toggle, and the handle of a slider. A control’s label is tinted through the color of its text.

std::string tooltip()#
void set_tooltip(std::string value)#

A short piece of text shown beside the pointer while it rests on the control. Empty, the default, shows nothing.

void remove()#

Remove the UI object.