Class pyglet.text.document.InlineElement

Known Subclasses:
formats.structured.ImageElement

Arbitrary inline element positioned within a formatted document.

Elements behave like a single glyph in the document. They are measured by their horizontal advance, ascent above the baseline, and descent below the baseline.

The pyglet layout classes reserve space in the layout for elements and call the element's methods to ensure they are rendered at the appropriate position.

If the size of a element (any of the advance, ascent, or descent instance variables) is modified it is the application's responsibility to trigger a reflow of the appropriate area in the affected layouts. This can be done by forcing a style change over the element's position.

Methods

  __init__(self, ascent, descent, advance)
  place(self, layout, x, y)
Construct an instance of the element at the given coordinates.
  remove(self, layout)
Remove this element from a layout.

Properties

int position
Position of the element within the document.

Instance Variables

int advance
Width of the element, in pixels.
int ascent
Ascent of the element above the baseline, in pixels.
int descent
Descent of the element below the baseline, in pixels.

Method Details

place

place(self, layout, x, y)

Construct an instance of the element at the given coordinates.

Called when the element's position within a layout changes, either due to the initial condition, changes in the document or changes in the layout size.

It is the responsibility of the element to clip itself against the layout boundaries, and position itself appropriately with respect to the layout's position and viewport offset.

The TextLayout.top_state graphics state implements this transform and clipping into window space.

Parameters:
layout : pyglet.text.layout.TextLayout
The layout the element moved within.
x : int
Position of the left edge of the element, relative to the left edge of the document, in pixels.
y : int
Position of the baseline, relative to the top edge of the document, in pixels. Note that this is typically negative.

remove

remove(self, layout)

Remove this element from a layout.

The counterpart of place; called when the element is no longer visible in the given layout.

Parameters:
layout : pyglet.text.layout.TextLayout
The layout the element was removed from.

Property Details

position

Position of the element within the document. Read-only.
Type:
int

Instance Variable Details

descent

Descent of the element below the baseline, in pixels. Typically negative.
Type:
int