Text: Handle drawing of text

_REF

Text: Handle drawing of text

class pymt.core.text.LabelBase(label, **kwargs)

Bases: pymt.baseobject.BaseObject

Core text label. This is the abstract class used for different backend to render text.

Warning

The core text label can’t be changed at runtime, you must recreate one.

Parameters :
font_size: int, default to 12

Font size of the text

font_name: str, default to DEFAULT_FONT

Font name of the text

bold: bool, default to False

Activate “bold” text style

italic: bool, default to False

Activate “italic” text style

size: list, default to (None, None)

Add constraint to render the text (inside a bounding box) If no size is given, the label size will be adapted from the text size.

anchor_x: str, default to “left”

Indicate what represent the X position inside the bounding box. Can be one of “left”, “center”, “right”.

anchor_y: str, default to “bottom”

Indicate what represent the Y position inside the bounding box. Can be one of “top”, “middle”, “bottom”.

padding: int, default to None

If it’s a integer, it will set padding_x and padding_y

padding_x: int, default to 0

Left/right padding

padding_y: int, default to 0

Top/bottom padding

halign: str, default to “left”

Horizontal text alignement inside bounding box

valign: str, default to “bottom”

Vertical text alignement inside bounding box

color: list, default to (1, 1, 1, 1)

Text color in (R, G, B, A)

viewport_pos: list, default to None

An bottom/left position of the viewport inside the label texture. This property is used only if viewport_size is set.

viewport_size: list, default to None

Width/height of the viewport, if you don’t want to show the whole texture. This could be used to limit the drawing of the label to a certain zone, and prevent to drawing outside the viewport. If the label have a size of (1800, 25) with a viewport_size of (100, 100), the drawing will not go outside the viewport, but start from (0, 0). If you want to draw another part of the texture, use viewport_pos.

content_height

Return the content height

content_size

Return the content size (width, height)

content_width

Return the content width

draw()

Draw the label

fontid

Return an uniq id for all font parameters

get_extents(text)

Return a tuple with (width, height) for a text.

label

Get/Set the label text

refresh()

Force re-rendering of the label

render(real=False)

Return a tuple(width, height) to create the image with the user constraints.

2 differents methods are used:
  • if user don’t set width, splitting line and calculate max width + height
  • if user set a width, blit per glyph
text

Get/Set the label text

Previous topic

SVG: handle loading of svg data

Next topic

MarkupLabel: Handle drawing of text with markup

This Page