You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A small thing, but also re: p5.dom a lot of my examples require dynamically accessing the size of a DIV (which changes according to the amount of text). I may be mistaken but I believe p5 only allows for setting the dimensions with size() but for retrieving the width/height I am doing the following:
var w = div.elt.offsetWidth;
var h = div.elt.offsetHeight;
Would it make sense to have a width()/height() method that returns the dimensions?
A small thing, but also re: p5.dom a lot of my examples require dynamically accessing the size of a DIV (which changes according to the amount of text). I may be mistaken but I believe p5 only allows for setting the dimensions with size() but for retrieving the width/height I am doing the following:
var w = div.elt.offsetWidth;
var h = div.elt.offsetHeight;
Would it make sense to have a width()/height() method that returns the dimensions?
@shiffman this would be great. I've been making most of the things in this library work as both setters and getters, so maybe these methods could set the w and h or return vals if arguments are null.
@brysonian interesting suggestion! we might have already implemented most of this, and in some ways slightly different than this lib, but let me take a closer look.
.size() now returns a string with the current width & height of the element if no arguments are provided.
However, p5 Elements already have the variables 'width' and 'height' that store the element's initial offsetWidth/offsetHeight. Should we use a naming convention like eltWidth and eltHeight?
var txt;
function setup() {
noCanvas();
txt = createDiv("Hello!");
txt.style("background-color","#00FF00");
txt.position(100,100);
console.log(txt.width);
txt.html("Hello again!")
console.log(txt.width);
}
function mousePressed() {
console.log(txt.width);
console.log(txt.size());
}
The current behavior I believe is:
size() returns the p5.Element instance. I like the idea of it returning dimensions, but a string is not particularly useful as it will almost always need to be parsed back into numbers. What if size() returns an object with a width and height, i.e.
width and height both return the original width and height of the element no matter how much it changes. This would be a perfect solution as far as I'm concerned but is that original width/height being maintained for a reason I'm not aware of? An alternative would be to add width() and height() functions but that seems like overkill given we have size() already.
I think an object returned from .size() is enough.
In this spirit of doubling as a getter/setter, what if with null arguments things like .style() return an object of the elt's styles.
This could also help when considering how to more easily deal with input events. We can make the setter/getter .events() which would either return an object of events or set an event handler.
Something like:
varbtn=createButton();vardiv=createDiv('im a div');btn.events().onmousedown=div.html('listening to btn');
I think this syntax is a bit hard to follow. We have a mousedown event handler actually, so I wonder how it fits with this? Or are you suggesting replacing it?
btn.mousePressed(function(e){// do stuff } )
If we wanted to add a generic event() method, I think a format like event(eventType, func) would follow the form set by style().
btn.event('mousedown',function(e){// do stuff } );
In any case, the right side of the code above would need to be wrapped inside of a function, so it's not fired immediately, something like:
re: width and height, this sounds like a bug. they should be updated when the size changes, though there is still room for these to be wrong. for example, if you created an element and set the width and height manually with css rather than using the style() function, so having size() return the width and height makes sense.
@lmccart I guess I'm trying to find a place for things that people might want when working with form elements. What if we had an onChange() to go with the listener functions?
Activity
brysonian commentedon Oct 11, 2014
Would it make sense to integrate something like bonzo? https://github.com/ded/bonzo
Chandler McWilliams
http://brysonian.com
On Sat, Oct 11, 2014 at 10:03 AM, Daniel Shiffman
notifications@github.com wrote:
lmccart commentedon Oct 13, 2014
@shiffman this would be great. I've been making most of the things in this library work as both setters and getters, so maybe these methods could set the w and h or return vals if arguments are null.
@brysonian interesting suggestion! we might have already implemented most of this, and in some ways slightly different than this lib, but let me take a closer look.
brysonian commentedon Oct 13, 2014
@lmccart yeah to be more clear i guess i'm just wondering how much wheel-reinventing is necessary, but if the work is already done then that's great!
futuremarc commentedon Jun 13, 2015
.size() now returns a string with the current width & height of the element if no arguments are provided.
However, p5 Elements already have the variables 'width' and 'height' that store the element's initial offsetWidth/offsetHeight. Should we use a naming convention like eltWidth and eltHeight?
shiffman commentedon Jun 13, 2015
I ran some quick tests (with the following code).
The current behavior I believe is:
size()returns thep5.Elementinstance. I like the idea of it returning dimensions, but a string is not particularly useful as it will almost always need to be parsed back into numbers. What ifsize()returns an object with a width and height, i.e.widthandheightboth return the original width and height of the element no matter how much it changes. This would be a perfect solution as far as I'm concerned but is that original width/height being maintained for a reason I'm not aware of? An alternative would be to addwidth()andheight()functions but that seems like overkill given we havesize()already.futuremarc commentedon Jun 13, 2015
I think an object returned from
.size()is enough.In this spirit of doubling as a getter/setter, what if with null arguments things like
.style()return an object of the elt's styles.This could also help when considering how to more easily deal with input events. We can make the setter/getter
.events()which would either return an object of events or set an event handler.Something like:
lmccart commentedon Jun 13, 2015
I think this syntax is a bit hard to follow. We have a mousedown event handler actually, so I wonder how it fits with this? Or are you suggesting replacing it?
If we wanted to add a generic
event()method, I think a format likeevent(eventType, func)would follow the form set bystyle().In any case, the right side of the code above would need to be wrapped inside of a function, so it's not fired immediately, something like:
lmccart commentedon Jun 13, 2015
re:
widthandheight, this sounds like a bug. they should be updated when the size changes, though there is still room for these to be wrong. for example, if you created an element and set the width and height manually with css rather than using thestyle()function, so havingsize()return the width and height makes sense.futuremarc commentedon Jun 18, 2015
widthandheightattributes now return the correct value and they update on change. (though only act as getters)size()returns an object ofwidthandheightif empty.size()bug fixed: actually sets the size of an element now (the css markup!importantwas breaking it).position()returns an object ofxandyif empty.xandyare now attributes on the element and can be accessed viaelt.xorelt.y(to stay consistent. re: Properties of a dom p5.element, position? #579 )@lmccart I guess I'm trying to find a place for things that people might want when working with form elements. What if we had an
onChange()to go with the listener functions?futuremarc commentedon Jun 29, 2015
closed with 9015ffe