selectors.py

No documentation

class Select

Description

A cycle selection widget with left/right arrows to scroll through options.
Requires activation (A) to enter manipulation mode.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'options': {'name': 'options', 'key': 'options', 'type': List[str], 'editable': True, 'description': 'List of selectable strings.'}, 'selected_index': {'name': 'selected index', 'key': 'selected_index', 'type': int, 'editable': True, 'description': 'Currently selected index.'}, 'font_size': {'name': 'font size', 'key': 'font_size', 'type': int, 'editable': True, 'description': 'Text size.'}}
Methods
def __init__(self: Any, x: int, y: int, width: int, height: int, options: List[str], font_size: int = 20, font_name: Optional[str] = None, pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, element_id: Optional[str] = None) -> None
No documentation
def can_focus(self: Any) -> bool
No documentation
def on_activate(self: Any) -> None
Enter or exit manipulation mode.
def on_directional_input(self: Any, direction: str) -> bool
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def _create_arrow_surfaces(self: Any) -> None
No documentation
def font(self: Any) -> pygame.font.Font
No documentation
def next_option(self: Any) -> None
No documentation
def previous_option(self: Any) -> None
No documentation
def set_selected_index(self: Any, index: int) -> None
No documentation
def set_on_selection_changed(self: Any, callback: Callable[[int, str], None]) -> None
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation
def _render_select_content(self: Any, renderer: Renderer, actual_x: int, actual_y: int, theme: Any) -> None
No documentation
def _draw_fallback_arrows(self: Any, renderer: Renderer, actual_x: int, actual_y: int, arrow_color: Any) -> None
No documentation

class Switch

Description

A toggle switch with animated sliding thumb.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'checked': {'name': 'checked', 'key': 'checked', 'type': bool, 'editable': True, 'description': 'Switch state (ON/OFF).'}}
Methods
def __init__(self: Any, x: int, y: int, width: int = 60, height: int = 30, checked: bool = False, pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, element_id: Optional[str] = None) -> None
No documentation
def can_focus(self: Any) -> bool
No documentation
def on_activate(self: Any) -> None
No documentation
def set_value(self: Any, value: bool) -> None
No documentation
def on_directional_input(self: Any, direction: str) -> bool
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def toggle(self: Any) -> None
No documentation
def set_checked(self: Any, checked: bool) -> None
No documentation
def set_on_toggle(self: Any, callback: Callable[[bool], None]) -> None
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def _get_colors(self: Any) -> Tuple[Tuple[int, int, int], Tuple[int, int, int]]
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation

class Slider

Description

A horizontal or vertical slider with draggable thumb.
Requires activation (A) to enter manipulation mode.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'min_val': {'name': 'min value', 'key': 'min_val', 'type': float, 'editable': True, 'description': 'Minimum value.'}, 'max_val': {'name': 'max value', 'key': 'max_val', 'type': float, 'editable': True, 'description': 'Maximum value.'}, 'value': {'name': 'value', 'key': 'value', 'type': float, 'editable': True, 'description': 'Current value.'}, 'orientation': {'name': 'orientation', 'key': 'orientation', 'type': str, 'editable': True, 'description': '"horizontal" or "vertical".', 'options': ['horizontal', 'vertical']}, 'render_text': {'name': 'render text', 'key': 'render_text', 'type': bool, 'editable': True, 'description': 'Render value as text.'}}
Methods
def __init__(self: Any, x: int | float, y: int | float, width: int, height: int, min_val: float = 0, max_val: float = 100, value: float = 50, orientation: Literal['horizontal', 'vertical'] = 'horizontal', pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, element_id: Optional[str] = None) -> None
No documentation
def can_focus(self: Any) -> bool
No documentation
def on_activate(self: Any) -> None
Enter or exit manipulation mode.
def on_directional_input(self: Any, direction: str) -> bool
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def set_on_value_changed(self: Any, callback: Callable[[float], None]) -> None
No documentation
def set_theme(self: Any, theme_type: ThemeType) -> None
No documentation
def _get_colors(self: Any) -> 'UITheme'
No documentation
def set_value(self: Any, value: float) -> None
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation

class Dropdown

Description

