pyglet.text.layout

Render simple text and formatted documents efficiently.

Three layout classes are provided:

TextLayout

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.

ScrollableTextLayout

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.

IncrementalTextLayout

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.

Style attributes

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 family name, as given to pyglet.font.load().

font_size

Font size, in points.

bold

Boolean.

italic

Boolean.

underline

4-tuple of ints in range (0, 255) giving RGBA underline color, or None (default) for no underline.

kerning

Additional space to insert between glyphs, as a distance. Defaults to 0.

baseline

Offset of glyph baseline from line baseline, as a distance. Positive values give a superscript, negative values give a subscript. Defaults to 0.

color

4-tuple of ints in range (0, 255) giving RGBA text color

background_color

4-tuple of ints in range (0, 255) giving RGBA text background color; or 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

Additional horizontal space to insert before the first glyph of the first line of a paragraph, as a distance.

leading

Additional space to insert between consecutive lines within a paragraph, as a distance. Defaults to 0.

line_spacing

Distance between consecutive baselines in a paragraph, as a distance. Defaults to None, which automatically calculates the tightest line spacing for each line based on the font ascent and descent.

margin_left

Left paragraph margin, as a distance.

margin_right

Right paragraph margin, as a distance.

margin_top

Margin above paragraph, as a distance.

margin_bottom

Margin below paragraph, as a distance. Adjacent margins do not collapse.

tab_stops

List of horizontal tab stops, as distances, measured from the left edge of the text layout. Defaults to the empty list. When the tab stops are exhausted, they implicitly continue at 50 pixel intervals.

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.

Other attributes can be used to store additional style information within the document; they will be ignored by the built-in text classes.

class IncrementalTextDecorationGroup
scissor_area: ClassVar[tuple[int, int, int, int]] = (0, 0, 0, 0)
class IncrementalTextLayout

Displayed text suitable for interactive editing and/or scrolling large documents.

Unlike TextLayout() and ScrollableTextLayout, this class generates vertex lists only for lines of text that are visible. As the document is scrolled, vertex lists are deleted and created as appropriate to keep video memory usage to a minimum and improve rendering speed.

Changes to the document are quickly reflected in this layout, as only the affected line(s) are reflowed. Use begin_update() and end_update() to further reduce the amount of processing required.

The layout can also display a text selection (text with a different background color). The Caret class implements a visible text cursor and provides event handlers for scrolling, selecting and editing text in an incremental text layout.

Class Variables:
  • group_class (ClassVar[type[IncrementalTextLayoutGroup]]) – Default group used to set the state for all glyphs.

  • decoration_class (ClassVar[type[IncrementalTextDecorationGroup]]) – Default group used to set the state for all decorations including background colors and underlines.

__init__(
document: AbstractDocument,
width: int,
height: int,
x: float = 0,
y: float = 0,
z: float = 0,
anchor_x: Literal['left', 'center', 'right'] = 'left',
anchor_y: Literal['top', 'bottom', 'center', 'baseline'] = 'bottom',
rotation: float = 0,
multiline: bool = False,
dpi: float | None = None,
batch: Batch | None = None,
group: Group | None = None,
program: ShaderProgram | None = None,
wrap_lines: bool = True,
) None

Initialize a text layout.

Parameters:
  • document (AbstractDocument) – Document to display.

  • x (float) – X coordinate of the label.

  • y (float) – Y coordinate of the label.

  • z (float) – Z coordinate of the label.

  • width (int) – Width of the layout in pixels, or None

  • height (int) – Height of the layout in pixels, or None

  • anchor_x (Literal['left', 'center', 'right']) – Anchor point of the X coordinate.

  • anchor_y (Literal['top', 'bottom', 'center', 'baseline']) – Anchor point of the Y coordinate.

  • rotation (float) – The amount to rotate the label in degrees. A positive amount will be a clockwise rotation, negative values will result in counter-clockwise rotation.

  • multiline (bool) – If False, newline and paragraph characters are ignored, and text is not word-wrapped. If True, text is wrapped only if the wrap_lines is True.

  • dpi (float | None) – Font resolution; defaults to 96.

  • batch (Batch | None) – Optional graphics batch to add this layout to.

  • group (Group | None) – Optional Group to parent all internal Groups that this text layout uses. Note that layouts with the same Groups will be rendered simultaneously in a Batch.

  • program (ShaderProgram | None) – Optional graphics shader to use. Will affect all glyphs in the layout.

  • wrap_lines (bool) – If True and multiline is True, the text is word-wrapped using the specified width.

  • init_document – If True the document will be initialized. If subclassing then you may want to avoid duplicate initializations by changing to False.

