Button:
Filter:
Classes | GUI > Views

Button : View : QObject : Object

A multi-state button
Subclasses: MButtonView, QButton

Description

A multi-state button.

Some Important Issues Regarding 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 a Button, and action would then be set to that function.

Class Methods

Button.new(parent, bounds)

From superclass: View

Arguments:

parent

The parent view.

bounds

An instance of Rect, or a Point indicating width@height.

Discussion:

Example:

Inherited class methods

Undocumented class methods

Button.qtClass

Instance Methods

.states

.states = stateArray

An array of labels and colors defining the states of the button.

Arguments:

stateArray

An Array of arrays of the form [ [String, strColor, bgColor] , .... ]

.value

.value = argVal

Sets or returns the index of the current state. This will not evaluate the function assigned to action (see View).

Arguments:

argVal

The index of an item in the states array.

.valueAction = anInt

Sets the button to display the item at index anInt of the states array, and evaluates action (see View), if the value has changed.

Arguments:

anInt

The index of an item in the states array.

.string

.string = string

Sets or gets the text of the currently active state.

.font

.font = aFont

From superclass: View

Sets the Font of the button. Default value is the default font: Font.default .

Arguments:

aFont

An instance of Font.

Subclassing and Internal Methods

The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.

.doAction(modifiers)

The method called by the primitive upon releasing the mouse.

Arguments:

modifiers

A key modifier number, which is passed to the action as its second argument upon mouse-releasing the button.

.defaultKeyDownAction(char, modifiers, unicode, keycode, key)

From superclass: View

Discussion:

The default keydown actions are:

keyactioncomment
" "value + 1space
\rvalue + 1
\nvalue + 1
3.asAsciivalue + 1enter key or cmd-C on macOS

To change these use defaultKeyDownAction_, see View.

.properties

From superclass: QObject

A list of properties to which this view responds. See View.

Returns:

[ \bounds, \visible, \enabled, \canFocus, \resize, \background, \minWidth, \maxWidth, \minHeight, \maxHeight, \value, \font, \states, \focusColor ]

.defaultGetDrag

The method called by default when initiating a drag from a Button. Returns the same as -value.

.defaultCanReceiveDrag

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.

.defaultReceiveDrag

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.

Inherited instance methods

Undocumented instance methods

.action

.action = func

From superclass: View

.icon = image

.iconSize

.iconSize = size

.menu

.menu = menu

Examples

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.