wijjit.elements.modal.ModalElement
- class wijjit.elements.modal.ModalElement(id=None, classes=None, title=None, width=50, height=10, border_style='single', centered=True, padding=(1, 2, 1, 2))[source]
Modal dialog element with frame and content.
This element renders as a bordered frame suitable for modal dialogs. It automatically handles frame rendering and child element layout.
- Parameters:
id (
str, optional) – Unique identifiertitle (
str, optional) – Modal title displayed in the frame borderwidth (
int, optional) – Modal width in characters (default: 50)height (
int, optional) – Modal height in lines (default: 10)border_style (
strorBorderStyle, optional) – Border style: “single”, “double”, or “rounded” (default: “single”)centered (
bool, optional) – Whether to center the modal (default: True)padding (
tupleofint, optional) – Padding as (top, right, bottom, left) (default: (1, 2, 1, 2))
- Variables:
- __init__(id=None, classes=None, title=None, width=50, height=10, border_style='single', centered=True, padding=(1, 2, 1, 2))[source]
Methods
__init__([id, classes, title, width, ...])add_child(element)Add a child element.
add_class(class_name)Add a CSS class to this element.
apply_props(props)Apply props from a VNode, skipping ephemeral props.
Calculate the bounds available for content inside the frame.
get_ephemeral_state()Get ephemeral state that should survive reconciliation.
get_focusable_children()Get all focusable child elements.
get_hardware_cursor_position()Absolute screen cell where the hardware terminal cursor should park.
get_height_for_width(width)Return the height this element needs when laid out at
width.get_intrinsic_size()Get the intrinsic (preferred) size of the element.
handle_key(key)Handle key press by routing to focused child.
handle_mouse(event)Handle mouse event by routing to child at mouse position.
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_child(element)Remove a child element.
remove_class(class_name)Remove a CSS class from this element.
render_signature()Hashable/comparable capture of everything
render_to()reads.render_to(ctx)Render the modal using cell-based rendering (NEW API).
restore_ephemeral_state(state)Restore ephemeral state after reconciliation.
set_bounds(bounds)Set the element's screen bounds.
set_content(content)Set the modal content text.
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_content(content)[source]
Set the modal content text.
- Parameters:
content (
str) – Content text (may contain newlines)- Return type:
None
- render_to(ctx)[source]
Render the modal using cell-based rendering (NEW API).
- Parameters:
ctx (
PaintContext) – Paint context with buffer, style resolver, and bounds- Return type:
None
Notes
This method implements proper cell-based rendering with sub-contexts for child elements. It handles: - Frame border and background rendering - Text element rendering with theme styles - Interactive element (button, input) rendering with sub-contexts - Proper bounds setting for mouse and focus handling
Theme styles:
This element uses the following theme style classes (via Frame): -
modal: Base modal style -modal.text: Text content style -modal.backdrop: Semi-transparent backdrop style (handled by overlay manager) -frame.border: Border style (inherited from Frame) -frame.border:focus: Focused border style (inherited from Frame)