Skip to content

Slider

Create a slider the user can drag to choose a value.

Creating a Slider

You can create a Slider using the following functions:

Slider()
Slider(orientation, minValue, maxValue, startValue, action)
Parameter Type Default Description
orientation int HORIZONTAL The slider direction, either HORIZONTAL or VERTICAL.
minValue int 0 The smallest value the slider can take.
maxValue int 100 The largest value the slider can take.
startValue int or float None The slider's starting value. Defaults to halfway between minValue and maxValue.
action function None The function to call when the slider moves; it receives one parameter, the new value.

For example,

slider = Slider(VERTICAL, 0, 127, 50, changeVolume)

where changeVolume is a function which expects one parameter, the new value of the slider. When the function is called, it may use this value to update the volume of some musical material, for instance.

Once created, you can add it to a Display using the Display's add() function.

Functions

Once a Slider slider has been created, the following functions are available:

Function Description
slider.getValue() Return the object's current value.
slider.setValue(value) Set the object's value.

Position

Function Description
button.getPosition() Return the object's position, the top-left corner of its bounding box.
button.getX() Return the object's horizontal position.
button.getY() Return the object's vertical position.
button.getCenter() Return the object's center point.
button.getCenterX() Return the object's horizontal center.
button.getCenterY() Return the object's vertical center.
button.setPosition(x, y) Move the object so the top-left corner of its bounding box sits at the given point.
button.setX(x) Set the object's horizontal position.
button.setY(y) Set the object's vertical position.
button.setCenter(x, y) Move the object so its center sits at the given point.
button.setCenterX(x) Set the object's horizontal center.
button.setCenterY(y) Set the object's vertical center.
button.move(x, y) Move the object to a new position.

Size

Function Description
button.getSize() Return the object's width and height.
button.getWidth() Return the object's width.
button.getHeight() Return the object's height.
button.setSize(width, height) Set the object's width and height.
button.setWidth(width) Set the object's width.
button.setHeight(height) Set the object's height.

Rotation

NOTE: Controls cannot be rotated. A control has these methods available, but they do nothing.

Function Description
button.setRotation(rotation) Do nothing, since controls cannot be turned.
button.getRotation() Return how far the object is turned.
button.rotate(angle) Turn the object by an additional angle.

Visibility

Function Description
button.getVisibility() Return how visible the object is.
button.setVisibility(visibility) Set how visible the object is.

Information

Function Description
button.getEndpoints() Return the object's four corners.
button.getBoundingBox() Return the smallest upright box that surrounds the object.
button.getGroup() Return the Group this object belongs to.
button.getDisplay() Return the Display this object is on.
button.setToolTipText() Set the hover text shown over the object.

Hit Testing

Function Description
button.contains(x, y) Report whether a point lies inside the object.
button.intersects(other) Report whether this object overlaps another.
button.encloses(other) Report whether this object completely contains another.

Events

Function Description
button.onMouseClick(action) Set up a function to call when the mouse is clicked on this object.
button.onMouseDown(action) Set up a function to call when the mouse button is pressed on this object.
button.onMouseUp(action) Set up a function to call when the mouse button is released over this object.
button.onMouseMove(action) Set up a function to call when the mouse moves over this object.
button.onMouseDrag(action) Set up a function to call when the mouse is dragged over this object.
button.onMouseEnter(action) Set up a function to call when the mouse moves onto this object.
button.onMouseExit(action) Set up a function to call when the mouse moves off this object.
button.onKeyType(action) Set up a function to call when a key is typed (pressed and released).
button.onKeyDown(action) Set up a function to call when a key is pressed down.
button.onKeyUp(action) Set up a function to call when a key is released.