Dropdown selection widget. When expanded, its height changes to include the
expanded options area. Supports an optional label, search functionality,
and scrollable options. Handles parent scrolling and auto-arrangement correctly.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'options': {'name': 'options', 'key': 'options', 'type': List[str], 'editable': True, 'description': 'Selectable options.'}, 'selected_index': {'name': 'selected index', 'key': 'selected_index', 'type': int, 'editable': True, 'description': 'Currently selected option index.'}, 'expanded': {'name': 'expanded', 'key': 'expanded', 'type': bool, 'editable': False, 'description': 'Whether the dropdown is expanded.'}, 'searchable': {'name': 'searchable', 'key': 'searchable', 'type': bool, 'editable': True, 'description': 'Show search box when expanded.'}, 'max_visible_options': {'name': 'max visible options', 'key': 'max_visible_options', 'type': int, 'editable': True, 'description': 'Maximum options shown before scrolling.'}}
Methods
def __init__(self: Any, x: int, y: int, width: int, height: int, options: Optional[List[str]] = None, font_size: int = 20, font_name: Optional[str] = None, pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, max_visible_options: int = 10, element_id: Optional[str] = None, searchable: bool = False, label: Optional[str] = None, label_size: Optional[int] = None, label_position: Literal['left', 'top'] = 'left') -> None
No documentation
def can_focus(self: Any) -> bool
No documentation
def on_activate(self: Any) -> None
No documentation
def on_directional_input(self: Any, direction: str) -> bool
No documentation
def _ensure_highlight_visible(self: Any, pos: int) -> None
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def set_on_expanded(self: Any, callback: Callable[[bool], None]) -> None
Register a callback that is called when the dropdown expands or collapses.
def _trigger_expanded_callback(self: Any, expanded: bool) -> None
No documentation
def _update_layout(self: Any) -> None
No documentation
def _get_expanded_height(self: Any) -> int
No documentation
def _update_expanded_height(self: Any) -> None
Recalculate the expanded height based on options and search box.
def _notify_parent_rearrange(self: Any) -> None
Mark the nearest parent with auto_arrange_y as dirty.
def get_selected(self: Any) -> Tuple[int, str]
No documentation
def _on_search_text_changed(self: Any, text: str) -> None
No documentation
def _update_filtered_options(self: Any) -> None
No documentation
def font(self: Any) -> pygame.font.Font
No documentation
def set_options(self: Any, options: List[str], selected_index: int = 0) -> None
No documentation
def set_theme(self: Any, theme_type: ThemeType) -> None
No documentation
def _get_colors(self: Any) -> Any
No documentation
def _get_visible_options(self: Any) -> List[int]
No documentation
def _find_auto_arrange_parent(self: Any) -> Optional[UIElement]
No documentation
def on_scroll(self: Any, event: pygame.event.Event) -> None
No documentation
def _get_button_screen_rect(self: Any) -> pygame.Rect
No documentation
def _get_expanded_screen_rect(self: Any) -> pygame.Rect
No documentation
def _get_scrollbar_track_rect(self: Any, btn_rect: pygame.Rect) -> pygame.Rect
No documentation
def _get_scrollbar_thumb_rect(self: Any, btn_rect: pygame.Rect) -> pygame.Rect
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation
def _draw_arrow_polygon(self: Any, renderer: Any, points: Any, color: Any) -> None
No documentation
def _render_expanded_options(self: Any, renderer: OpenGLRenderer, theme: Any) -> None
No documentation
def add_option(self: Any, option: str) -> None
No documentation
def remove_option(self: Any, option: str) -> None
No documentation
def set_selected_index(self: Any, index: int) -> None
No documentation
def set_on_selection_changed(self: Any, callback: Callable[[int, str], None]) -> None
No documentation

class NumberSelector

Description

A numeric spinner with optional label. Supports min/max, step, and value change callbacks.
Requires activation (A) to enter manipulation mode.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'value': {'name': 'value', 'key': 'value', 'type': int, 'editable': True, 'description': 'Current numeric value.'}, 'min_value': {'name': 'min value', 'key': 'min_value', 'type': int, 'editable': True, 'description': 'Minimum allowed value.'}, 'max_value': {'name': 'max value', 'key': 'max_value', 'type': int, 'editable': True, 'description': 'Maximum allowed value.'}, 'step': {'name': 'step', 'key': 'step', 'type': int, 'editable': True, 'description': 'Increment/decrement step.'}, 'min_length': {'name': 'min length', 'key': 'min_length', 'type': int, 'editable': True, 'description': 'Minimum number of digits (zero padding).'}}
Methods
def __init__(self: Any, x: int, y: int, width: int, height: int, min_value: int, max_value: int, value: int, min_length: int = 1, max_length: int = 10, step: int = 1, label: Optional[str] = None, label_size: Optional[int] = None, label_position: Literal['left', 'top'] = 'left', pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, element_id: Optional[str] = None) -> None
No documentation
def can_focus(self: Any) -> bool
No documentation
def on_activate(self: Any) -> None
Enter or exit manipulation mode.
def on_directional_input(self: Any, direction: str) -> bool
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def value(self: Any) -> int
No documentation
def value(self: Any, new_value: int) -> None
No documentation
def get_value(self: Any) -> int
No documentation
def set_on_value_changed(self: Any, callback: Callable[[int], None]) -> None
No documentation
def increment(self: Any, multiplier: float = 1.0) -> None
No documentation
def decrement(self: Any, multiplier: float = 1.0) -> None
No documentation
def _calculate_rects(self: Any) -> Any
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def _get_multiplier(self: Any, inputState: InputState) -> float
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation
def _format_value(self: Any) -> str
No documentation

class Checkbox

Description

A clickable checkbox with optional label.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'checked': {'name': 'checked', 'key': 'checked', 'type': bool, 'editable': True, 'description': 'Checkbox state.'}, 'label': {'name': 'label', 'key': 'label', 'type': str, 'editable': True, 'description': 'Text displayed next to checkbox.'}, 'label_position': {'name': 'label position', 'key': 'label_position', 'type': str, 'editable': True, 'description': '"left" or "right".', 'options': ['left', 'right']}}
Methods
def __init__(self: Any, x: int, y: int, width: int, height: int, checked: bool, label: Optional[str] = None, label_position: str = 'right', pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, element_id: Optional[str] = None) -> None
No documentation
def can_focus(self: Any) -> bool
No documentation
def on_activate(self: Any) -> None
No documentation
def on_directional_input(self: Any, direction: str) -> bool
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def set_on_toggle(self: Any, callback: Callable[[bool], None]) -> None
No documentation
def get_state(self: Any) -> bool
No documentation
def value(self: Any) -> bool
No documentation
def _get_colors(self: Any) -> Tuple[Tuple[int, int, int], Tuple[int, int, int], Tuple[int, int, int], Tuple[int, int, int]]
No documentation
def toggle(self: Any) -> None
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation
Back to Ui Module