-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
Improve API usage of BitmapFont.from #6640
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #6640 +/- ##
=======================================
Coverage 82.34% 82.34%
=======================================
Files 37 37
Lines 1897 1897
=======================================
Hits 1562 1562
Misses 335 335 Continue to review full report at Codecov.
|
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.
Looks much better than before!
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.
🥇 🥇
One other thing I discovered was the use of Array.prototype.find which is not supported in IE will need to replace that with something more compatible. |
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.
nice tidy up @bigtimebuddy ! 👍
import { hex2rgb, string2hex } from '@pixi/utils'; | ||
import type { TextMetrics, TextStyle } from '@pixi/text'; | ||
|
||
// TODO: Prevent code duplication b/w drawGlyph & Text#updateText |
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.
oh yes! this is great idea!
we could create a cache that is mapped by style :D
love the idea of storing standard fonts as B/W and then tinting them! 👍
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.
"
Both these signatures are now supported BitmapFont.from(name, style) and BitmapFont.from(options, style)
"
Like the changes! But this signature style doesn't make sense to me. Surely you just have
BitmapFont.from(name, style, options)
And then you've one signature to rule them all?
Good shout @themoonrat. Fixed. |
Overview
This change is mostly about improving and streamlining ergonomics using the new
BitmapFont.from
API (#6600).Also, did some minor code organization and documentation fixes.
Before
Previously you optionally defined the font name and no chars were set by default.
After
Now, font is installed, name is required, and chars are optional (defaults to ALPHANUMERIC).
Now, if you want to change something on the fly, regenerating the font is as easy as calling
BitmapFont.from
again with some new style options.Demo
https://jsfiddle.net/bigtimebuddy/wt9szqp6/
Changed
Both these signatures are now supportedChanged API signature to beBitmapFont.from(name, style)
andBitmapFont.from(options, style)
BitmapFont.from(name, style, options)
name
is required forBitmapFont.from
for ease of use.BitmapFont.from
, it will override any existing font by default with the same name, making it easier to regenerate the font.BitmapFont.defaultOptions
in case users want to change this globally.drawGlyph
andprocessCharData
to their own utilities. Still need a cleanup ongenerateFillStyle
anddrawGlyph
with Text. Probably better for a follow-up PR.