Skip to content
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

Choose your own font and size #1154

Merged
merged 27 commits into from
Jan 24, 2022
Merged

Choose your own font and size #1154

merged 27 commits into from
Jan 24, 2022

Conversation

emilk
Copy link
Owner

@emilk emilk commented Jan 23, 2022

This PR rewrites a lot of the font and TextStyle related code so that you can now no longer limited to what's in TextStyle. Now you can use any font size and any font family in all widgets and painting.

TextStyle still exists, but has been moved from epaint to egui, with a look-up-table in egui::Style. It has also been extended with TextStyle::Name so you can create your own named text styles.

FontFamily also has a FontFamily::Name variant so you can name any of your custom font families (if FontFamily::Proportional and FontFamily::Monospace are not enough for you).

FontId is a new struct that contains a FontFamily and a size.

TODO:

  • Update changelogs
  • Improve docs
  • Self-review

@emilk emilk mentioned this pull request Jan 24, 2022
9 tasks
@coderedart
Copy link
Contributor

What happens if fonts don't fit in a texture within max Tex size?

@emilk
Copy link
Owner Author

emilk commented Jan 24, 2022

What happens if fonts don't fit in a texture within max Tex size?

Each font only allocates the glyph it actually uses (*), so a font texture of e.g. 4096x4096 can fit a lot of glyphs. If it gets full, the atlas is cleared and filled in again.

The atlas can still get full if you use a lot of glyphs of different types and font sizes at the same time. For that to realistically happen though, you are filling your screen with all kinds of different text (or have a lot of varying text of varying sizes in a scroll area). Anyway, if this happens: an error is printed to stderr (I will likely start using the log crate soon…) and the atlas will be cleared each frame, leading to a big slowdown.

I believe this could happen if you load a big font (which supports tens of thousands of glyphs) and open the Font Book in the demo (which will paint all glyphs in the font), but otherwise I hope this will be extremely rare.

For now I think this is a reasonable limitation, as a more robust solution would require multiple font textures which will complicate text painting (needing to switch textures mid-mesh), or require a completely different way of rendering text.

(*) All of ASCII is currently pre-cached for each font, but this might change

@emilk emilk changed the title Choose your own font and isze Choose your own font and size Jan 24, 2022
@emilk emilk merged commit fa43d16 into master Jan 24, 2022
@emilk emilk deleted the fonts-refactor branch January 24, 2022 13:32
emilk added a commit that referenced this pull request Jan 24, 2022
In #1154 the default was set to
16k x 512, which is way excessive, as most of it will be blank.

This PR changes it to 8k x 64, which will make egui
use less RAM and VRAM, and load quicker again.

This also decreases the max size from 16k² to 8k².
That should be enough.
emilk added a commit that referenced this pull request Jan 25, 2022
In #1154 the default was set to
16k x 512, which is way excessive, as most of it will be blank.

This PR changes it to 8k x 64, which will make egui
use less RAM and VRAM, and load quicker again.

This also decreases the max size from 16k² to 8k².
That should be enough.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants