GuiChecbox
August 26, 2019 ยท View on GitHub
GuiChecbox
Example | Constructor | Variables | Functions
Description
Checkbox class.

Example
let gui;
// Create a variable for your Toggle
let t;
function setup() {
createCanvas(400, 400);
gui = createGui();
// Create Toggle
t = createToggle("Toggle", 100, 50, 200, 50);
}
function draw() {
background(220);
drawGui();
if (t.isPressed) {
// Print a message when Toggle is pressed
// that displays its value.
print(t.label + " is " + t.val);
}
if (t.val) {
// Draw an ellipse when Toggle is true.
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
createCheckbox()
Example
let gui;
let cb;
function setup() {
createCanvas(400, 400);
gui = createGui();
cb = createCheckbox("Checkbox", 50, 50);
}
Description
Creates a new GuiCheckbox object. This is a checkbox which functions like a toggle button.
Syntax
createCheckbox(label, x, y, [w], [h], [defaultVal])
Parameters
labelString: label for the GuiCheckboxxNumber: x-coordinate of the GuiCheckboxyNumber: y-coordinate of the GuiCheckboxwNumber: width of the GuiCheckbox (default is 32)hNumber: height of the GuiCheckbox (default is 32)defaultValNumber: default value for your GuiCheckbox (default isfalse)
Returns
GuiCheckbox
Variables
val
Example
checkbox.val = True;
print(checkbox.val)
Description
Value of the GuiCheckbox.
Functions
setStyle()
Example
checkbox.setStyle("fillBg", color(255, 0, 0));
checkbox.setStyle({
fillBg: color("#FF0000"),
rounding: 10,
textSize: 40
});
Description
Individual GuiCheckbox 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 GuiCheckbox style properties are:
strokeWeightNumber: the weight (in pixels) of the strokeroundingNumber: radius of cornerstextSizeNumber: the size of the letters in units of pixelsfillBgp5.Color: default background colorfillBgHoverp5.Color: hover background colorfillBgActivep5.Color: active background colorfillCheckp5.Color: default check colorfillCheckHoverp5.Color: hover check colorfillCheckActivep5.Color: active check colorstrokeBgp5.Color: default stroke color