delete() None

Deletes all vertices and boxes associated with the layout.

Return type:

None

ensure_line_visible(line_idx: int) None

Adjust view_y so that the line with the given index is visible.

Return type:

None

ensure_x_visible(x: float) None

Adjust view_x so that the given X coordinate is visible.

The X coordinate is given relative to the current view_x.

Return type:

None

get_line_count() int

Get the number of lines in the text layout.

Return type:

int

get_line_from_point(x: float, y: float) int

Get the closest line index to a point.

Return type:

int

get_line_from_position(position: int) int

Get the line index of a character position in the document.

Return type:

int

get_point_from_line(line_idx: int) tuple[float, float]

Get the X, Y coordinates of a line index.

Return type:

tuple[float, float]

get_point_from_position(
position: int,
line_idx: int | None = None,
) tuple[float, float]

Get the X, Y coordinates of a character position in the document.

The position that ends a line has an ambiguous point: it can be either the end of the line, or the beginning of the next line. You may optionally specify a line index to disambiguate the case.

The resulting Y coordinate gives the baseline of the line.

Return type:

tuple[float, float]

get_position_from_line(line_idx: int) int

Get the first document character position of a given line index.

Return type:

int

get_position_from_point(x: float, y: float) int

Get the closest document position to a point.

Return type:

int

get_position_on_line(line_idx: int, x: float) int

Get the closest document position for a given line index and X coordinate.

Return type:

int

on_delete_text(start: int, end: int) None

Event handler for AbstractDocument.on_delete_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

Return type:

None

on_insert_text(start: int, text: str) None

Event handler for AbstractDocument.on_insert_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

Return type:

None

on_layout_update() None

Some or all of the layout text was reflowed.

Text reflow is caused by document edits or changes to the layout’s size. Changes to the layout’s position or active selection, and certain document edits such as text color, do not cause a reflow.

Handle this event to update the position of a graphical element that depends on the laid out position of a glyph or line.

Event:

Return type:

None

on_style_text(
start: int,
end: int,
attributes: dict[str, Any],
) None

Event handler for AbstractDocument.on_style_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

Return type:

None

set_selection(start: int, end: int) None

Set the text selection range.

If start equals end no selection will be visible.

Parameters:
  • start (int) – Starting character position of selection.

  • end (int) – End of selection, exclusive.

Return type:

None

property anchor_x: Literal['left', 'center', 'right']

Horizontal anchor alignment.

This property determines the meaning of the x coordinate.

The following values are supported:

"left" (default)

The X coordinate gives the position of the left edge of the layout.

"center"

The X coordinate gives the position of the center of the layout.

"right"

The X coordinate gives the position of the right edge of the layout.

For the purposes of calculating the position resulting from this alignment, the width of the layout is taken to be width if multiline is True and wrap_lines is True, otherwise content_width.

property anchor_y: Literal['top', 'bottom', 'center', 'baseline']

Vertical anchor alignment.

This property determines the meaning of the y coordinate.

The following values are supported:

"top"

The Y coordinate gives the position of the top edge of the layout.

"center"

The Y coordinate gives the position of the center of the layout.

"baseline"

The Y coordinate gives the position of the baseline of the first line of text in the layout.

"bottom" (default)

The Y coordinate gives the position of the bottom edge of the layout.

For the purposes of calculating the position resulting from this alignment, the height of the layout is taken to be the smallest of height and content_height.

See also content_valign.

event_types: list = ['on_layout_update', 'on_translation_update']
property height: int

The defined maximum height of the layout in pixels, or None

When height is not None, it affects the positioning of the text when anchor_y and content_valign are used.

