Defines an attribute for an interface element. See also the Attributes Guide section.
void IupSetAttribute(Ihandle *ih, const char *name, const char *value); [in C]
iup.SetAttribute(ih: iulua_tag, name: string, value: string) [in Lua]
ih: Identifier of the interface element. If
NULL will set in the global environment.
name: name of the attribute.
value: value of the attribute. If NULL (nil in Lua), the default value
will be used.
See the Attributes Guide for more details.
When an attribute is set it is first processed by the element class implementation, if allowed or ignored by the class implementation then it is stored in the internal hash table. If it is an inheritable attribute then the attribute is propagated to the element children class implementation, their hash table remains untouched.
If the value is NULL, the attribute will be removed from the hash table and the default value will be used during the element class implementation.
Since IUP 3.0, if the attribute is marked non inheritable at a child then its propagation can be ignored by the child. This depends on the implementation of the child class. When that happen set the attribute directly at the child.
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.
struct myData* mydata = malloc(sizeof(struct myData));
IupSetAttribute(dlg, "MYDATA", (char*)mydata) // correct (unknown attributes will be stored as pointers)
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)
Defines a radio’s initial value.
Ihandle *portrait = IupToggle("Portrait" , NULL);
Ihandle *landscape = IupToggle("landscape" , NULL);
Ihandle *box = IupVbox(portrait, IupFill(),landscape, NULL);
Ihandle *mode = IupRadio(box);
IupSetHandle("landscape", landscape); /* associates a name to initialize the radio */
IupSetAttribute(mode, "VALUE", "landscape"); /* defines the radio’s initial value */
Other usages:
1. IupSetAttribute(text, "VALUE", "Hello!");
2. IupSetAttribute(indicator, "VALUE", "ON");
3. struct
{
int x;
int y;
} myData;
IupSetAttribute(text, "myData", (char*)&myData); // correct, BUT myData should be a global variable.
IupGetAttribute, IupSetAttributes, IupGetAttributes, IupStoreAttribute