button widget

The button widget is very important in Blender. A majority of interface elements are buttons. Buttons can be (and frequently are) stored in ui blocks which are containers for buttons.

types

Buttons are used to implement widget functionality of many different widgets commonly found in GUI toolkits. For example Blender buttons are used as traditional push buttons, radio buttons, popup menus, check boxes, text/integer edit fields, etc. The problem with this is that it makes it difficult for a user to imagine what kind of functionality is implemented with a particular button. For example, the buttons in the picture below have quite different functionality but they look the same:

Their function must be inferred from subtle hints such as

implementation

definition

The definition of a Blender button structure can be found in the file interface.h. There is one button structure for all button types.

typedef struct uiBut
{
struct uiBut *next, *prev;
short type, pointype, bit, bitnr, retval, flag, strwidth;
short ofs, pos, pad;
uint paper;

char *str;
char strdata[UI_MAX_NAME_STR];
char drawstr[UI_MAX_DRAW_STR];

float x1, y1, x2, y2;

char *poin;
float min, max;
float a1, a2, rt[4];
float aspect;
void (*func)();
void (*butfunc)(struct uiBut *);
struct uiBlock *(*blockfunc)();
void (*embossfunc)(uiCol *, float, float, float, float, float, int);

uiLink *link;

char *tip, *lockstr;

uiCol *col;
void *font;
uiIconImage *icon;

short lock, win;
short iconxadd, iconx, icony;

} uiBut ;

From the structure definition, you can see that the button can be part of a linked list of buttons.

The button structure contains four function pointers:

The function pointers are set at button creation.

creation

The button is created with the uiDefBut routine declared in the file interface.h and defined in the file interface.c:

uiBut *uiDefBut(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip);

This routine creates a new uiBut structure and fills in a number of the structure fields.

Some of the parameters are somewhat cryptic. Here is a short description for each of them:

d;ld;l