Repository navigation
Add a Drawing Text programming guide page - #2924
Merged
Merged
Conversation
- New doc/programming_guide/text.rst: choosing between draw_text, Text, TextPool, and create_text_sprite; what's slow and fast to change; with blocks and batches; fonts, font files, and the bundled Kenney and Liberation fonts; bold weights, italic, and gradient colors; anchors and layout. Linked from the Manual table of contents. - Rewrite the text section of the performance tips, which still called draw_text the slowest thing aside from disk access. - Make the draw_text warning and docstring match measurements: an unchanged call costs about the same as Text.draw(), while changing text, many lines, and batches are where Text objects win. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR 7 of the text improvements: text documentation.
1. New programming guide page: "Drawing Text"
doc/programming_guide/text.rst, linked in the Manual table of contents after Textures. Until now, the guide had no page on text. It covers:draw_text,Text,TextPoolandcreate_text_sprite, with what each is best for.Text: creating (~0.6 ms), drawing (~30 µs), moving or recoloring (almost free), and changing the text or style (lays it out again). Setting an unchanged value is free since Skip unneeded Text layouts for unchanged values and with blocks #2921, andwith text:groups changes into one layout.Textobjects drawn one at a time took ~570 µs, and in one batch ~30 µs.TextPooland text sprites.load_fontand using the font's name;load_kenney_fonts()/load_liberation_fonts().boldweights,italic/"oblique", andLinearGradientcolors (since Fix Text italic, bold strings, gradient colors, and swallowed errors #2920).Every code example on the page runs, and I checked the font names against what actually loads. One finding from that: on Windows,
"Kenney Future Narrow"can't be found by name, because DirectWrite treats it as a narrower width of"Kenney Future". It falls back to the default font. The page has a note: on Windows, usefont_name="Kenney Future", stretch="semicondensed", which I verified there. I couldn't check Linux or macOS.2. Performance tips
The "Text drawing performance" section still called
draw_text"the slowest thing aside from disk access". It's now a short list: useTextobjects, change position and color freely but not the text, usewith text:, use batches, useTextPool, and use text sprites for static text that moves. It links to the new page.3.
draw_textwarning and docstringTextobjects, "especially for many lines or changing text".Textobjects "can be 10-100 times faster". For one unchanged line I measured 31 µs fordraw_textagainst 27 µs forText.draw(). The difference is in changing text, many lines, and batches, so the docstring now says that and links to the guide. I kept "might be removed in the near future", since that's a project decision.Checks
sphinx-build -W, the same as CI'sdocs-full, with no warnings. All the new page's API and:ref:links resolve.pyglet.text.LinearGradientshows as code without a link, because pyglet's docs don't index it.The changelog has an entry under Unreleased → Misc Changes.
🤖 Generated with Claude Code