textinputs.py

No documentation

class TextBox

Description

Single-line text input field with optional label.
Supports placeholder text, max length, and focus management.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'text': {'name': 'text', 'key': 'text', 'type': str, 'editable': True, 'description': 'Current text content.'}, 'placeholder_text': {'name': 'placeholder', 'key': 'placeholder_text', 'type': str, 'editable': True, 'description': 'Text shown when empty.'}, 'font_size': {'name': 'font size', 'key': 'font_size', 'type': int, 'editable': True, 'description': 'Font size in pixels.'}, 'max_length': {'name': 'max length', 'key': 'max_length', 'type': int, 'editable': True, 'description': 'Maximum characters allowed (0 = unlimited).'}, 'focused': {'name': 'focused', 'key': 'focused', 'type': bool, 'editable': False, 'description': 'Whether the text box has keyboard focus.'}, 'label': {'name': 'label', 'key': 'label', 'type': str, 'editable': True, 'description': 'Label text displayed next to or above the input.'}, 'label_position': {'name': 'label position', 'key': 'label_position', 'type': str, 'editable': True, 'description': '"left" or "top".', 'options': ['left', 'top']}, 'label_size': {'name': 'label size', 'key': 'label_size', 'type': int, 'editable': True, 'description': 'Font size of the label (0 = auto).'}}
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: Optional[ThemeType] = None, max_length: int = 0, element_id: Optional[str] = None, label: Optional[str] = None, label_position: Literal['left', 'top'] = 'left', label_size: Optional[int] = None, **kwargs: dict) -> None
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def set_on_text_changed(self: Any, callback: Callable[[str], None]) -> None
Set a callback to be invoked when the text changes.
def font(self: Any) -> pygame.font.Font
No documentation
def placeholder_font(self: Any) -> pygame.font.Font
No documentation
def label_font(self: Any) -> pygame.font.Font
No documentation
def _update_layout(self: Any) -> None
Recalculate label and input rectangles based on current settings.
def get_text(self: Any) -> str
No documentation
def has_focus(self: Any) -> bool
No documentation
def set_text(self: Any, text: str) -> None
No documentation
def _update_text_surface(self: Any) -> None
No documentation
def _get_text_color(self: Any) -> Tuple[int, int, int]
No documentation
def _get_placeholder_color(self: Any) -> Tuple[int, int, int, int]
No documentation
def _get_background_color(self: Any) -> Tuple[int, int, int]
No documentation
def on_key_down(self: Any, event: pygame.event.Event) -> None
No documentation
def on_key_up(self: Any, event: pygame.event.Event) -> None
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def focus(self: Any) -> None
No documentation
def unfocus(self: Any) -> None
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation
def _render_text_content(self: Any, renderer: Renderer, input_abs_x: int, input_abs_y: int, theme: Any) -> None
Render actual text or placeholder inside the input area.
def _get_cursor_position(self: Any, input_abs_x: int, input_abs_y: int) -> Tuple[int, int]
Compute screen position of the cursor.
def update_theme(self: Any, theme_type: ThemeType) -> None
No documentation

class TextArea

Description

Multi-line text input area with word wrapping and scrollbars.
Supports text editing, selection, copy/paste, and line numbers.

Attributes
_properties: Dict[str, Dict[str, Any]] = {**UIElement._properties, 'text': {'name': 'text', 'key': 'text', 'type': str, 'editable': True, 'description': 'The text content.'}, 'line_numbers': {'name': 'line numbers', 'key': 'line_numbers', 'type': bool, 'editable': True, 'description': 'Show line numbers on the left.'}, 'word_wrap': {'name': 'word wrap', 'key': 'word_wrap', 'type': bool, 'editable': True, 'description': 'Automatically wrap long lines.'}, 'read_only': {'name': 'read only', 'key': 'read_only', 'type': bool, 'editable': True, 'description': 'If True, text cannot be edited.'}, 'tab_size': {'name': 'tab size', 'key': 'tab_size', 'type': int, 'editable': True, 'description': 'Number of spaces per tab.'}}
Methods
def __init__(self: Any, x: int, y: int, width: int, height: int, text: str = '', font_size: int = 16, font_name: Optional[str] = None, line_numbers: bool = True, word_wrap: bool = True, read_only: bool = False, tab_size: int = 4, pivot: Tuple[float, float] = (0, 0), theme: Optional[ThemeType] = None, element_id: Optional[str] = None) -> None
No documentation
def line_height(self: Any) -> int
No documentation
def font(self: Any) -> pygame.font.Font
No documentation
def _get_init_args(self: Any) -> Dict[str, Any]
No documentation
def get_text(self: Any) -> str
No documentation
def set_text(self: Any, text: str) -> None
No documentation
def _update_dimensions(self: Any) -> None
No documentation
def _update_text_buffer(self: Any) -> None
No documentation
def _save_to_undo_stack(self: Any) -> None
No documentation
def undo(self: Any) -> None
No documentation
def redo(self: Any) -> None
No documentation
def _get_visible_lines(self: Any) -> List[int]
No documentation
def _get_text_width(self: Any, text: str) -> int
Return the exact pixel width of a string using the current font.
def _get_char_width_at_position(self: Any, line: str, col: int) -> int
Return the pixel width of the character at the given column.
def _get_cursor_screen_pos(self: Any) -> Tuple[int, int]
No documentation
def _scroll_to_cursor(self: Any) -> None
No documentation
def _insert_text(self: Any, text: str) -> None
No documentation
def _delete_selection(self: Any) -> None
No documentation
def _get_selection_text(self: Any) -> str
No documentation
def copy(self: Any) -> None
No documentation
def cut(self: Any) -> None
No documentation
def paste(self: Any) -> None
No documentation
def select_all(self: Any) -> None
No documentation
def _move_cursor(self: Any, line_delta: int, column_delta: int, extend_selection: bool = False) -> None
No documentation
def update(self: Any, dt: float, inputState: InputState) -> None
No documentation
def on_key_down(self: Any, event: pygame.event.Event) -> None
No documentation
def on_key_up(self: Any, event: pygame.event.Event) -> None
No documentation
def _get_cursor_from_mouse(self: Any, mouse_pos: Tuple[int, int]) -> Tuple[int, int]
No documentation
def _handle_key_event(self: Any, event: pygame.event.Event) -> None
No documentation
def render(self: Any, renderer: Renderer) -> None
No documentation
def _draw_selection_highlight(self: Any, renderer: Renderer, ax: int, ay: int, line_num: int, line_y: int) -> None
No documentation
Back to Ui Module