GuiButton
August 26, 2019 ยท View on GitHub
GuiButton
Example | Constructor | Variables | Functions
Description
Momentary button class.

Example
let gui;
// Create variable for your Button
let b;
function setup() {
createCanvas(400, 400);
gui = createGui();
// Create Button
b = createButton("Button", 100, 50, 200, 50);
}
function draw() {
background(220);
drawGui();
if (b.isPressed) {
// Print a message when Button is pressed.
print(b.label + " pressed.");
}
if (b.isHeld) {
// Draw an ellipse when Button is held.
fill(255, 0, 0);
ellipse(200, 300, 100);
}
}
/// Add these lines below sketch to prevent scrolling on mobile
function touchMoved() {
// do some stuff
return false;
}
Constructor
createButton()
Example
let gui;
let b;
function setup() {
createCanvas(400, 400);
gui = createGui();
b = createButton("Button", 50, 50);
}
Description
Creates a new GuiButton object. This is a momentary button.
Syntax
createButton(label, x, y, [w], [h])
Parameters
labelString: label for the GuiButtonxNumber: x-coordinate of the GuiButtonyNumber: y-coordinate of the GuiButtonwNumber: width of the GuiButton (default is 128)hNumber: height of the GuiButton (default is 32)
Returns
GuiButton
Variables
val
Example
button.val = True;
print(button.val)
Description
Value of the GuiButton.
label
button.label = "Button";
print(button.label)
Description
Label of the GuiButton. Setting the label will automatically set labelOn and labelOff (see below).
labelOn
button.labelOn = "Button On";
print(button.labelOn)
Description
Label of the GuiButton when pressed or "on".
labelOff
button.labelOff = "Button Off";
print(button.labelOff)
Description
Label of the GuiButton when unpressed or "off".
Functions
setStyle()
Example
button.setStyle("fillBg", color(255, 0, 0));
button.setStyle({
fillBg: color("#FF0000"),
rounding: 10,
textSize: 40
});
Description
Individual GuiButton 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 GuiButton style properties are:
strokeWeightNumber: the weight (in pixels) of the strokeroundingNumber: radius of cornersfontObject|String: a font loaded via loadFont(), or a String representing a web safe font (a font that is generally available across all systems)textSizeNumber: the size of the letters in units of pixelsfillBgp5.Color: default background colorfillBgHoverp5.Color: hover background colorfillBgActivep5.Color: active background colorfillLabelp5.Color: default label colorfillLabelHoverp5.Color: hover label colorfillLabelActivep5.Color: active label colorstrokeBgp5.Color: default stroke colorstrokeBgHoverp5.Color: hover stroke colorstrokeBgActivep5.Color: active stroke color