lines: list[_Line]
property multiline: bool

Set if multiline layout is enabled.

If multiline is False, newline and paragraph characters are ignored and text is not word-wrapped. If True, the text is word-wrapped only if the wrap_lines is True.

property position: tuple[float, float, float]

The (X, Y, Z) coordinates of the layout, as a tuple.

See also anchor_x, and anchor_y.

property rotation: float

Rotation will always be 0 as incremental layouts cannot be rotated.

Raises:

NotImplementedError – Rotating IncrementalTextLayout’s is not supported.

property selection_background_color: tuple[int, int, int, int]

Background color of active selection.

The color is an RGBA tuple with components in range [0, 255].

property selection_color: tuple[int, int, int, int]

Text color of active selection.

The color is an RGBA tuple with components in range [0, 255].

property selection_end: int

End position of the active selection (exclusive).

See:

py:meth:~pyglet.text.layout.IncrementalTextLayout.set_selection

property selection_start: int

Starting position of the active selection.

See:

py:meth:~pyglet.text.layout.IncrementalTextLayout.set_selection

property view_x: int

Horizontal scroll offset.

The initial value is 0, and the left edge of the text will touch the left side of the layout bounds. A positive value causes the text to “scroll” to the right. Values are automatically clipped into the range [0, content_width - width]

property view_y: int

Vertical scroll offset.

The initial value is 0, and the top of the text will touch the top of the layout bounds (unless the content height is less than the layout height, in which case content_valign is used).

A negative value causes the text to “scroll” upwards. Values outside of the range [height - content_height, 0] are automatically clipped in range.

property width: int

The defined maximum width of the layout in pixels, or None

If multiline and wrap_lines is True, the width defines where the text will be wrapped. If multiline is False or wrap_lines is False, this property has no effect.

property x: float

X coordinate of the layout.

See also anchor_x.

property y: float

Y coordinate of the layout.

See also anchor_y.

property z: float

Z coordinate of the layout.

class IncrementalTextLayoutGroup
scissor_area: ClassVar[tuple[int, int, int, int]] = (0, 0, 0, 0)
class ScrollableTextDecorationGroup

Create a text decoration rendering group.

The group is created internally when a Label is created; applications usually do not need to explicitly create it.

__init__(
program: ShaderProgram,
order: int = 0,
parent: Group | None = None,
) None
set_state() None

Apply the OpenGL state change.

The default implementation does nothing.

Return type:

None

unset_state() None

Repeal the OpenGL state change.

The default implementation does nothing.

Return type:

None

scissor_area: ClassVar[tuple[int, int, int, int]] = (0, 0, 0, 0)
class ScrollableTextLayout

Display text in a scrollable viewport.

This class does not display a scrollbar or handle scroll events; it merely clips the text that would be drawn in TextLayout() to the bounds of the layout given by x, y, width and height; and offsets the text by a scroll offset.

Use view_x and view_y to scroll the text within the viewport.

Class Variables:
  • group_class (ClassVar[type[ScrollableTextLayoutGroup]]) – Default group used to set the state for all glyphs.

  • decoration_class (ClassVar[type[ScrollableTextDecorationGroup]]) – Default group used to set the state for all decorations including background colors and underlines.

__init__(
document: AbstractDocument,
width: int,
height: int,
x: float = 0,
y: float = 0,
z: float = 0,
anchor_x: Literal['left', 'center', 'right'] = 'left',
anchor_y: Literal['top', 'bottom', 'center', 'baseline'] = 'bottom',
rotation: float = 0,
multiline: bool = False,
dpi: float | None = None,
batch: Batch | None = None,
group: Group | None = None,
program: ShaderProgram | None = None,
wrap_lines: bool = True,
) None

Initialize a text layout.

