Behaviors
Last updated
Last updated
Behaviors can define requirements which are resuable across multiple components to standardize instance names and behaviors. If a component uses a behavior, then it is forced to include categories and instances according to the behavior definition.
Behaviors are used to define requirements for components, to simplify the creation of new components, and to reduce the chances of spelling and implementation mistakes.
C# programmers may find the concept of behaviors to be similar to interfaces in code. Behaviors define requirements for components, but they give components the flexibility to implement these requirements, just like interfaces define required properties and methods which classes can implement.
Behaviors are used to standardize state, category, and instance names. The most common usage of behaviors is with Gum Forms. Of course, behaviors can also be used to standardize names in your project for components which are not intended to be with Gum Forms.
To add a behavior:
Right-click on the Behaviors folder
Select Add Behavior
Enter the new behavior name. Often time the word Behavior is added at the end of the name, such as ButtonBehavior
New behaviors appear in the Project tab.
Once a behavior has been created, it can be given categories, states, and instances. Any component which uses this behavior is required to have the same categories and states.
The process of adding and removing states to behaviors is the same as adding and removing states in other elements. For more information, see the States page.
For example, the ButtonBehavior may have the following:
ButtonCategory (Category)
Enabled (State)
Disabled (State)
Focused (State)
Pushed (State)
A behavior can have as many categories and states as needed.
Once a behavior is added, it can be used in a component. To add a behavior to a component, drag+drop the behavior onto the component in the tree view.
Behaviors can also be added and removed on the component's Behaviors tab:
Select a component which should use the behavior
Click the Behaviors tab
Click the Edit button
Check the desired behaviors - a component may use multiple behaviors
Click OK
Notice that once a behavior is added to a component, the component automatically creates the matching categories and states.
These categories cannot be removed as long as the component uses the behavior.
As mentioned above, if a component uses a behavior, then the component is required to include all of the states and categories defined by the behavior. If a behavior is added to a component, then all states and categories in the behavior are automatically added to the component. Keep in mind that newly-added states do not automatically assign any values. The behavior only requires that the states exist but it does not decide which variables are assigned by the states. These required states can even be left to their default so they have no affect on the component.
Required states and categories cannot be removed or renamed. Required states cannot be moved to different categories.
If a new category or state is added to a behavior, all components which use the behavior also have the new category or state added.
If a state or category is removed from a behavior, Gum does not remove the state or category from components which implement the behavior. Behaviors only define what is required, but they do not prevent components from defining additional states and categories. Also, the states on components may still be needed even if the behavior is removed. Therefore, if you remove any states or categories from a behavior, you may need to manually remove the same states and categories from components which use the behavior if these are no longer needed.
Behaviors can include instances, resulting in required instances existing in components which use the behavior. Instances in behaviors only include two properties:
Name
Base Type
Instances in behaviors only require that instances in components have these two matching properties. All other properties can be set to any value.
To add an instance to a behavior, drag+drop a standard element or component onto the behavior in the Project tab.
An instance can have its Name changed, Base Type changed, or removed.
If a component is missing a behavior then the Error window provides information about the missing requirement.
At this time Gum does not automatically add required instances to components which need them. This may change in future versions of Gum. For now, instances must be manually added to resolve errors.