Internal class for generating unique IDs for UI elements.
Generates IDs in the format: ui_{element_type}_{counter}
Example: ui_button_1, ui_label_2, ui_dropdown_1
def __init__(self: Any) -> Any
def generate_id(self: Any, element_type: str) -> str
Enumeration of possible UI element states.
NORMAL: Any = 0
HOVERED: Any = 1
PRESSED: Any = 2
DISABLED: Any = 3
No methods defined.
Class representing style properties for UI elements.
normal_color: Optional[Tuple[int, int, int]] = None
hovered_color: Optional[Tuple[int, int, int]] = None
pressed_color: Optional[Tuple[int, int, int]] = None
disabled_color: Optional[Tuple[int, int, int]] = None
text_color: Optional[Tuple[int, int, int]] = None
border_color: Optional[Tuple[int, int, int]] = None
alpha: float = 1.0
border_radius: int = 0
border_width: int = 0
blur: int = 0
def loadFromTheme(theme_type: ThemeType) -> 'ElementStyle'
Manages fonts and ensures Pygame font system is initialized.
Supports both system fonts (by name) and file fonts (by path).
Caches fonts with style variants (bold/italic).
Also supports resolving font names via the engine's Atlas resource catalog,
and loading fonts from a bundled resource (using io.BytesIO).
Usage:
# Basic usage
font = FontManager.get_font("Arial", 24)
# Using an atlas-registered font
FontManager.set_atlas(engine.atlas)
font = FontManager.get_font("main_font", 24) # looks up "main_font" in atlas
# File font
font = FontManager.get_font("path/to/font.ttf", 16)
_initialized: Any = False
_font_cache: Dict[Tuple[str, int, bool, bool], pygame.font.Font] = {}
_atlas: Any = None
def initialize(cls: Any) -> Any
def set_atlas(cls: Any, atlas: Any) -> Any
def get_font(cls: Any, font_name: Optional[str] = None, font_size: int = 24, bold: bool = False, italic: bool = False) -> pygame.font.Font
def get_system_fonts(cls: Any) -> List[str]
Base class for all UI elements providing common functionality.
Attributes:
element_id (str): Unique identifier for this element in format ui_{type}_{counter}
x (int): X coordinate position
y (int): Y coordinate position
width (int): Width of the element in pixels
height (int): Height of the element in pixels
pivot (Tuple[float, float]): Anchor point for positioning
state (UIState): Current state of the element
visible (bool): Whether element is visible
enabled (bool): Whether element is enabled
children (List[UIElement]): Child elements
parent (UIElement): Parent element
can_focus (bool): Whether this element can receive controller focus (override in subclasses)
_global_engine: 'LunaEngine' = None
_properties: Dict[str, Dict[str, Any]] = {'x': {'name': 'x position', 'key': 'x', 'type': int, 'editable': True, 'description': 'X coordinate position of the element', 'range': (0, '')}, 'y': {'name': 'y position', 'key': 'y', 'type': int, 'editable': True, 'description': 'Y coordinate position of the element', 'range': (0, '')}, 'width': {'name': 'width', 'key': 'width', 'type': int, 'editable': True, 'description': 'Width of the element in pixels', 'range': (0, '')}, 'height': {'name': 'height', 'key': 'height', 'type': int, 'editable': True, 'description': 'Height of the element in pixels', 'range': (0, '')}, 'style': {'name': 'style', 'key': 'style', 'type': ElementStyle, 'editable': False, 'description': 'Style properties for the element'}, 'visible': {'name': 'visible', 'key': 'visible', 'type': bool, 'editable': True, 'description': 'Whether the element is visible'}, 'enabled': {'name': 'enabled', 'key': 'enabled', 'type': bool, 'editable': True, 'description': 'Whether the element is enabled for interaction'}, 'pivot': {'name': 'root point', 'key': 'pivot', 'type': Tuple[float, float], 'editable': True, 'description': 'Anchor point for positioning where (0,0) is top-left and (1,1) is bottom-right'}, 'selection_order': {'name': 'selection order', 'key': 'selection_order', 'type': int, 'editable': True, 'description': 'Order for controller focus navigation (lower = earlier)'}}
category: str = 'None'
def __init__(self: Any, x: int, y: int, width: int, height: int, pivot: Tuple[float, float] = (0, 0), element_id: Optional[str] = None) -> Any
def can_focus(self: Any) -> bool
def is_globally_visible(self: Any) -> bool
def add_to_parent(self: Any, parent: 'UIElement', extra: Any = None) -> None
def getIndexedChilds(self: Any) -> int
def set_enabled(self: Any, enabled: bool) -> Any
def get_engine(self: Any) -> 'LunaEngine'
def set_corner_radius(self: Any, radius: int | Tuple[int, int, int, int]) -> Any
def group(self: Any) -> str
def add_group(self: Any, group: str) -> Any
def remove_group(self: Any, group: str) -> Any
def clear_groups(self: Any) -> Any
def has_group(self: Any, group: str) -> bool
def __str__(self: Any) -> str
def __repr__(self: Any) -> str
def type(self: Any) -> str
def get_id(self: Any) -> str
def set_id(self: Any, new_id: str) -> None
def get_scroll_offset(self: Any, is_for_scroll_event: Optional[bool] = False) -> Union[Tuple[int, int], Tuple[float, float]]
def get_actual_position(self: Any, x: Union[int, float, None] = None, y: Union[int, float, None] = None) -> Union[Tuple[int, int], Tuple[float, float]]
def mouse_over(self: Any, input_state: InputState | Tuple[int, int], rect: pygame.Rect | pygame.Rect | None = None, is_for_scroll_event: Optional[bool] = False) -> bool
def get_mouse_position(self: Any, input_state: InputState | Tuple[int, int]) -> Tuple[int, int]
def getCollideRect(self: Any, rect: pygame.Rect | None = None, is_for_scroll_event: Optional[bool] = False) -> pygame.Rect
def add_child(self: Any, child: Any) -> Any
def remove_child(self: Any, child: 'UIElement') -> Any
def set_tooltip(self: Any, tooltip: 'Tooltip') -> Any
def set_simple_tooltip(self: Any, text: str, **kwargs: dict) -> Any
def remove_tooltip(self: Any) -> Any
def update(self: Any, dt: float, inputState: InputState) -> Any
def update_theme(self: Any, theme_type: ThemeType) -> Any
def render(self: Any, renderer: Renderer | OpenGLRenderer) -> Any
def kill(self: Any) -> Any
def _get_init_args(self: Any) -> Dict[str, Any]
def restart(self: Any) -> Optional['UIElement']
def on_click(self: Any) -> Any
def on_hover(self: Any) -> Any
def on_activate(self: Any) -> None
def on_directional_input(self: Any, direction: str) -> bool