-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Dynamic fonts #3698
Dynamic fonts #3698
Conversation
…heir size information when constants change.
@BeksOmega fyi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random subset of comments--I'm not done reading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I really like it! I didn't see any code problems, but I haven't pulled it to test it yet.
One thing I'm curious about is the changes to isDirty. Was this just for code consistency or did you run into problems? Either way I'm cool with removing it where you did.
Otherwise it was just little doc things. Thanks for your work on this :D
core/utils/dom.js
Outdated
@@ -273,7 +273,7 @@ Blockly.utils.dom.getTextWidth = function(textElement) { | |||
* This method requires that we know the text element's font family and size in | |||
* advance. Similar to `getTextWidth`, we cache the width we compute. | |||
* @param {!Element} textElement An SVG 'text' element. | |||
* @param {number} fontSize The font size to use. | |||
* @param {string} fontSize The font size to use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a breaking change, so it should be marked for doc updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change here is just whether you expect the 'pt' on the font size to be added here or by the calling code, right? What's the advantage of changing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flyout button dynamically reads from CSS what the font size should be, which generates the font size in pixels. I needed to change this in order to support both pt
for fields and px
for flyout buttons.
As I think about this, there's a way to do this without making it a breaking change. I'll just add another util method that uses pixels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm struggling to come up with the other method name, how do we feel about getFastTextWidthWithSizeString
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-field files look solid (pending some changes we just discussed).
I pulled down the branch and did some testing and it looks really good! I did find a smattering of small issues though so I'm just going to smatter them at you :P Multiline text field is a bit broken. Geras inline inputs are kinda weird. But I don't think this is a bug. Checkbox needs to re-render when the character is changed (this one is probably mine hehe) Dropdown carrots act differently in geras and zelos. In geras they match text in zelos they do not. Not sure if this is a bug, or which way it goes if it is. Might want to ask devs what they want. Warnings are a bit broken. They do resize pretty well if you close & reopen them though. Comments (block & workspace) don't reflect text size. Not sure if they should. Zelos flyout buttons don't reflect text size. I think the text category flyout label should automatically match the text size since it only overrides the font family, which it is not doing. But I'm not sure, this could be intended.
I expect both And I think that #2694 should be left open, as applying a class directly to the field still doesn't quite work. If you want me to create separate issues for any of these I'm totally cool with that! (┏-‿ ◕)┏ Thanks for all your hard work! |
Will fix.
Yeah, that's expected. Thrasos doesn't have that problem as it vertically aligns everything.
I think a forceRerender would fix this in
True, the background here is that zelos uses SVG and we don't resize the SVG based on the text font size. Whereas dropdowns are text in geras and are resized when the font changes.
This one's a little tricky as icons don't have render loops.
Also simple to make them reflect the size, currently renderers aren't applying it's font properties to
That's by design, I added an override in the playground in order to test custom CSS.
Similar to comments, we can have a think about applying the renderer font properties to that as well.
The flyout gaps are the same, its just that text has different height and in turn gaps around its legible text depending on the font size. Not sure what can be done here. |
Thanks all for reviewing and for your feedback! Apologies that this ended up being on the larger end of changes that I usually like. But hey dynamic fonts woo! |
The basics
The details
Resolves
Fixes #2793
Partially addresses #2694
Proposed Changes
Use theme options in the renderer.
Support custom font styles either by extending the renderer and overriding
getDefaultFontStyle_
or by setting the font style in a theme.Support the ability for flyout buttons to declare in CSS their font styles, and measure the height when the flyout opens.
Computing text height during initializes and anytime a theme changes. Font metrics include: height and baseline, baseline is used when
FIELD_TEXT_BASELINE_CENTER
is set to false (geras and Edge / IE).Added debugger element to show text baseline of field labels.
Text constants are all computed now, no more browser specific heights / offsets.
Reason for Changes
Dynamic font sizes.
Test Coverage
Tested all blocks in the playground in all supported browsers.
Tested both
FIELD_TEXT_BASELINE_CENTER
true and false.Tested on:
Documentation
Additional Information