Open bushrat011899 opened 2 weeks ago
Awesome! I swapped to this branch locally with my playground example and every locale now displays without the need to load any external font files 🎊
I suppose this does increase the need for users to have the ability to control cosmic_text
fallbacks. I should have time later in the week to dig into that and see what's viable.
If it's enabled by default, add an example that shows how to disable this feature. Reasoning is simple: if an app is shipped with a font, why waste time loading all system fonts? IMO add something like:
fn setup(....) { .... let system_fonts: SystemFonts = asset_loader.load_sys_fonts(); .... }
So user will have simple way, and control when to load.
If it's enabled by default...
I've left it is a feature that's disabled by default. To enable system fonts, you enable the system_font
feature in Bevy. This feature does have a startup time cost and I completely agree that the functionality should be opt-in, at least while it has a noticeable impact.
I've just noticed #14150, was that effort abandoned?
I never saw that! Looks like it wasn't linked to the original issue. I'm happy to incorporate changes from that PR, or close this out in favour of that one, I'll leave that up to the reviewers.
Objective
Solution
system_font
, which will instructcosmic_text
to load system fonts on startup.FontLibrary
, which allows for convenient searching of all loaded fonts, returning aHandle<Font>
if you have found a suitable candidate.system_fonts
, which demonstrates searching for and using system fonts.Testing
system_fonts
exampleShowcase
Users now have access to the
FontLibrary
system parameter, which allows searching for available fonts. This helps with using the newsystem_fonts
feature, which will load system fonts at runtime.In the below snippets,
fonts
is of typeFontLibrary
Notes
system_fonts
feature is enabled on a platformcosmic_text
does not support, it is simply a no-op, making the feature safe to enable in all cases.FontLibrary
system param could use some more methods, such as an iterator. I have deliberately only exposed afind
method since we need to do some work with theAssets<Font>
to ensure it's available for theTextPipeline
.Font
type assumes every font will have binary data associated with it (thedata
field). For system fonts this is not the case. I'm simply inserting no data (empty slice) for these fonts. It might be prudent to updateFont
to be anenum
instead to make this more clear.