GMSwitchButton:
Filter:
GraphicalModule/Classes (extension) | GUI > Graphical Module

GMSwitchButton
ExtensionExtension

A simple multi states button for creating graphical interfaces

Description

GMSwitchButton is an easy to use customisable button.

It allows to switch between multiple states, behaving like a looping counter.

It only responds to mouse down clicks, and does not discriminate button identifiers.

Class Methods

.new

Creates a new instance of GMSwitchButton.

By default, its graphical properties are defined by its associated GMStyle.

Returns:

a GMSwitchButton instance.

Instance Methods

Interaction

.action

Sets or gets the Function to be triggered when the button is pressed down. This Function takes the current index of the button as argument, i.e. pressing it down from its first state to its second state will call the Function passing 1 as argument.

Arguments:

aFunction

A Function with one argument, the current index of the button as an Integer. The case control structure allows to easily define what actions it should trigger (see example below).

.mouseDownAction

Sets or gets the Function to be triggered when the button is pressed down. This Function takes the current index of the button as argument, i.e. pressing it down from its first state to its second state will call the Function passing 1 as argument. Equivalent to .action .

Arguments:

aFunction

A Function with one argument, the current index of the button as an Integer. The case control structure allows to easily define what actions it should trigger (see example below).

.states

Sets or gets the View's states array, and refreshes the View. Resets the current index to 0.

Arguments:

anArray

An Array containing an arbitrary number of IdentityDictionary, each containing at least a \string key, and optionnals \color and \fontColor keys (see example below). Lastly, a \svg key containing a valid path to an SVG file can be provided to display said SVG on the state.

It is also possible to only provide an Array of strings. In this case, the GMStyle backgroundColor will be used as the state background, and the valueFontColor will be used as font color (see example below).

.state

Sets or gets the View's current index, and refreshes the View. This doesn't trigger the associated action.

.free

Frees every SVG, allowing garbage collection.

Graphic settings

.fontRatio

Sets or gets the font ratio relative to the widget size (depends on direction).

.svgRatio

Sets or gets the svg ratio relative to the widget size.

.direction

Sets or gets the string direction. Valid values are: \right, \top, \left, \bottom.

.setColorAll

Sets every states background colors at once.

.setFontColorAll

Sets every states font colors at once.

Internal Methods

.draw

The function associated to the View's drawFunc. Shouldn't be modified.

.prResizeSVGs

Examples

Assigning states without specifying colors :