IupSetAttribute
Defines an attribute for an interface element.
Parameters/Return
void IupSetAttribute(Ihandle *element, char *a, char *v); [in C] IupSetAttribute(element: iulua_tag, attribute: string, value: string) [in IupLua3] iup.SetAttribute(element: iulua_tag, attribute: string, value: string) [in IupLua5]
element: Identifier of the interface element.
a: name of the attribute.
v: value of the attribute. If it equals NULL (nil in Lua), the attribute will be removed from the element.
Notes
The value stored in the attribute is not duplicated. Therefore, you can store your private attributes, such as a structure with data to be used in a callback. When you want IUP to store an attribute by duplicating a string passed as a value, use function IupStoreAttribute. For further information on memory allocation by IupSetAttribute, see IupGetAttributes notes section.
A very common mistake when using IupSetAttribute is to use local string arrays to set attributes. For ex:
{ char value[30]; sprintf(value, "%d", i); IupSetAttribute(dlg, "BADEXAMPLE", value) // WRONG (value pointer will be internally stored, } // but its memory will be released at the end of this scope) // Use IupStoreAttribute in this case{ char *value = malloc(30); sprintf(value, "%d", i); IupSetAttribute(dlg, "EXAMPLE", value) // correct (but to avoid memory leaks you should free the pointer } after the dialog has been destroyed)IupSetAttribute(dlg, "VISIBLE", "YES") // correct (static values still exists after this scope)char attrib[30]; sprintf(attrib, "ITEM%d", i); IupSetAttribute(dlg, attrib, "Test") // correct (attribute names are always internally duplicated)struct myData* mydata = malloc(sizeof(struct myData)); IupSetAttribute(dlg, "MYDATA", (char*)mydata) // correct (unknown attributes will be stored as pointers)When an attribute is set it is always stored at the hash table. If the value is NULL, the attribute will be removed from the hash table. Then the driver or the custom control is updated. Finally the attribute is also updated for the children of the element in the driver if they do not have the attribute defined in their own hash table.
Example 1
Defines a radios initial value.
In C
Ihandle *portrait = IupToggle("Portrait" , "acao_portrait"); Ihandle *landscape = IupToggle("landscape" , "acao_landscape"); Ihandle *box = IupVbox(portrait, IupFill(),landscape, NULL); Ihandle *modo = IupRadio(box); IupSetHandle("landscape", landscape); /* associates a name to initialize the radio */ IupSetAttribute(modo, "VALUE", "landscape"); /* defines the radios initial value */
Example 2
Some usages:
In C
1. IupSetAttribute(texto, "VALUE", "Hello!");2. IupSetAttribute(indicador, "VALUE", "ON");3. struct { int x; int y; } myData; IupSetAttribute(texto, "myData", (char*)&myData);
See Also
IupGetAttribute, IupSetAttributes, IupGetAttributes, IupStoreAttribute