InlineElement Class

Inheritance diagram of InlineElement

class InlineElement(ascent, descent, advance)

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.

Variables:
  • ascent – Ascent of the element above the baseline, in pixels.
  • descent – Descent of the element below the baseline, in pixels. Typically negative.
  • advance – Width of the element, in pixels.

Constructor:

__init__(ascent, descent, advance)

Methods:

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

Attributes:

position Position of the element within the document.

Methods

InlineElement.place(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.
InlineElement.remove(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.

Attributes

InlineElement.position

Position of the element within the document. Read-only.

Type:int

Table Of Contents

Previous topic

FormattedDocument Class

Next topic

UnformattedDocument Class