GuiSlider / GuiSliderV
August 26, 2019 ยท View on GitHub
GuiSlider / GuiSliderV
Example | Constructor | Variables | Functions
Description
Slider class.
Note: vertical slider class is virtually the same, just with a different orientation.

Example
let gui;
// Create a variable for your Slider
let s;
function setup() {
createCanvas(400, 400);
gui = createGui();
// Create Slider.
// The last two optional arguments define the min and max (minimum and maximum) values.
// The default min and max values are 0 and 1, respectively.
s = createSlider("Slider", 50, 50, 300, 32, 100, 300);
}
function draw() {
background(220);
drawGui();
if (s.isChanged) {
// Print a message when Slider is changed
// that displays its value.
print(s.label + " = " + s.val);
}
// Use Slider's value to determine where the ellipse is drawn.
fill(255, 0, 0);
ellipse(s.val, 300, 100);
}
/// Add these lines below sketch to prevent scrolling on mobile
function touchMoved() {
// do some stuff
return false;
}
Constructor
createSlider()
Example
let gui;
let s;
function setup() {
createCanvas(400, 400);
gui = createGui();
s = createSlider("Slider", 50, 50);
}
Description
Creates a new GuiSlider object. This is a horizontal slider.
Note: For a vertical slider, instead use createSliderV().
Syntax
createSlider(label, x, y, [w], [h], [min], [max])
Parameters
labelString: label for the GuiSliderxNumber: x-coordinate of the GuiSlideryNumber: y-coordinate of the GuiSliderwNumber: width of the GuiSlider (default is 128)hNumber: height of the GuiSlider (default is 32)minNumber: lower bound of the value's range (default value is 0)maxNumber: upper bound of the value's range (default value is 1)
Returns
GuiSlider
Variables
val
Example
slider.val = 0.5;
if (slider.isChanged) {
print(slider.val);
}
Description
Value of the GuiSlider.
min
Example
slider.min = -100;
Description
Lower bound of the GuiSlider range.
max
Example
slider.max = 100;
Description
Upper bound of the GuiSlider range.
isInteger
Example
slider.isInteger = True;
Description
Sets the mode of the GuiSlider so that all values are integers.
Functions
setStyle()
Example
slider.setStyle("fillBg", color(255, 0, 0));
slider.setStyle({
fillBg: color("#FF0000"),
rounding: 10,
trackWidth: 0.1
});
Description
Individual GuiSlider objects can be styled using this method. There are two types of input it takes. Use an input string and value to set an individual property, and use an Object with key/value notation to set multiple properties at once.
Syntax
setStyle(property, value)
setStyle(Object)
Parameters
property String: name of property to be set
value Number|String|Object: value of property to be set
Object Object: multiple propertys and values to be set
Returns
None
Style
The GuiSlider style properties are:
strokeWeightNumber: the weight (in pixels) of the strokeroundingNumber: radius of cornerstrackWidthNumber: width of all slider tracks between 0 (line) and 1 (full)fillBgp5.Color: default background fill colorfillBgHoverp5.Color: hover background fill colorfillBgActivep5.Color: active background fill colorfillTrackp5.Color: default track fill colorfillTrackHoverp5.Color: hover track fill colorfillTrackActivep5.Color: active track fill colorfillHandlep5.Color: default handle fill colorfillHandleHoverp5.Color: hover handle fill colorfillHandleActivep5.Color: active handle fill colorstrokeBgp5.Color: default background stroke colorstrokeBgHoverp5.Color: hover background stroke colorstrokeBgActivep5.Color: active background stroke colorstrokeTrackp5.Color: default track stroke colorstrokeTrackHoverp5.Color: hover track stroke colorstrokeTrackActivep5.Color: active track stroke colorstrokeHandlep5.Color: default handle stroke colorstrokeHandleHoverp5.Color: hover handle stroke colorstrokeHandleActivep5.Color: active handle stroke color