Parameters:
  • document (AbstractDocument) – Document to display.

  • x (float) – X coordinate of the label.

  • y (float) – Y coordinate of the label.

  • z (float) – Z coordinate of the label.

  • width (int) – Width of the layout in pixels, or None

  • height (int) – Height of the layout in pixels, or None

  • anchor_x (Literal['left', 'center', 'right']) – Anchor point of the X coordinate.

  • anchor_y (Literal['top', 'bottom', 'center', 'baseline']) – Anchor point of the Y coordinate.

  • rotation (float) – The amount to rotate the label in degrees. A positive amount will be a clockwise rotation, negative values will result in counter-clockwise rotation.

  • multiline (bool) – If False, newline and paragraph characters are ignored, and text is not word-wrapped. If True, text is wrapped only if the wrap_lines is True.

  • dpi (float | None) – Font resolution; defaults to 96.

  • batch (Batch | None) – Optional graphics batch to add this layout to.

  • group (Group | None) – Optional Group to parent all internal Groups that this text layout uses. Note that layouts with the same Groups will be rendered simultaneously in a Batch.

  • program (ShaderProgram | None) – Optional graphics shader to use. Will affect all glyphs in the layout.

  • wrap_lines (bool) – If True and multiline is True, the text is word-wrapped using the specified width.

  • init_document – If True the document will be initialized. If subclassing then you may want to avoid duplicate initializations by changing to False.

property anchor_x: Literal['left', 'center', 'right']

Horizontal anchor alignment.

This property determines the meaning of the x coordinate.

The following values are supported:

"left" (default)

The X coordinate gives the position of the left edge of the layout.

"center"

The X coordinate gives the position of the center of the layout.

"right"

The X coordinate gives the position of the right edge of the layout.

For the purposes of calculating the position resulting from this alignment, the width of the layout is taken to be width if multiline is True and wrap_lines is True, otherwise content_width.

property anchor_y: Literal['top', 'bottom', 'center', 'baseline']

Vertical anchor alignment.

This property determines the meaning of the y coordinate.

The following values are supported:

"top"

The Y coordinate gives the position of the top edge of the layout.

"center"

The Y coordinate gives the position of the center of the layout.

"baseline"

The Y coordinate gives the position of the baseline of the first line of text in the layout.

"bottom" (default)

The Y coordinate gives the position of the bottom edge of the layout.

For the purposes of calculating the position resulting from this alignment, the height of the layout is taken to be the smallest of height and content_height.

See also content_valign.

property position: tuple[float, float, float]

The (X, Y, Z) coordinates of the layout, as a tuple.

See also anchor_x, and anchor_y.

property view_x: int

Horizontal scroll offset.

The initial value is 0, and the left edge of the text will touch the left side of the layout bounds. A positive value causes the text to “scroll” to the right. Values are automatically clipped into the range [0, content_width - width]

property view_y: int

Vertical scroll offset.

The initial value is 0, and the top of the text will touch the top of the layout bounds (unless the content height is less than the layout height, in which case content_valign is used).

A negative value causes the text to “scroll” upwards. Values outside of the range [height - content_height, 0] are automatically clipped in range.

property x: float

X coordinate of the layout.

See also anchor_x.

property y: float

Y coordinate of the layout.

See also anchor_y.

property z: float

Z coordinate of the layout.

class ScrollableTextLayoutGroup

Default rendering group for ScrollableTextLayout.

The group maintains internal state for specifying the viewable area, and for scrolling. Because the group has internal state specific to the text layout, the group is never shared.

__init__(
texture: Texture,
program: ShaderProgram,
order: int = 1,
parent: Group | None = None,
) None
set_state() None

Apply the OpenGL state change.

The default implementation does nothing.

Return type:

None

unset_state() None

Repeal the OpenGL state change.

The default implementation does nothing.

Return type:

None

scissor_area: ClassVar[tuple[int, int, int, int]] = (0, 0, 0, 0)
class TextDecorationGroup

Create a text decoration rendering group.

The group is created internally when a Label is created; applications usually do not need to explicitly create it.

__init__(
program: ShaderProgram,
order: int = 0,
parent: Group | None = None,
) None
set_state() None

Apply the OpenGL state change.

The default implementation does nothing.

Return type:

None

unset_state() None

Repeal the OpenGL state change.

The default implementation does nothing.

Return type:

None

class TextLayout

Lay out and display documents.

This class is intended for displaying documents.

Label() and HTMLLabel() provide a convenient interface to this class.

