Rich Text¶
keyed_extras.rich_text
¶
Rich text rendering with Pango.
WrapMode
¶
Markup
¶
Create PangoMarkup strings.
Use this in conjuction with RichText(use_markup=True, ...)
.
Example
span
¶
span(text, color=None, font=None, size=None, weight=None, style=None, underline=None, strikethrough=None, background=None, stretch=None, letter_spacing=None)
Add a formatted span of text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text content |
required |
color
|
str | tuple[float, float, float] | None
|
Text color as hex string (#RRGGBB) or RGB tuple (0-1) |
None
|
font
|
str | None
|
Font family name |
None
|
size
|
int | None
|
Font size in points (multiplied by Pango.SCALE) |
None
|
weight
|
int | None
|
Font weight from FontWeight constants |
None
|
style
|
int | None
|
Font style from FontStyle constants |
None
|
underline
|
bool | None
|
Whether to underline the text |
None
|
strikethrough
|
bool | None
|
Whether to strike through the text |
None
|
background
|
str | tuple[float, float, float] | None
|
Background color as hex string or RGB tuple |
None
|
stretch
|
int | None
|
Font stretch (condensed, expanded) |
None
|
letter_spacing
|
int | None
|
Spacing between letters in Pango units |
None
|
Returns:
Type | Description |
---|---|
Self
|
self |
RichText
¶
Bases: Base
Rich text that can be drawn with complex styling using Pango.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene
|
Scene
|
The scene to which the text belongs |
required |
text
|
HasValue[str]
|
Text or markup string to display |
required |
width
|
HasValue[float]
|
Maximum width for wrapping text (0 for no wrapping) |
0
|
x
|
HasValue[float] | None
|
X position (left side of text box when no path is used) |
None
|
y
|
HasValue[float] | None
|
Y position (top side of text box when no path is used) |
None
|
font
|
str
|
Default font family name |
'Sans'
|
size
|
HasValue[float]
|
Default font size in points |
24
|
color
|
tuple[float, float, float] | HasValue[Color]
|
Default RGB color tuple |
(1, 1, 1)
|
alpha
|
HasValue[float]
|
Opacity from 0-1 |
1.0
|
alignment
|
int
|
Text alignment (not used when on path) |
LEFT
|
wrap_mode
|
int
|
Text wrapping mode (not used when on path) |
WORD
|
operator
|
Operator
|
Cairo operator for blending |
OPERATOR_OVER
|
use_markup
|
bool
|
Whether to interpret the text as Pango markup |
False
|
line_spacing
|
HasValue[float]
|
Additional spacing between lines (not used when on path) |
1.0
|
indent
|
HasValue[float]
|
First line indent in pixels (not used when on path) |
0.0
|
path
|
HasValue[LineString] | list[Tuple[float, float]] | None
|
None
|
|
path_offset
|
HasValue[float]
|
Distance along the path to start text (in 0-1) (used when path is provided) |
0.0
|
path_spacing
|
HasValue[float]
|
Spacing factor between characters (used when path is provided) |
1.0
|
align_perpendicular
|
bool
|
Whether to align glyphs perpendicular to the path (used when path is provided) |
True
|