Open abstract instantiable class
The class of all button gadgets.
accelerator:false-or(<gesture>). Default value: #f.
mnemonic:false-or(<character>). Default value: #f.
duim-gadgets
duim-gadgets
The class of all button gadgets.
The accelerator: init-keyword is used to specify a keyboard accelerator for the button. This is a key press that gives the user a method for activating the button using a short key sequence rather than by clicking the button itself. Keyboard accelerators usually combine the CONTROL and possibly SHIFT keys with an alphanumeric character.
When choosing accelerators, you should be aware of style guidelines that might be applicable for the operating system you are developing for. For example, a common accelerator for the command File > Open in Windows is CTRL+O.
Keyboard accelerators are mostly used in menu buttons, though they can be applied to other forms of button as well.
The mnemonic: init-keyword is used to specify a keyboard mnemonic for the button. This is a key press that involves pressing the ALT key followed by a number of alphanumeric keys.
Note that the choice of keys is more restrictive than for keyboard accelerators. They are determined in part by the names of button itself (and, in the case of menu buttons, the menu that contains it), as well as by any appropriate style guidelines. For example, a common mnemonic for the File > Open command is ALT, F, O.
Mnemonics have the advantage that the letters forming the mnemonic are automatically underlined in the button label on the screen (and, for menu buttons, the menu itself). This means that they do not have to be remembered. In addition, when the user makes use of a mnemonic in a menu, the menu itself is displayed on screen, as if the command had been chosen using the mouse. This does not happen if the keyboard accelerator is used.
Buttons are intrinsically "non-stretchy" gadgets. That is, the width and height of a button is generally calculated on the basis of the button's label, and the button will be sized so that it fits the label accordingly. Sometimes, however, you want a button to occupy all the available space that is given it, however large that space may be. To force a button to use all the available width or height, specify max-width: $fill or max-height: $fill accordingly in the button definition. See the second example below to see how this is done.
dialog-apply-button-setter dialog-back-button-setter dialog-cancel-button-setter dialog-exit-button-setter dialog-help-button-setter dialog-next-button-setter dialog-apply-button-setter
contain
(make(<button>, label: "Hello",
activate-callback:
method (gadget)
notify-user
(format-to-string
("Pressed button %=", gadget),
owner: gadget)
end));The following example creates a column layout that contains two elements.
The use of equalize-widths?: in the call to vertically ensures that these two elements have the same width.
The interesting part of this example is in the use of max-width: $fill in the definition of the buttons with shorter labels. If this was not used, then each button would be sized such that it just fit its own label, and there would be empty space in the row layout. However, using max-width: $fill ensures that each button is made as large as possible, so as to fit the entire width of the row layout.
vertically (equalize-widths?: #t)
horizontally ()
make(<button>, label: "Red", max-width: $fill);
make(<button>, label: "Ultraviolet",
max-width: $fill);
end;
make(<button>,
label:
"A button with a really really long label");
end