-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recenter NumberControl title when changed with PhET-iO? #526
Comments
My recommendation is to not make the change to NumberControl. Instead, set a Its more appropriate (and probably safer) to observe 'bounds', not 'text':
Re "the resize option".... You are presumably talking about the |
The way it was working did seem to be resizing the text correctly - it just wasn't centering it. |
The priority of this was raised because a client asked for it. In lieu of this I decided to only update this for NumberControls using layoutFunction3 and centering the title. I tested that this works as expected when changing the title in GFL studio, and I also regression tested a slider that with a centered title, and a slider with a left aligned title. @pixelzoom please review. |
Here is the phetioID of the element in GFL studio that adjusts a number control title: |
Imo, e1f6bb5 is totally unacceptable. Not only does it not address layout functions uniformly, it doesn’t even handle all values of |
Thanks! I'll take another look. |
After discussing with @zepumph on Slack, here's what I recommend: (1) Correctly handle all values of titleAlignBox.on( 'bounds', () => {
if ( options.alignTitle === 'center' ) {
titleAlignBox.centerX = vBox.centerX;
}
else if( options.alignTitle === 'left'){
titleAlignBox.left = vBox.left;
}
else if( options.alignTitle === 'right'){
titleAlignBox.right = vBox.right;
}
} ); (2) If being able to change the title is truly "important for PhET-iO", then adding support to |
I added (1) in the above commit. When testing with ISLCControlPanel (in GFL), the "left" option worked as expected, but for some reason, the "right" one did not. I'm going to have to investigate further (it may be ISLC implementation specific). |
After some more experimenting, I found a solution that I am more happy with. Instead of manually trying to recompute the alignment, I just passed that work up to the vbox. This is working perfectly save for really large strings. When the string is past the maxWidth, it begins scaling down, and then that pushed the numbercontrol content up, see below. I don't know an easy way around this. @pixelzoom can you think of how to "lock in" the height of the vBox on creation?
Yes I think that is a good point. Up to this point we have been tackling these as we go in PhET-iO design meetings, file by file. NumberControl is the first we have encountered that is big enough that I recommended not handling everything in it at once, but I could be convinced that that isn't the best approach. I think it is best when there is an easy way to test the changes (usually in studio), so ad-hoc is nice for that reason. I'll mark this for phet-io meeting to try to figure out the best approach for tackling our iceberg. |
Example of how you're using VBox to solve the problem? |
In
To set this, open GFL in studio, and change the text on |
I think this problem is in the same category as blank spaces that appear in panels when UI components are hidden. The client will just have to live with it. This is how text (and all Nodes) behave in general. If the maxWidth (or maxHeight) is exceeded, it gets scaled down. And if it's in a layout with other UI components, then things will move around. I don't recommend adding some title-specific hack (like a VStrut or AlignGroup) to |
I totally agree with you, and I'm very happy you said this! To me no further work is needed here. Thanks @pixelzoom for the review. I created https://github.com/phetsims/phet-io/issues/1551 to investigate what further work is needed for PhET-iO dynamic layout both in NumberControl and in general. Closing |
From phetsims/gravity-force-lab#76. It looks like GFL is using layoutFunction3 with the title align "center". @kathy-phet and I thought it would be nice if that recentered when the text changed. I couldn't figure out an easy way to do it, I tried something like
But it didn't work out of the box. I think this may have to do with the "resize" option which is set to false to "prevent slider from causing a resize when thumb is at min or max."
@pixelzoom added that commit (albeit 3 years ago). What do you think the best way to accomplish this is? Or do you think I should push back on this request?
UPDATE: tagging phetsims/gravity-force-lab#175 too
The text was updated successfully, but these errors were encountered: