Step 1 - Create a state manager to control the application state¶
In this step of the tutorial you create a state manager to control toggle buttons that switch on and off the air conditioning indicators which display the body, legs, and shield. You create state groups and states that set when the indicators are visible. You also create a property type which you use to control the air conditioning level indicators.
Assets for the tutorial¶
The <KanziWorkspace>/Tutorials/State managers/Completed directory contains the completed Kanzi Studio project of this tutorial.
The starting point of this tutorial is the State managers.kzproj Kanzi Studio project stored in the <KanziWorkspace>/Tutorials/State managers/Start directory. The project contains the nodes you need to complete this tutorial:
A Toggle Button 2D node named Legs contains the image for the indicator which displays the air conditioning on the legs.
A Toggle Button 2D node named Body contains the image for the indicator which displays the air conditioning on the body.
A Toggle Button 2D node named Shield contains the image for the indicator which displays the air conditioning on the windshield.
A Stack Layout 2D node named AirCondition level contains the background image of the application user interface and an image node which contains:
A Button 2D node for each air conditioning level indicator named Level 1, Level 2, Level 3, and Level 4.
Each Button 2D node contains the image for the level indicator which the button displays.
Create a state manager for the air conditioning states¶
You can use state managers to create different states in your application. For example, you can define the appearance and behavior of a button during different states, such as how the button reacts when a user presses the button.
In this section you create a state manager and a state group to control the state of the air conditioning indicators in the application. You use the state manager to set when the image in each toggle button is visible.
To create a state manager:
In Kanzi Studio open the
State managers.kzprojproject stored in the<KanziWorkspace>/Tutorials/State managers/Startdirectory.In the Library press Alt and right-click State Managers, select State Manager to create a state manager, and name it AC Controls.
In the Library > State Managers > AC Controls select the State Group, press F2 and rename it to Indicators, and rename the two states to On and Off.
State groups contain states, define controller properties, and transitions between states in a state group. You use the Indicators state group to set when the body, legs, and shield indicator images are visible.
In the Library > State Managers > AC Controls select the Indicators state group and in the Properties set:
Controller Property to Toggle State (ButtonConcept.ToggleState)
The state manager uses the Controller Property to set which state in that state group is active. Here you use the Toggle State property to transition to a state based on the value of that property.
The AC Controls state manager and Indicators state group are displayed red until you set the Toggle State for each state.
Initial State to AC Controls/Indicators/Off.
The initial state is the state that the application uses when it is first started. You set the air conditioning off until the user clicks one of the indicator buttons.
In the Library > State Managers > AC Controls > Indicators select the On state and in the Properties set the Toggle State property to 1.
The Toggle State property is set to 0 by default in the Off state.
In the On state press Alt and right-click, select State Object to create a State Object, name it IndicatorVisible, and in the Properties:
Set the Target Object Path to ./Image
Add and enable the Node > Visible property.
State objects define the properties of nodes for a specific state. In the Node Tree the Body, Legs, and Shield nodes each contain an image node called Image. The Target Object Path points to all of these images and sets them visible.
Repeat the previous step for the Off state, but name the state object IndicatorInvisible, and make sure the Visible property is disabled.
In the Node Tree select the Legs, Body, and Shield nodes, in the Properties add the Resources > State Manager property, and set it to AC Controls.
By setting the value of the State Manager property you set a state manager to control the selected node and its subtree. In this case you set the AC Controls state manager to control the indicator buttons that set the air conditioning state.