Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions arcade/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,39 @@ def position(self, point: Point):
else:
self._label.position = x, y, self._label.z

@property
def tracking(self) -> float | None:
"""
Get/set the tracking amount for this text object, or rather,
the added space between each character.

The value is an amount in pixels and can be negative.
To convert from the em unit, use Text.em_to_px().

Returns:
a pixel amount, or None if the tracking is inconsistent.
"""
kerning = self._label.get_style("kerning")
return kerning if kerning != pyglet.text.document.STYLE_INDETERMINATE else None

@tracking.setter
def tracking(self, value: float):
self._label.set_style("kerning", value)

def em_to_px(self, em: float) -> float:
"""Convert from an em value to a pixel amount.

1em is defined as ``font_size`` pt.
"""
return (em * self.font_size) * (4 / 3)

def px_to_em(self, px: float) -> float:
"""Convert from a pixel amount to a value in ems.

1em is defined as ``font_size`` pt.
"""
return px / (4 / 3) / self.font_size


def create_text_sprite(
text: str,
Expand Down
Loading