Some properties may cause the document to be recreated rather than updated. Refer to property documentation for details.

Class Variables:
__init__(
document: AbstractDocument,
width: int | None = None,
height: int | None = None,
x: float = 0,
y: float = 0,
z: float = 0,
anchor_x: Literal['left', 'center', 'right'] = 'left',
anchor_y: Literal['top', 'bottom', 'center', 'baseline'] = 'bottom',
rotation: float = 0,
multiline: bool = False,
dpi: float | None = None,
batch: Batch | None = None,
group: Group | None = None,
program: ShaderProgram | None = None,
wrap_lines: bool = True,
init_document: bool = True,
) None

Initialize a text layout.

Parameters:
  • document (AbstractDocument) – Document to display.

  • x (float) – X coordinate of the label.

  • y (float) – Y coordinate of the label.

  • z (float) – Z coordinate of the label.

  • width (int | None) – Width of the layout in pixels, or None

  • height (int | None) – Height of the layout in pixels, or None

  • anchor_x (Literal['left', 'center', 'right']) – Anchor point of the X coordinate.

  • anchor_y (Literal['top', 'bottom', 'center', 'baseline']) – Anchor point of the Y coordinate.

  • rotation (float) – The amount to rotate the label in degrees. A positive amount will be a clockwise rotation, negative values will result in counter-clockwise rotation.

  • multiline (bool) – If False, newline and paragraph characters are ignored, and text is not word-wrapped. If True, text is wrapped only if the wrap_lines is True.

  • dpi (float | None) – Font resolution; defaults to 96.

  • batch (Batch | None) – Optional graphics batch to add this layout to.

  • group (Group | None) – Optional Group to parent all internal Groups that this text layout uses. Note that layouts with the same Groups will be rendered simultaneously in a Batch.

  • program (ShaderProgram | None) – Optional graphics shader to use. Will affect all glyphs in the layout.

  • wrap_lines (bool) – If True and multiline is True, the text is word-wrapped using the specified width.

  • init_document (bool) – If True the document will be initialized. If subclassing then you may want to avoid duplicate initializations by changing to False.

begin_update() None

Indicate that a number of changes to the layout or document are about to occur.

Changes to the layout or document between calls to begin_update and end_update do not trigger any costly relayout of text. Relayout of all changes is performed when end_update is called.

Note that between the begin_update and end_update calls, values such as content_width and content_height are undefined (i.e., they may or may not be updated to reflect the latest changes).

Return type:

None

delete() None

Deletes all vertices and boxes associated with the layout.

Return type:

None

draw() None

Draw this text layout. :rtype: None

Note

This method performs very badly if a batch was supplied to the constructor. If you add this layout to a batch, you should ideally use only the batch’s draw method.

Note

If this is not its own batch, InlineElements will not be drawn.

end_update() None

Perform pending layout changes since begin_update.

See begin_update.

Return type:

None

get_as_texture(
min_filter: int = 9728,
mag_filter: int = 9728,
) Texture

Utilizes a Framebuffer to draw the current layout into a texture.

Warning

Usage is recommended only if you understand how texture generation affects your application. Improper use will cause texture memory leaks and performance degradation.

Note

Does not include InlineElements.

Return type:

Texture

Returns:

A new texture with the layout drawn into it.

New in version 2.0.11.

on_delete_text(start: int, end: int) None

Event handler for AbstractDocument.on_delete_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

Return type:

None

on_insert_text(start: int, text: str) None

Event handler for AbstractDocument.on_insert_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

Return type:

None

on_style_text(
start: int,
end: int,
attributes: dict[str, Any],
) None

Event handler for AbstractDocument.on_style_text.

The event handler is bound by the text layout; there is no need for applications to interact with this method.

Return type:

None

property anchor_x: Literal['left', 'center', 'right']

Horizontal anchor alignment.

This property determines the meaning of the x coordinate.

The following values are supported:

"left" (default)

The X coordinate gives the position of the left edge of the layout.

"center"

The X coordinate gives the position of the center of the layout.

"right"

The X coordinate gives the position of the right edge of the layout.

