DUIM provides three standard button gadget classes:
<push-button> Sometimes referred to as command button in Microsoft documentation.
<radio-button>Sometimes referred to as option button in Microsoft documentation.
<check-button>Sometimes referred to as check box in Microsoft documentation.
|
The chapters covering the task list manager application (chapters 2 to 6) introduced you to the <push-button> class. This is the default type of button (that is, creating an instance of <button> actually creates an instance of <push-button>).
make(<push-button>, label: "Hello");
Radio buttons let you choose one option out of a group of several. They are usually implemented in groups of several buttons (using the <radio-box> class), although they can also be created singly, as shown in Figure 7.1. For more information about creating groups of radio buttons, see Section 7.2.3.2 on page 94.
make(<radio-button>, label: "Hello");
Check buttons are buttons whose setting can be toggled on and off. Like radio buttons, they are often implemented in groups, although unlike radio buttons, they are frequently used individually. For more information about creating groups of check buttons, see Section 7.2.3.2 on page 94.
define variable *my-check-button*
:= make(<check-button>, label: "Hello"
value: #f);
Remember that you can use gadget-label to set or return the label for any button. As demonstrated in the examples above, it is also good practice to set the label when defining any button, using the label: init-keyword.
Radio and check buttons have a gadget-value of #t or #f, depending on whether or not the button is selected. For example:
gadget-value(*my-check-button*)
returns #f if the check button is not selected.
You can set the gadget-value with the := operator.
gadget-value(*my-check-button*) := #t;
Supplying a value for a push button is a useful way of sending information to your application. The value of a push button can be used by any callback defined on the push button.
You can make any push button the default option for the frame it is a part of using the default?: init-keyword when defining the button. By default, this is #f, but if specified as #t, the button is displayed on the screen with a heavier border, and any callback defined for the button is invoked by pressing the RETURN key on the keyboard, as well as by clicking the button itself.
define variable *my-default-button*
:= make(<push-button>,
label: "Click me or press Return",
default?: #t));
It is good practice to define a default button in most dialog boxes, so that the user can easily perform a default action. Generally, the OK or Yes button in a dialog box is the most acceptable default button, though for particularly destructive operations you should consider another choice.
Buttons are intrinsically "non-stretchy" objects. That is, the width of a button is computed from the length of its label, and the button will not automatically size itself according to the size of the sheet that it is a part of. You should use the max-width: init-keyword to make a button fill all the available space, by setting it to the constant $fill.
Thus, the button created by
make(<button>, label: "Red");
will only be as wide as the label it is given--"Red", in this case--but the button created by
make(<button>, label: "Red", max-width: $fill);
will have a width that is determined by the sheet that it is a child of and will still have the same minimum width, so it cannot be resized too small.