A multi-state button.
Failure to set any states at all results in an invisible button.
The button performs its action upon releasing the mouse. In musical contexts, you might want to use mouseDownAction_()
to set a function to be performed on pressing the mouse (see View, and examples below).
If the drag contains a number, then valueAction_()
is performed using the currentDrag
. If the drag contains anything else, action
is set to the current drag. You could, for example, drag a function to an Button, and action would then be set to that function.
parent |
The parent view. |
bounds |
Example:
An array of labels and colors defining the states of the button.
stateArray |
An Array of arrays of the form |
Sets or returns the index of the current state. This will not evaluate the function assigned to action (see View).
argVal |
The index of an item in the states array. |
Sets the button to display the item at index anInt of the states array, and evaluates action (see View), if the value has changed.
anInt |
The index of an item in the states array. |
Sets or gets the text of the currently active state.
Sets the Font of the button. Default value is the default font: Font.default .
font |
An instance of Font. |
The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.
The method called by the primitive upon releasing the mouse.
modifiers |
A key modifier number, which is passed to the action as its second argument upon mouse-releasing the button. |
The default keydown actions are:
key | action | comment |
" " | value + 1 | space |
\r | value + 1 | |
\n | value + 1 | |
3.asAscii | value + 1 | enter key or cmd-C on macOS |
To change these use defaultKeyDownAction_
, see View.
A list of properties to which this view responds. See View.
[ \bounds, \visible, \enabled, \canFocus, \resize, \background, \minWidth, \maxWidth, \minHeight, \maxHeight, \value, \font, \states, \focusColor ]
The method called by default when initiating a drag from a Button. Returns the same as -value.
The method called by default when attempting to drop a drag in this object. By default, Button will respond only to drags where the drag contains a Number or Function.
The default method called when a drag has been received. If the drag contains a number, then action is set to the current drag. Otherwise valueAction_()
is performed using the currentDrag
.
In a musical context, a button-down press is more meaningful than a button-up (release) as it's more intuitive to press a button on the beat. For that you can use View's View: mouseDownAction (a superclass of Button).
If you drag a function to a button, the button's action is set to that function. you can us this for swapping functions.
Using Routine to set button states on the fly.
Using Routine to set button states on the fly 2.
Complex drag and drop example try dragging the buttons to white slot, and then between white slots, or simply out of the view.