buttons.py

No documentation

class Button

Description

A clickable button with text and theming support.

Attributes
category: str = 'button'
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'text': {'name': 'text', 'key': 'text', 'type': str, 'editable': True, 'description': 'Text displayed on the button.'}, 'font_size': {'name': 'font size', 'key': 'font_size', 'type': int, 'editable': True, 'description': 'Size of the text in pixels.'}, 'font_name': {'name': 'font name', 'key': 'font_name', 'type': Optional[str], 'editable': True, 'description': 'Path to a custom font file.'}, 'background_color': {'name': 'background color', 'key': 'background_color', 'type': Tuple[int, int, int], 'editable': True, 'description': 'Custom RGB background color (overrides theme).'}, 'text_color': {'name': 'text color', 'key': 'text_color', 'type': Tuple[int, int, int], 'editable': True, 'description': 'Custom RGB text color (overrides theme).'}}
Methods
def __init__(self: Any, x: int, y: int, width: int, height: int, text: str = '', font_size: int = 20, font_name: Optional[str] = None, pivot: Tuple[float, float] = (0, 0), theme: ThemeType = None, element_id: Optional[str] = None) -> None
No documentation
def can_focus(self: Any) -> bool
Buttons are focusable for controller navigation.
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def set_background_color(self: Any, color: Optional[Tuple[int, int, int]]) -> None
No documentation
def set_text_color(self: Any, color: Optional[Tuple[int, int, int]]) -> None
No documentation
def set_text(self: Any, text: str) -> None
No documentation
def get_text(self: Any) -> str
No documentation
def update_theme(self: Any, theme_type: ThemeType) -> None
No documentation
def font(self: Any) -> pygame.font.Font
No documentation
def set_on_click(self: Any, callback: Callable, *args: tuple, **kwargs: dict) -> None
No documentation
def set_theme(self: Any, theme_type: ThemeType) -> None
No documentation
def _get_colors(self: Any) -> UITheme
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def _get_color_for_state(self: Any) -> Tuple[int, int, int]
No documentation
def _get_text_color(self: Any) -> Tuple[int, int, int]
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation

class ImageButton

Description

A clickable button that displays an image instead of text.

Attributes
category: str = 'button'
_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), theme: ThemeType = None, element_id: Optional[str] = None) -> None
No documentation
def can_focus(self: Any) -> bool
Image buttons are focusable.
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def _load_image(self: Any) -> None
No documentation
def set_on_click(self: Any, callback: Callable, *args: tuple, **kwargs: dict) -> None
No documentation
def get_image(self: Any) -> pygame.Surface
No documentation
def set_image(self: Any, image_path: Union[str, pygame.Surface]) -> None
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def _get_overlay_color(self: Any) -> Optional[Tuple[int, int, int, int]]
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation
Back to Ui Module