wijjit.elements.base.TextElement
- class wijjit.elements.base.TextElement(text, id=None, classes=None, wrap=True, html=None, align='left')[source]
Simple text display element.
This element displays static text content. It is non-interactive and cannot receive focus.
- Parameters:
text (
str) – Text content to displayid (
str, optional) – Unique identifier for this elementclasses (
strorlistofstrorsetofstr, optional) – CSS class names for stylingwrap (
bool, optional) – Whether to wrap text to fit bounds width (default: True)html (
boolorNone, optional) – Whether to parse HTML tags in text content (default: None, treated as disabled). Set per element withhtml=True/html=False.align (
str, optional) – Horizontal alignment of each line within the element’s width:"left"(default),"center", or"right".
- Variables:
Methods
__init__(text[, id, classes, wrap, html, align])add_class(class_name)Add a CSS class to this element.
apply_props(props)Apply props from a VNode, skipping ephemeral props.
get_ephemeral_state()Get ephemeral state that should survive reconciliation.
get_hardware_cursor_position()Absolute screen cell where the hardware terminal cursor should park.
get_height_for_width(width)Return the row count this text needs once wrapped to
width.Get the intrinsic size based on text content.
handle_key(key)Handle a key press.
handle_mouse(event)Handle a mouse event.
has_class(class_name)Check if element has a CSS class.
on_blur()Called when element loses focus.
on_focus()Called when element gains focus.
on_hover_enter()Called when mouse enters element.
on_hover_exit()Called when mouse exits element.
on_mount()Called when element is first added to the element tree.
on_unmount()Called when element is removed from the element tree.
on_update(changed_props)Called when element props are updated during reconciliation.
remove_class(class_name)Remove a CSS class from this element.
Paint memo for the skip-unchanged fast path.
render_to(ctx)Render the text element using cell-based rendering.
restore_ephemeral_state(state)Restore ephemeral state after reconciliation.
set_bounds(bounds)Set bounds and wrap text if needed.
toggle_class(class_name)Toggle a CSS class on this element.
Attributes
captures_tabWhether this element wants the Tab key instead of focus movement.
parent_frameGet the parent Frame if this element is inside a scrollable frame.
supports_dynamic_sizingWhether this element supports dynamic sizing.
- set_bounds(bounds)[source]
Set bounds and wrap text if needed.
- Parameters:
bounds (
Bounds) – New bounds for the element- Return type:
None
- get_intrinsic_size()[source]
Get the intrinsic size based on text content.
- Returns:
(width, height) based on text lines
- Return type:
tuple[int,int]
Notes
If HTML mode is enabled, HTML tags are stripped when calculating visible width to get accurate sizing.
The height counts unwrapped lines, because the layout width is not known during the bottom-up measure pass. Containers that have resolved this element’s width should call
get_height_for_width()instead.
- get_height_for_width(width)[source]
Return the row count this text needs once wrapped to
width.- Parameters:
width (
int) – The width the element will be laid out at.- Returns:
Number of display rows. Equal to the unwrapped line count when wrapping is off or every line already fits.
- Return type:
Notes
Without this, a long line is measured as one row, is allocated one row, and then paints its wrapped continuation lines over whatever sibling was laid out beneath it - so the sibling silently disappears.
- render_signature()[source]
Paint memo for the skip-unchanged fast path.
Captures the displayed text (already wrapped for the current width), alignment, HTML mode, and the style-affecting state. See
Element.render_signature().- Return type:
- render_to(ctx)[source]
Render the text element using cell-based rendering.
- Parameters:
ctx (
PaintContext) – Paint context with buffer, style resolver, and bounds- Return type:
None
Notes
If HTML mode is enabled, HTML tags are parsed and converted to styled cells. HTML classes like <span class=”text-danger”> are resolved through the theme’s style definitions.