Text Properties
Quick Guide
| Property | Type | Default |
|---|---|---|
text |
str |
None |
font |
str |
None (uses default font) |
font_size |
int |
16 |
text_color |
tuple(r, g, b) |
(255, 255, 255) |
text_align |
CoshTextAlign |
CENTER |
text_justify |
CoshTextJustify |
CENTER |
text_overflow |
CoshTextOverflow |
VISIBLE |
bold |
bool |
False |
italic |
bool |
False |
strikethrough |
bool |
False |
underline |
bool |
False |
Introduction
Any TextNode-based Element — like Label() or Button() — exposes a set of properties to control how its text is rendered. These properties are set directly on the Node itself, not through style, and act as the default style for the whole string.
RichLabel shares these same base properties, but also parses CoshML tags inside text to override styling for specific portions of the string — see CoshML for that.
text
The string content to render.
font
References a font by name from CoshUI's font library, not by file path directly. If font is left as None, the Node falls back to the active default font. See Fonts for registering your own.
# Courier is one of the 3 fonts that comes with CoshUI
cui.Label(id="my_label", text="Styled text", font="Courier")
font_size
Controls the pixel size of the rendered text. Defaults to 16 if not set.
text_color
An (r, g, b) tuple controlling the color of the text. Defaults to white.
bold and italic
These properties require you to add extra font paths for that specific font family when calling add_font(). This is discussed in the Fonts section.
The bold property is boolean value that sets whether the text uses the bold font path.
Whilst the italic property is a boolean value that sets whether the text uses the italic font path.
bold AND italic
Both bold and italic booleans can be set to True if you've passed in a bold_italic font path for that font family.
strikethrough
A boolean value that sets whether the text has a strike line through it.
underline
A boolean value that sets whether the text has an underline below it.
text_align
Controls vertical alignment of the text within the Node's bounds.
| Value | Behavior |
|---|---|
TEXT_ALIGN_TOP |
Text is aligned to the top |
TEXT_ALIGN_CENTER |
Text is vertically centered |
TEXT_ALIGN_BOTTOM |
Text is aligned to the bottom |
text_justify
Controls horizontal alignment of the text within the Node's bounds.
| Value | Behavior |
|---|---|
TEXT_JUSTIFY_LEFT |
Text is aligned to the left |
TEXT_JUSTIFY_CENTER |
Text is horizontally centered |
TEXT_JUSTIFY_RIGHT |
Text is aligned to the right |
text_overflow
Controls what happens when text exceeds the Node's bounds.
| Value | Behavior |
|---|---|
TEXT_VISIBLE |
Text overflows the bounds without being clipped |
TEXT_HIDDEN |
Text is clipped at the Node's bounds |
TEXT_WRAP |
Text wraps onto multiple lines to fit the width |
cui.Label(id="my_label", text="A long sentence that needs wrapping", width=150, text_overflow=cui.TEXT_WRAP)
Auto Sizing
If width or height is left as AUTO, the Node measures the text and sizes itself to fit it exactly.