Contents
TwDefineEnum (function)
DescriptionThis function creates a new TwType corresponding to a C/C++ enum. Thus it could be used with TwAddVar* functions to control variables of type enum. ParametersnameSpecify a name for the enum type (must be unique). enumValuesAn array of structures of type TwEnumVal containing integer values and their associated labels (pointers to zero terminated strings) corresponding to the values. nbValuesNumber of elements of the enumValues array. Return values
Exampletypedef enum { SUMMER, FALL, WINTER, SPRING } Seasons; Seasons season = WINTER; TwEnumVal seasonsEV[] = { {SUMMER, "Summer"}, {FALL, "Fall"}, {WINTER, "Winter"}, {SPRING, "Spring"} }; TwType seasonType; // ... // Defining season enum type seasonType = TwDefineEnum("SeasonType", seasonsEV, 4); // Adding season to bar TwAddVarRW(bar, "Season", seasonType, &season, NULL); Note that enum values definition can also be done by TwDefineEnumFromString, or through the enum parameter of the def string of TwAddVar* like this: typedef enum { SUMMER, FALL, WINTER, SPRING } Seasons; Seasons season = WINTER; TwType seasonType; // ... // Defining an empty season enum type seasonType = TwDefineEnum("SeasonType", NULL, 0); // Adding season to bar and defining seasonType enum values TwAddVarRW(bar, "Season", seasonType, &season, " enum='0 {Summer}, 1 {Fall}, 2 {Winter}, 3 {Spring}' "); // This will affect all variables that are of type seasonType. See also |