For the purposes of calculating the position resulting from this alignment, the width of the layout is taken to be width if multiline is True and wrap_lines is True, otherwise content_width.

property anchor_y: Literal['top', 'bottom', 'center', 'baseline']

Vertical anchor alignment.

This property determines the meaning of the y coordinate.

The following values are supported:

"top"

The Y coordinate gives the position of the top edge of the layout.

"center"

The Y coordinate gives the position of the center of the layout.

"baseline"

The Y coordinate gives the position of the baseline of the first line of text in the layout.

"bottom" (default)

The Y coordinate gives the position of the bottom edge of the layout.

For the purposes of calculating the position resulting from this alignment, the height of the layout is taken to be the smallest of height and content_height.

See also content_valign.

property batch: Batch

The Batch that this Layout is assigned to.

If no Batch is assigned, an internal Batch is created and used.

property bottom: float

The y-coordinate of the bottom side of the layout.

property content_height: int

The calculated height of the text in the layout.

This is the actual height of the text in pixels, not the user defined height.

property content_valign: Literal['left', 'center', 'top']

Vertical alignment of content within larger layout box.

This property determines how content is positioned within the layout box when content_height is less than height.

The following values are supported:

top (default)

Content is aligned to the top of the layout box.

center

Content is centered vertically within the layout box.

bottom

Content is aligned to the bottom of the layout box.

This property has no effect when content_height is greater than height (in which case the content is aligned to the top) or when height is None (in which case there is no vertical layout box dimension).

property content_width: int

Calculated width of the text in the layout.

This is the actual width of the text in pixels, not the user defined width. The content width may overflow the layout width if word-wrapping is not possible.

property document: AbstractDocument

Document to display.

For IncrementalTextLayout it is far more efficient to modify a document in-place than to replace the document instance on the layout.

property dpi: float

Get DPI used by this layout.

property group: Group | None

Get the Group specified by the user.

Changing a group will cause the layout to be recreated.

property height: int | None

The defined maximum height of the layout in pixels, or None

When height is not None, it affects the positioning of the text when anchor_y and content_valign are used.

property left: float

The x-coordinate of the left side of the layout.

property multiline: bool

Set if multiline layout is enabled.

If multiline is False, newline and paragraph characters are ignored and text is not word-wrapped. If True, the text is word-wrapped only if the wrap_lines is True.

property position: tuple[float, float, float]

The (X, Y, Z) coordinates of the layout, as a tuple.

See also anchor_x, and anchor_y.

property program: ShaderProgram

The ShaderProgram that is assigned to this Layout.

If set, the shader will impact all Glyphs. InlineElements will not be affected.

property right: float

The x-coordinate of the right side of the layout

property rotation: float

Rotation of the layout in degrees. Rotated based on the anchor of the layout.

Negative values will rotate in reverse.

See anchor_x, and anchor_y.

property top: float

The y-coordinate of the top side of the layout.

property visible: bool

True if the layout will be visible when drawn.

property width: int | None

The defined maximum width of the layout in pixels, or None

If multiline and wrap_lines is True, the width defines where the text will be wrapped. If multiline is False or wrap_lines is False, this property has no effect.

property x: float

X coordinate of the layout.

See also anchor_x.

property y: float

Y coordinate of the layout.

See also anchor_y.

property z: float

Z coordinate of the layout.

class TextLayoutGroup

Create a text layout rendering group.

The group is created internally when a Label is created; applications usually do not need to explicitly create it.

__init__(
texture: Texture,
program: ShaderProgram,
order: int = 1,
parent: Group | None = None,
) None
set_state() None

Apply the OpenGL state change.

The default implementation does nothing.

Return type:

None

unset_state() None

Repeal the OpenGL state change.

The default implementation does nothing.

Return type:

None

get_default_decoration_shader() ShaderProgram

The default shader for underline and background decoration effects in the layout.

Return type:

ShaderProgram

get_default_image_layout_shader() ShaderProgram

The default shader used for an InlineElement image. Used for HTML Labels that insert images via <img> tag.

Return type:

ShaderProgram

get_default_layout_shader() ShaderProgram

The default shader used for all glyphs in the layout.

Return type:

ShaderProgram