Buttons (XForms (Forms Library) - Version 1.2 (Rev. 4) A Graphical User Interface Toolkit for X)

Next: Sliders, Previous: Texts, Up: Part I Defining Forms [Contents][Index]

### 3.4 Buttons

A very important class of objects are buttons. Buttons are placed on the form such that the user can push them with the mouse. Different types of buttons exist: buttons that return to their normal position when the user releases the mouse, buttons that stay pushed until the user pushes them again and radio buttons that make other buttons be released. Adding a button to a form can be done using the following routine

    FL_OBJECT *fl_add_button(int type, FL_Coord x, FL_Coord y,
                             FL_Coord w, FL_Coord h,
                             const char *label);

`label` is the text placed inside (or next to) the button. `type` indicates the type of the button. The Forms Library at the moment supports a number of types of buttons. The most important ones are:

    FL_NORMAL_BUTTON
    FL_PUSH_BUTTON
    FL_TOUCH_BUTTON
    FL_RADIO_BUTTON

They all look the same on the screen but their functions are quite different. Each of these buttons get pushed down when the user presses the mouse on top of them. What actually happens when the user does so depends on the type of button.

A normal button returns to its normal position when the user releases the mouse button.

A push button remains pushed and is only released when the user pushes it again.

A touch button is like a normal button except that as long as the user keeps the mouse pressed it is returned to the application program (see Doing Interaction on the details of interaction).

A radio button is a push button with additional extra property: Whenever the user pushes a radio button, all other pushed radio buttons in the form (or at least in the group, see below) they belong to are released. In this way the user can make a choice among some mutually exclusive possibilities.

Whenever the user pushes a button and then releases the mouse, the interaction routine `fl_do_forms()` is interrupted and returns a pointer to the button that was pushed and released. If a callback routine is present for the object being pushed, this routine will be invoked. In either case, the application program knows that the button was pushed and can take action accordingly. In the first case, control will have to be returned to `fl_do_forms()` again after the appropriate action is performed; and in the latter, `fl_do_forms()` would never return. See Doing Interaction, for details on the interaction with forms.

Different types of buttons are used in all the example programs provided. The application program can also set a button to appear pushed or not without user action. This is of course only useful for push buttons and radio buttons. To set or reset a push or radio button use the routine

    void fl_set_button(FL_OBJECT *obj, int pushed);

`pushed` indicates whether the button should appear to be pushed (1) or released (0). Note that this does not invoke a callback routine bound to the button or results in the button getting returned to the program, i.e., only the visual appearance of the button is changed and what it returns when asked for its state (and, in the case of a radio button, possibly that of another radio button in the same group). To also get the callback invoked or the button returned to the program additonally call e.g., `fl_trigger_object()`.

To figure out whether a button appears as pushed or not use

    int fl_get_button(FL_OBJECT *obj);

See the program `pushbutton.c` for an example of the use of push buttons and setting and getting button information.

The color and label of buttons can again be changed using the routines in Changing Attributes.

There are other classes of buttons available that behave the same way as buttons but only look different.

Light buttons

  have a small "light" (colored area) in the button. Pushing the button switches the light on, and releasing the button switches it off. To add a light button use `fl_add_lightbutton()` with the same parameters as for normal buttons. The other routines are exactly the same as for normal buttons. The color of the light can be controlled with the routine `fl_set_object_color()`, see Changing Attributes.

Round buttons

  are buttons that are round. Use `fl_add_roundbutton()` to add a round button to a form.

Round3d buttons

  are buttons that are round and 3D-ish looking. Round and light buttons are nice as radio and push buttons.

Check buttons

  are buttons that have a small checkbox the user can push. To add a check button, use `fl_add_checkbutton()`. More stylish for a group of radio buttons.

Bitmap buttons

  are buttons that have a bitmap on top of the box. Use routine `fl_add_bitmapbutton()` to add a bitmap button to a form.

Pixmap buttons

  are buttons that have a pixmap on top of the box. Use routine `fl_add_pixmapbutton()` to add a pixmap button to a form.

Playing with different boxtypes, colors, etc., you can make many different types of buttons. See `buttonall.c` for some examples. Fig. 16.1 shows all buttons in their default states.

Next: Sliders, Previous: Texts, Up: Part I Defining Forms [Contents][Index]