Constructor | Variables | Functions
Gui
is a class that functions as the context within which all GuiObject
objects are created, stored, updated, and drawn. This is automatically created when you call the global function createGui()
.
let gui;
function setup() {
createCanvas(400, 400);
gui = createGui();
}
Creates a new Gui
object, which retains and computes all of the information regarding your GUI, including style, user input, and object states. This should be called from within your sketch's setup()
function.
createGui()
None
Gui
An array of GuiObject
objects stored within the Gui
.
let gui;
let b, bCopy;
function setup() {
createCanvas(400, 400);
gui = createGui();
b = createButton("Button", 50, 50);
if (gui.get("Button").length == 1) {
bCopy = gui.get("Button");
}
}
Returns an array of GuiObject
objects that match the label parameter.
get(label)
label
String: label name of the object(s) that will be returned
GuiObject[]
let gui;
function setup() {
createCanvas(400, 400);
gui = createGui();
gui.loadStyle("TerminalGreen");
}
Loads a GuiStyle
preset style based on string input. Options are:
"Gray"
"Rose"
"Seafoam"
"Blue"
"TerminalGreen"
"TerminalRed"
"TerminalBlue"
"TerminalYellow"
"TerminalMagenta"
loadStyle(preset)
preset
String: name of style preset
None
let gui;
let s;
function setup() {
createCanvas(400, 400);
gui = createGui();
s = createSlider("BoxySlider", 50, 50);
gui.style.slider.rounding = 0;
gui.updateStyle();
}
Copies all properties currently stored in Gui.style
to its children GuiObject
objects. This is useful if you've set specific parameters in Gui.style
that you'd like to propogate to all GuiObject
objects.
updateStyle()
None
None
let gui;
function setup() {
createCanvas(400, 400);
gui = createGui();
gui.setStrokeWeight(10); // Draws thick lines.
}
Sets the stroke weight for all GuiObjects
.
setStrokeWeight(weight)
weight
Number: the weight (in pixels) of the stroke
None
let gui;
function setup() {
createCanvas(400, 400);
gui = createGui();
gui.setRounding(10); // Draws nice rounded corners.
}
Sets the radius for all GuiObject
corners. This creates a rounded corner effect.
setRounding(rounding)
rounding
Number: radius of corners
None
let gui;
function setup() {
createCanvas(400, 400);
gui = createGui();
gui.setFont("Arial");
}
let gui;
let font;
function preload() {
font = loadFont('assets/Regular.otf');
}
function setup() {
createCanvas(400, 400);
gui = createGui();
gui.setFont(font);
}
Sets the font that will be applied to all GuiObject
objects.
setFont(font)
font
Object|String: a font loaded via loadFont(), or a String representing a web safe font (a font that is generally available across all systems)
None
let gui;
function setup() {
createCanvas(400, 400);
gui = createGui();
gui.setTextSize(40);
}
Sets the textSize that will be applied to the text in all GuiObject
objects.
setTextSize(theSize)
theSize
Number: the size of the letters in units of pixels
None
let gui;
function setup() {
createCanvas(400, 400);
gui = createGui();
gui.setTrackWidth(0.1);
}
Sets the width of slider tracks as a ratio. For instance, setTrackWidth(1)
sets it to full width, while setTrackWidth(0.5)
sets it to half width. setTrackWidth(0)
renders the track as a single line.
setTrackWidth(ratio)
ratio
Number: width of all slider tracks between 0 (line) and 1 (full)
None
These are the preset styles for p5.touchgui:
"Gray"
"Rose"
"Seafoam"
"Blue"
"TerminalGreen"
(shown onbackground(0)
)
"TerminalRed"
(shown onbackground(0)
)
"TerminalBlue"
(shown onbackground(0)
)
"TerminalYellow"
(shown onbackground(0)
)
"TerminalMagenta"
(shown onbackground(0)
)