micuat
April 24, 2021, 4:28pm
8
I dug into the code and found there is a bug. The original library QuickSettings has a function to add a button:
http://bit101.github.io/quicksettings/demos/demo.html
however, p5.gui did something wrong with inheritance and addButton function is in a bit weird place. They simply assigned qs to prototype
// interface for quicksettings
function QSGui(label, parent, sketch) {
// hard code the position, it can be changed later
let x = 20;
let y = 20;
var qs = QuickSettings.create(x, y, label, parent);
// proxy all functions of quicksettings
this.prototype = qs;
// addGlobals(global1, global2, ...) to add the selected globals
this.addGlobals = function() {
qs.bindGlobals(arguments);
};
// addObject(object) to add all params of the object
// addObject(object, param1, param2, ...) to add selected params
this.addObject = function() {
// get object
but I think this is wrong and you need to copy every member variables and functions to prototype… if I’m correct. Nevertheless you can access like this
gui.prototype.addButton("say hi", function() {
console.log("hi!!")
})
https://editor.p5js.org/micuat/sketches/Y11IACWvQ
1 Like