Open samreid opened 5 years ago
(a) Throw an error if non-empty text is detected to have (0,0) bounds during sim runtime.
I'm not sure how throwing an error would be helpful for built simulations. What are the advantages of this?
(b) When non-empty text is detected to have (0,0) bounds, use an alternative approach for determining bounds
This sounds like a good fallback to implement. If agreed upon, I'd like to implement this.
(c) Combine approach (a) with a strategy that preallocates all Text instances, so we can be sure bounds exist during creation
It seems like a difficult problem to be able to anticipate every single font (including the size) used by a simulation.
(d) When non-empty text is detected to have (0,0) bounds, print something to the console to help us debug this if it comes up in the future
This also seems generally useful, so we'll see something in the console.
I'd like to hear thoughts, but a combination of (b) and (d) sounds the best to me right now.
but a combination of (b) and (d) sounds the best to me right now.
That sounds good to me too.
It looks like the DOM-based methods aren't working in this situation either (including our built-in ones, and some online like https://stackoverflow.com/questions/10247132/how-can-i-get-the-height-of-the-baseline-of-a-certain-font)
The most reliable fallback was honestly just figuring out a formula for the anticipated bounds of PhetFont and basing things off of that. I've added that above, and it seems to be working acceptably (even if the sim is detecting 0,0s). Additionally, it will print a single warning (so we don't spam things).
@samreid can you review, and is that everything for this issue?
That seems nice, can you please document how you arrived at the heuristics in getNumericSize
and something about platforms (what platform(s) they were deduced from or tested on)?
From https://github.com/phetsims/chipper/issues/764
I said:
@jonathanolson replied:
I agree the primary case is making sure text bounds are available at the beginning of startup, but I think we should decide how to handle this during the sim runtime. Some possibilities:
(a) Throw an error if non-empty text is detected to have (0,0) bounds during sim runtime.
(b) When non-empty text is detected to have (0,0) bounds, use an alternative approach for determining bounds (c) Combine approach (a) with a strategy that preallocates all Text instances, so we can be sure bounds exist during creation (d) When non-empty text is detected to have (0,0) bounds, print something to the console to help us debug this if it comes up in the future
We do not control how clients will hide/show simulation divs, so I think we should be proactive about how to proceed here.
In my opinion, this feature doesn't need to block publication, because we have had this problem for the entire history of our project. Reassigning to @jonathanolson for follow-up discussion.