base.py

No documentation

class _UIDGenerator

Description

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

Methods
def __init__(self: Any) -> Any
No documentation
def generate_id(self: Any, element_type: str) -> str
Generate a unique ID for a UI element.

Args:
   element_type (str): Type of the UI element (e.g., 'button', 'label')
   
Returns:
   str: Unique ID in format "ui_{element_type}_{counter}"

class UIState

Description

Enumeration of possible UI element states.

Attributes
NORMAL: Any = 0
HOVERED: Any = 1
PRESSED: Any = 2
DISABLED: Any = 3
Methods

No methods defined.

class ElementStyle

Description

Class representing style properties for UI elements.

Attributes
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
Methods
def loadFromTheme(theme_type: ThemeType) -> 'ElementStyle'
Load complete element style from the theme system.
Uses button_* properties as base, but can be overridden for specific elements.

class FontManager

Description

Manages fonts and ensures Pygame font system is initialized.

Attributes
_initialized: Any = False
_default_fonts: Any = {}
Methods
def initialize(cls: Any) -> Any
Initialize the font system.

This method should be called before using any font-related functionality.
It initializes Pygame's font module if not already initialized.
def get_font(cls: Any, font_name: Optional[str] = None, font_size: int = 24) -> Any
Get a font object for rendering text.

Args:
   font_name (Optional[str]): Path to font file or None for default system font.
   font_size (int): Size of the font in pixels.
   
Returns:
   pygame.font.Font: A font object ready for text rendering.

class UIElement

Description

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
   root_point (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

Attributes
_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'}, 'y': {'name': 'y position', 'key': 'y', 'type': int, 'editable': True, 'description': 'Y coordinate position of the element'}, 'width': {'name': 'width', 'key': 'width', 'type': int, 'editable': True, 'description': 'Width of the element in pixels'}, 'height': {'name': 'height', 'key': 'height', 'type': int, 'editable': True, 'description': 'Height of the element in pixels'}, 'style': {'name': 'style', 'key': 'style', 'type': ElementStyle, 'editable': True, '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'}, 'root_point': {'name': 'root point', 'key': 'root_point', 'type': Tuple[float, float], 'editable': True, 'description': 'Anchor point for positioning where (0,0) is top-left and (1,1) is bottom-right'}}
Methods
def __init__(self: Any, x: int, y: int, width: int, height: int, root_point: Tuple[float, float] = (0, 0), element_id: Optional[str] = None) -> Any
Initialize a UI element with position and dimensions.

Args:
   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.
   root_point (Tuple[float, float]): Anchor point for positioning where (0,0) is top-left
                                   and (1,1) is bottom-right.
   element_id (Optional[str]): Custom element ID. If None, generates automatic ID.
def add_to_parent(self: Any, parent: 'UIElement', extra: Any = None) -> None
No documentation
def getIndexedChilds(self: Any) -> int
No documentation
def get_mouse_position(self: Any, input_state: InputState) -> Tuple[int, int]
No documentation
def getCollideRect(self: Any) -> pygame.Rect
No documentation
def mouse_over(self: Any, input_state: InputState | Tuple) -> bool
No documentation
def set_enabled(self: Any, enabled: bool) -> Any
No documentation
def get_engine(self: Any) -> 'LunaEngine'
No documentation
def set_corner_radius(self: Any, radius: int | Tuple[int, int, int, int]) -> Any
No documentation
def group(self: Any) -> str
No documentation
def add_group(self: Any, group: str) -> Any
No documentation
def remove_group(self: Any, group: str) -> Any
No documentation
def clear_groups(self: Any) -> Any
No documentation
def has_group(self: Any, group: str) -> bool
No documentation
def __str__(self: Any) -> str
No documentation
def __repr__(self: Any) -> str
No documentation
def get_id(self: Any) -> str
Get the unique ID of this UI element.

Returns:
   str: The unique element ID
def set_id(self: Any, new_id: str) -> None
Set a new unique ID for this UI element.

Args:
   new_id (str): The new unique ID to set
def get_actual_position(self: Any, x: int | float = None, y: int | float = None) -> Tuple[int, int]
Calculate actual screen position based on root_point anchor.

Args:
   parent_width (int): Width of parent element if applicable.
   parent_height (int): Height of parent element if applicable.
   
Returns:
   Tuple[int, int]: The actual (x, y) screen coordinates.
def add_child(self: Any, child: Any) -> Any
Add a child element to this UI element.

Args:
   child: The child UI element to add.
def remove_child(self: Any, child: Any) -> Any
Remove a child element from this UI element.

Args:
   child: The child UI element to remove.
def set_tooltip(self: Any, tooltip: 'Tooltip') -> Any
Set tooltip for this element using a Tooltip instance.

Args:
   tooltip (Tooltip): Tooltip instance to associate with this element
def set_simple_tooltip(self: Any, text: str, **kwargs: dict) -> Any
Quick method to set a simple tooltip with text.

Args:
   text (str): Tooltip text
   **kwargs: Additional arguments for TooltipConfig
def remove_tooltip(self: Any) -> Any
Remove tooltip from this element.
def update(self: Any, dt: float, inputState: InputState) -> Any
Update element state.

Args:
   dt (float): Delta time in seconds since last update.
def update_theme(self: Any, theme_type: ThemeType) -> Any
Update the theme for this element and all its children.

Args:
   theme_type (ThemeType): The new theme to apply.
def render(self: Any, renderer: Renderer | OpenGLRenderer) -> Any
Render this element using OpenGL backend.  
Override this in subclasses for OpenGL-specific rendering.
def on_click(self: Any) -> Any
Called when element is clicked by the user.
def on_hover(self: Any) -> Any
Called when mouse hovers over the element.
Back to Ui Module