TwSetParam (function)

int TwSetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int inValueCount, const void *inValues)


This function modifies the value(s) of a bar or variable parameter. Parameters define the behavior of bars and vars and may be set by functions TwDefine or TwAddVar* using a definition string. TwSetParam is an alternative to these functions avoiding the conversion of the new parameter value into a definition string.



Bar identifier. If the parameter to modify is global, NULL may be used as identifier.


If the parameter is directly related to a bar, varName should be NULL.

Otherwise, varName is the name of the parameter’s variable (ie., the unique name used to create the variable).


Name of the parameter. This is one of the key words listed in the bar parameters page if the parameter is directly related to a bar, or listed in the var parameters page if the parameter is related to a variable.


Type of the data pointed by inValues. Should be one of the constants defined by TwParamValueType: TW_PARAM_INT32, TW_PARAM_FLOAT, TW_PARAM_DOUBLE or TW_PARAM_CSTRING.


Depending on the parameter, one or more values may be required to modify it. For instance, a state parameter requires one value while a rgb-color parameter requires 3 values.

If the parameter value is a string, inValueCount must be 1 (not the length of the string), and the string must be an array of chars terminated by a zero (ie., a C-style string).


Pointer to the new parameter value(s). If there is more than one value, the values must be stored consecutively as an array starting at the address pointed by inValues.


// set a variable 'step' parameter
float vstep = 0.1f;
TwSetParam(bar, "varname", "step", TW_PARAM_FLOAT, 1, &vstep);
// fold a group
int opened = 0;
TwSetParam(bar, "groupname", "opened", TW_PARAM_INT32, 1, &opened);
// set arrow color of a direction variable
int color[3] = { 255, 255, 128 };
TwSetParam(bar, "varname", "arrowcolor", TW_PARAM_INT32, 3, color);
// set a key shortcut
char keysc[] = "ALT+a";
TwSetParam(bar, "varname", "keyincr", TW_PARAM_CSTRING, 1, keysc);
// set a bar values width
int width = 160; // pixels
TwSetParam(bar, NULL, "valueswidth", TW_PARAM_INT32, 1, &width);
// set global icon alignment
char align[] = "horizontal";
TwSetParam(NULL, NULL, "iconalign", TW_PARAM_CSTRING, 1, align);

Return value

  • 0 if an error has occurred (call TwGetLastError to retrieve the error).
  • 1 otherwise.

See also