Use the Toggle Button Group nodes to allow users to select only one option from a set of options that are mutually exclusive. Toggle buttons in a toggle button group behave like radio buttons, where only one toggle button can be active at a time. Use Toggle Button Group 3D to group 3D toggle buttons in 3D space, and Toggle Button Group 2D to group 2D toggle buttons in 2D space.
A toggle button group is a node that can contain Toggle Button nodes and manages their states, but does not provide a visual shape.
When a Toggle Button node in a Toggle Button Group has focus, it receives click input from the keyboard keys Space, Enter, and Enter on the numeric pad by default. Use scripting functions to get and set the node that currently has focus in the project. See Scripting reference and Using triggers.
To create a toggle button group:
In the Preview when you click the Toggle Button nodes in the Toggle Button Group node, the Toggle Button Group node toggles the states in Toggle Button nodes.
You can set off a trigger when the user toggles the state of a Toggle Button in a Toggle Button Group. For example, you can execute a script which sets focus to a user interface element based on which a Toggle Button was toggled.
To set off a trigger when a Toggle Button in a Toggle Button Group is toggled:
Now when you change the toggle state of any of the buttons in the Toggle Button Group, Kanzi prints to the Log window the message you entered as the value of the Log Message property.
To open the Log window, in the main menu select > Log.
To set the appearance of 2D nodes:
To create a Toggle Button Group 3D node with three toggle buttons:
// Create a Toggle Button Group 3D named Toggle button group and add it to the scene. ToggleButtonGroup3DSharedPtr toggleButtonGroup3D = ToggleButtonGroup3D::create(domain, "Toggle button group"); scene->addChild(toggleButtonGroup3D); // Create a Stack Layout 3D named Stack layout and add it to the Toggle button group. // This stack layout is used only for arranging the items in the Toggle button group. StackLayout3DSharedPtr stackLayout3D = StackLayout3D::create(domain, "Stack layout"); toggleButtonGroup3D->addChild(stackLayout3D); // Create three toggle buttons and add them to the Stack layout. ToggleButton3DSharedPtr buttons[3]; for (kzUint i = 0; i < 3; ++i) { buttons[i] = ToggleButton3D::create(domain, "Toggle button"); // Setting the Button Group Index property to -1, which tells the Toggle button group // to set the index of the toggle button. buttons[i]->setIndexInGroup(-1); stackLayout3D->addChild(buttons[i]); } // Print the index of the toggled button to show that the last button is toggled. std::cout << toggleButtonGroup3D->getCurrentButtonIndex() << endl; // Toggle the first toggle button. buttons[0]->setToggleState(1); // Print the index of the toggled button to show that the first button is toggled. std::cout << toggleButtonGroup3D->getCurrentButtonIndex() << endl;
For details, see the ToggleButtonGroup3D
class in the API reference.
To create a Toggle Button Group 2D node with three toggle buttons:
// Create a Toggle Button Group 2D named Toggle button group and add it to the scene. ToggleButtonGroup2DSharedPtr toggleButtonGroup2D = ToggleButtonGroup2D::create(domain, "Toggle button group"); viewportNode->addChild(toggleButtonGroup2D); // Create a Stack Layout 2D named Stack layout and add it to the Toggle button group. // This stack layout is used only for arranging the items in the Toggle button group. StackLayout2DSharedPtr stackLayout2D = StackLayout2D::create(domain, "Stack layout"); toggleButtonGroup2D->addChild(stackLayout2D); // Create three toggle buttons and add them to the Stack layout. ToggleButton2DSharedPtr buttons[3]; for (kzUint i = 0; i < 3; ++i) { buttons[i] = ToggleButton2D::create(domain, "toggle button"); // Setting the Button Group Index property to -1, which tells the Toggle button group // to set the index of the toggle button. buttons[i]->setIndexInGroup(-1); stackLayout2D->addChild(buttons[i]); } // Print the index of the toggled button to show that the last button is toggled. std::cout << toggleButtonGroup2D->getCurrentButtonIndex() << endl; // Toggle the first toggle button. buttons[0]->setToggleState(1); // Print the index of the toggled button to show that the first button is toggled. std::cout << toggleButtonGroup2D->getCurrentButtonIndex() << endl;
For details, see the ToggleButtonGroup2D
class in the API reference.
For lists of the available property types and messages for the Toggle Button Group nodes, see Toggle button group 2D and Toggle button group 3D.