wijjit.elements.input.button.Button
- class wijjit.elements.input.button.Button(label, id=None, classes=None, tab_index=None, on_click=None, style=ButtonStyle.BRACKETS, action=None)[source]
Button element.
- Parameters:
label (
str) – Button label textid (
str, optional) – Element identifierclasses (
strorlistofstr, optional) – CSS-like class names for stylingon_click (
callable, optional) – Callback when button is activated, receives ActionEventstyle (
ButtonStyle, optional) – Visual style for button rendering (default: BRACKETS)action (
str, optional) – Action ID to dispatch when button is activatedtab_index (int | None)
- Variables:
Examples
Create a basic button:
>>> btn = Button("Click Me")
Create button with different styles:
>>> btn = Button("Save", style=ButtonStyle.BOX) >>> btn = Button("Cancel", style=ButtonStyle.MINIMAL)
- __init__(label, id=None, classes=None, tab_index=None, on_click=None, style=ButtonStyle.BRACKETS, action=None)[source]
Methods
__init__(label[, id, classes, tab_index, ...])activate()Activate the button (trigger click callback and action callback).
Activate the button asynchronously (trigger async callbacks).
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 height this element needs when laid out at
width.Get the intrinsic size of the button based on label and style.
handle_key(key)Handle keyboard input.
handle_mouse(event)Handle mouse input.
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 button using cell-based rendering (NEW API).
restore_ephemeral_state(state)Restore ephemeral state after reconciliation.
set_bounds(bounds)Set the element's screen bounds.
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.
- handle_key(key)[source]
Handle keyboard input.
- Parameters:
key (
Key) – Key press to handle- Returns:
True if key was handled
- Return type:
- async handle_mouse(event)[source]
Handle mouse input.
- Parameters:
event (
MouseEvent) – Mouse event to handle- Returns:
True if event was handled
- Return type:
Notes
This async handler supports async on_click and on_activate callbacks.
Setting
on_double_clicktakes precedence over activation: a double-click invokes that callback instead of activating the button.
- activate()[source]
Activate the button (trigger click callback and action callback).
Creates an ActionEvent with the button’s action_id and element id, and passes it to both on_click and on_activate callbacks.
Notes
This is the synchronous activation method. For async callback support, use activate_async() instead.
- Return type:
None
- async activate_async()[source]
Activate the button asynchronously (trigger async callbacks).
Creates an ActionEvent with the button’s action_id and element id, and passes it to both on_click and on_activate callbacks. Supports both sync and async callbacks.
Notes
This method supports async callbacks. If callbacks are sync, they are called directly. If async, they are awaited.
- Return type:
None
- get_intrinsic_size()[source]
Get the intrinsic size of the button based on label and style.
- Returns:
(width, height) - width includes label + decorations, height is always 1
- Return type:
tuple[int,int]
- render_signature()[source]
Paint memo for the skip-unchanged fast path.
Captures the label, visual style, and style-affecting state (focus/hover drive the
button/button:focus/button:hoverselector). SeeElement.render_signature().- Return type:
- render_to(ctx)[source]
Render button using cell-based rendering (NEW API).
- Parameters:
ctx (
PaintContext) – Paint context with buffer, style resolver, and bounds- Return type:
None
Notes
This is the reference implementation for cell-based rendering. It demonstrates how to: 1. Resolve styles based on element state (focused, hovered) 2. Apply different visual styles based on configuration 3. Write styled text to the cell buffer 4. Handle multi-character borders and decorations
The button renders as a single line with decorative borders based on the style setting.