pyglet.text.layout
¶Render simple text and formatted documents efficiently.
Three layout classes are provided:
The entire document is laid out before it is rendered. The layout will be grouped with other layouts in the same batch (allowing for efficient rendering of multiple layouts).
Any change to the layout or document, and even querying some properties, will cause the entire document to be laid out again.
Based on TextLayout.
A separate group is used for layout which crops the contents of the
layout to the layout rectangle. Additionally, the contents of the
layout can be “scrolled” within that rectangle with the view_x
and
view_y
properties.
Based on ScrollableTextLayout.
When the layout or document are modified, only the affected regions are laid out again. This permits efficient interactive editing and styling of text.
Only the visible portion of the layout is actually rendered; as the viewport is scrolled additional sections are rendered and discarded as required. This permits efficient viewing and editing of large documents.
Additionally, this class provides methods for locating the position of a caret in the document, and for displaying interactive text selections.
All three layout classes can be used with either UnformattedDocument or
FormattedDocument, and can be either single-line or multiline
. The
combinations of these options effectively provides 12 different text display
possibilities.
The following character style attribute names are recognised by the layout classes. Data types and units are as specified.
Where an attribute is marked “as a distance” the value is assumed to be
in pixels if given as an int or float, otherwise a string of the form
"0u"
is required, where 0
is the distance and u
is the unit; one
of "px"
(pixels), "pt"
(points), "pc"
(picas), "cm"
(centimeters), "mm"
(millimeters) or "in"
(inches). For example,
"14pt"
is the distance covering 14 points, which at the default DPI of 96
is 18 pixels.
font_name
font_size
bold
italic
underline
kerning
baseline
color
background_color
None
for no background fill.The following paragraph style attribute names are recognised. Note that paragraph styles are handled no differently from character styles by the document: it is the application’s responsibility to set the style over an entire paragraph, otherwise results are undefined.
align
left
(default), center
or right
.indent
leading
line_spacing
None
, which automatically calculates the tightest line
spacing for each line based on the font ascent and descent.margin_left
margin_right
margin_top
margin_bottom
tab_stops
wrap
char
, word
, True (default) or False. The boundaries at which to
wrap text to prevent it overflowing a line. With char
, the line
wraps anywhere in the text; with word
or True, the line wraps at
appropriate boundaries between words; with False the line does not wrap,
and may overflow the layout width. char
and word
styles are
since pyglet 1.2.Other attributes can be used to store additional style information within the document; they will be ignored by the built-in text classes.
Note
Since pyglet 1.1
IncrementalTextLayout |
Displayed text suitable for interactive editing and/or scrolling large documents. |
ScrollableTextLayout |
Display text in a scrollable viewport. |
ScrollableTextLayoutGroup |
Top-level rendering group for ScrollableTextLayout. |
TextLayout |
Lay out and display documents. |
TextLayoutForegroundDecorationGroup |
Rendering group for decorative elements (e.g., glyph underlines) in all text layouts. |
TextLayoutForegroundGroup |
Rendering group for foreground elements (glyphs) in all text layouts. |
TextLayoutGroup |
Top-level rendering group for TextLayout. |
TextLayoutTextureGroup |
Rendering group for a glyph texture in all text layouts. |
compat_platform
= 'linux2'¶str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
Defined
event
gl
glext_arb
glu
graphics
lib
lib_glx
re
runlist
sys