tooltips.py

tooltips.py - Tooltip System for LunaEngine

This module handles tooltips for UI elements, providing helpful information
when hovering over elements.

class TooltipConfig

Description

Configuration class for tooltip appearance and behavior.
Allows easy customization of tooltips without passing multiple parameters.

Methods
def __init__(self: Any, text: str = '', font_size: int = 14, padding: int = 8, corner_radius: int = 4, offset_x: int = 10, offset_y: int = 10, show_delay: float = 0.5, max_width: int = 300, theme: ThemeType = None) -> Any
Initialize tooltip configuration.

Args:
   text (str): Tooltip text content
   font_size (int): Font size for tooltip text
   padding (int): Padding around text
   corner_radius (int): Border radius for rounded corners
   offset_x (int): Horizontal offset from target element
   offset_y (int): Vertical offset from target element
   show_delay (float): Delay in seconds before showing tooltip
   max_width (int): Maximum width before text wraps
   theme (ThemeType): Custom theme for tooltip

class Tooltip

Description

Tooltip element that displays helpful information when hovering over UI elements.
Automatically adjusts position to stay within screen boundaries.

Methods
def __init__(self: Any, config: TooltipConfig = None, element_id: Optional[str] = None) -> Any
Initialize a tooltip with configuration.

Args:
   config (TooltipConfig): Configuration object for tooltip appearance
   element_id (Optional[str]): Custom element ID
def _calculate_size(self: Any) -> Any
Calculate tooltip size based on text and configuration.
def _wrap_text(self: Any, text: str, font: Any) -> List[str]
Wrap text to fit within max width.

Args:
   text (str): Text to wrap
   font: Font object for size calculation
   
Returns:
   List[str]: List of wrapped lines
def set_text(self: Any, text: str) -> Any
Update tooltip text and recalculate size.

Args:
   text (str): New tooltip text
def set_config(self: Any, config: TooltipConfig) -> Any
Update tooltip configuration.

Args:
   config (TooltipConfig): New configuration
def set_target(self: Any, element: UIElement) -> Any
Set the target element for this tooltip.

Args:
   element (UIElement): Element to attach tooltip to
def update_tooltip(self: Any, inputState: InputState, dt: float, screen_width: int, screen_height: int) -> bool
Update tooltip state and position.

Args:
   mouse_pos (Tuple[int, int]): Current mouse position
   dt (float): Delta time in seconds
   screen_width (int): Screen width for boundary checking
   screen_height (int): Screen height for boundary checking
   
Returns:
   bool: True if tooltip should be visible, False otherwise
def _update_position(self: Any, screen_width: int, screen_height: int, mouse_pos: Tuple[int, int]) -> Any
Update tooltip position to follow mouse and stay within screen bounds.

Args:
   screen_width (int): Screen width for boundary checking
   screen_height (int): Screen height for boundary checking
   mouse_pos (Tuple[int, int]): Current mouse position
def render(self: Any, renderer: Any) -> Any
Render tooltip using OpenGL backend
def _render_wrapped_text(self: Any, renderer: Any, x: int, y: int, theme: Any) -> Any
Render wrapped text inside tooltip.

class UITooltipManager

Description

Manages tooltips globally to ensure proper display and positioning.
Supports multiple tooltips for different UI elements.

Attributes
_instance: Any = None
_tooltips: Dict[str, Tooltip] = {}
_active_tooltip: Optional[Tooltip] = None
Methods
def __new__(cls: Any) -> Any
No documentation
def register_tooltip(cls: Any, element: UIElement, tooltip: Tooltip) -> Any
Register a tooltip for a UI element.

Args:
   element (UIElement): The UI element that triggers the tooltip
   tooltip (Tooltip): The tooltip to show
def unregister_tooltip(cls: Any, element: UIElement) -> Any
Unregister tooltip for a UI element.

Args:
   element (UIElement): The UI element to remove tooltip from
def update(cls: Any, engine: 'LunaEngine', dt: float) -> Any
Update all tooltips and determine which one should be active.

Args:
   engine (LunaEngine): The main engine instance
   dt (float): Delta time in seconds
def get_tooltip_to_render(cls: Any, engine: 'LunaEngine') -> List[Tooltip]
Get the currently active tooltip to render.

Args:
   engine (LunaEngine): The main engine instance
   
Returns:
   List[Tooltip]: List containing the active tooltip, or empty if none
def render(cls: Any, renderer: Any) -> Any
Render the active tooltip.
def clear_all(cls: Any) -> Any
Clear all registered tooltips.
Back to Ui Module