labels.py

No documentation

class RichTextSegment

Description

Represents a segment of rich text with its formatting.

Attributes:
   text (str): The text content.
   color (Optional[Union[Tuple[int, int, int], Color, ThemeStyle]]):
       Text color (RGB tuple, Color object, or ThemeStyle).
       If None, uses default color.
   bold (bool): Whether text is bold.
   italic (bool): Whether text is italic.
   underline (bool): Whether text is underlined.

Methods
def __init__(self: Any, text: str, color: Optional[Union[Tuple[int, int, int], Color, ThemeStyle]] = None, bold: bool = False, italic: bool = False, underline: bool = False) -> Any
No documentation
def __repr__(self: Any) -> Any
No documentation

class TextLabel

Description

A text label with optional rich text support.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'text': {'name': 'text', 'key': 'text', 'type': str, 'editable': True, 'description': 'The text content of the label.'}, 'color': {'name': 'color', 'key': 'custom_color', 'type': Tuple[int, int, int], 'editable': True, 'description': 'Custom text color (RGB). Overrides theme color.'}, 'font_size': {'name': 'font size', 'key': 'font_size', 'type': int, 'editable': True, 'description': 'Size of the font in pixels.'}, 'font_name': {'name': 'font name', 'key': 'font_name', 'type': Optional[str], 'editable': True, 'description': 'Path to font file or None for default font.'}, 'rich_text': {'name': 'rich text', 'key': 'rich_text', 'type': bool, 'editable': True, 'description': 'Use rich text formatting.'}, 'use_theme_color': {'name': 'use theme color', 'key': 'use_theme_color', 'type': bool, 'editable': True, 'description': 'Use theme color instead of custom color.'}}
Methods
def __init__(self: Any, x: Union[int, float], y: Union[int, float], text: str, font_size: int = 24, color: Optional[Union[Tuple[int, int, int], Color, ThemeStyle]] = None, font_name: Optional[str] = None, rich_text: bool = False, use_theme_color: bool = True, pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, element_id: Optional[str] = None, **kwargs: dict) -> None
No documentation
def can_focus(self: Any) -> bool
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def get_text(self: Any) -> str
No documentation
def update_theme(self: Any, theme_type: ThemeType) -> None
No documentation
def set_text_color(self: Any, color: Union[Tuple[int, int, int], Color, ThemeStyle]) -> None
No documentation
def set_color(self: Any, color: Union[Tuple[int, int, int], Color]) -> None
No documentation
def font(self: Any) -> pygame.font.Font
No documentation
def set_text(self: Any, text: str) -> None
No documentation
def set_theme(self: Any, theme_type: ThemeType) -> None
No documentation
def _get_text_color(self: Any) -> Union[Color, ThemeStyle, Tuple[int, int, int]]
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation

class LongTextLabel

Description

A multi-line text label with optional rich text support and word wrapping.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'text': {'name': 'text', 'key': 'text', 'type': str, 'editable': True, 'description': 'The text content of the label.'}, 'color': {'name': 'color', 'key': 'custom_color', 'type': Tuple[int, int, int], 'editable': True, 'description': 'Custom text color (RGB). Overrides theme color.'}, 'font_size': {'name': 'font size', 'key': 'font_size', 'type': int, 'editable': True, 'description': 'Size of the font in pixels.'}, 'font_name': {'name': 'font name', 'key': 'font_name', 'type': Optional[str], 'editable': True, 'description': 'Path to font file or None for default font.'}, 'rich_text': {'name': 'rich text', 'key': 'rich_text', 'type': bool, 'editable': True, 'description': 'Use rich text formatting.'}, 'line_spacing': {'name': 'line spacing', 'key': 'line_spacing', 'type': int, 'editable': True, 'description': 'Additional spacing between lines in pixels.'}, 'wrap_width': {'name': 'wrap width', 'key': 'wrap_width', 'type': int, 'editable': True, 'description': 'Maximum width before wrapping (0 = no wrap).'}}
Methods
def __init__(self: Any, x: Union[int, float], y: Union[int, float], text: str, width: Optional[int] = None, height: Optional[int] = None, font_size: int = 24, color: Optional[Union[Tuple[int, int, int], Color, ThemeStyle]] = None, font_name: Optional[str] = None, rich_text: bool = False, line_spacing: int = 4, wrap_width: int = 0, pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, element_id: Optional[str] = None, **kwargs: dict) -> None
No documentation
def _calculate_text_size(self: Any, text: str, max_width: int) -> Tuple[int, int]
No documentation
def _wrap_plain_text(self: Any, text: str, max_width: int) -> List[str]
No documentation
def _wrap_rich_text(self: Any, text: str, max_width: int) -> List[List[RichTextSegment]]
No documentation
def _measure_rich_text_line(self: Any, line: List[RichTextSegment]) -> int
No documentation
def set_text_color(self: Any, color: Union[Tuple[int, int, int], Color, ThemeStyle]) -> None
No documentation
def set_text(self: Any, text: str) -> None
No documentation
def get_text(self: Any) -> str
No documentation
def font(self: Any) -> pygame.font.Font
No documentation
def _get_text_color(self: Any) -> Union[Color, ThemeStyle, Tuple[int, int, int]]
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation

class ImageLabel

Description

A simple label that displays an image (non‑interactive).

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'image_path': {'name': 'image path', 'key': 'image_path', 'type': Union[str, pygame.Surface], 'editable': False, 'description': 'Path to image file or Surface object.'}}
Methods
def __init__(self: Any, x: int, y: int, image_path: Union[str, pygame.Surface], width: Optional[int] = None, height: Optional[int] = None, pivot: Tuple[float, float] = (0, 0), element_id: Optional[str] = None) -> None
No documentation
def can_focus(self: Any) -> bool
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def _load_image(self: Any) -> None
No documentation
def set_image(self: Any, image_path: Union[str, pygame.Surface]) -> None
No documentation
def get_image(self: Any) -> pygame.Surface
No documentation
def set_size(self: Any, width: int, height: int) -> None
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation

Global Functions

def parse_rich_text(text: str) -> List[RichTextSegment]

  Parse rich text markup into a list of segments.
 
  Supported tags:
      <b>bold</b> - Bold text
      <i>italic</i> - Italic text
      <u>underline</u> - Underlined text
      <red>text</red> - Colored text (predefined colors)
      <#FF0000>text</#FF0000> - Hex color text
      <br> or
- Line break (handled by renderer)
 
  Args:
      text: The rich text string to parse
     
  Returns:
      List of RichTextSegment objects
 

def _extract_rgb_from_color(color: Union[Tuple[int, int, int], Color, ThemeStyle, None]) -> Tuple[int, int, int]

Extract RGB tuple from a color object (Tuple, Color, ThemeStyle, or None).
If None, returns (255, 255, 255) as fallback.

def _get_segment_font(seg: RichTextSegment, base_font: pygame.font.Font) -> pygame.font.Font

Return a font for the segment with bold/italic applied if needed.
Uses FontManager to get the styled font.

def render_rich_text(text: str, renderer: Any, x: int, y: int, default_color: Union[Color, Tuple[int, int, int], ThemeStyle], font: pygame.font.Font, pivot: Tuple[float, float] = (0.0, 0.0), **kwargs: dict) -> None

Render rich text using the provided renderer.

def render_rich_text_line(line: List[RichTextSegment], renderer: Any, x: int, y: int, default_color: Union[Color, Tuple[int, int, int], ThemeStyle], font: pygame.font.Font) -> None

Render a pre-parsed rich text line (for LongTextLabel).

Back to Ui Module