xnano.utils.focus
xnano.utils.focus
¶
xnano.utils.focus
Discover, move, and synchronize focus across grid fields.
Functions:
-
is_component–Return whether a value follows the component contract.
-
is_focusable_component–Return whether a component accepts field focus.
-
uses_default_component_size–Return whether a component uses the default layout size.
-
get_focusable_component–Return a focusable component stored in one grid field.
-
field_group–Return the configured group for a grid field.
-
collect_focusable_fields–Collect focusable fields from the runtime's root grid.
-
collect_group_targets–Map focus group names to their first matching field.
-
resolve_group_target–Return the field targeted by a focus group.
-
set_field_focus–Set the focused field and synchronize component flags.
-
clear_field_focus–Clear the active field focus.
-
focus_group–Focus the field registered for a group.
-
focused_group_name–Return the focused field's group name.
-
is_group_focused–Return whether a focus group is active.
-
focused_component–Return the component inside the focused field.
-
sync_input_focus_flags–Synchronize component and field-state focus flags.
-
cycle_field_focus–Move focus forward or backward through focusable fields.
-
ensure_default_field_focus–Apply autofocus or select the first focusable field.
-
spatial_focus_enabled–Return whether any focusable field declares
autofocus. -
move_field_focus–Move focus to the nearest focusable field in
direction. -
apply_text_keyboard–Send keyboard input to a focused text component.
-
place_cursor_for_focus–Show and place the terminal caret at the focused input, else hide it.
-
scroll_handle_for_group–Return mutable scroll state for a grouped scroll field.
is_component
¶
is_focusable_component
¶
uses_default_component_size
¶
Return whether a component uses the default layout size.
get_focusable_component
¶
Return a focusable component stored in one grid field.
field_group
¶
Return the configured group for a grid field.
collect_focusable_fields
¶
collect_focusable_fields(terminal: Any) -> list[FieldFocus]
Collect focusable fields from the runtime's root grid.
Source code in xnano/utils/focus.py
collect_group_targets
¶
collect_group_targets(
terminal: Any,
) -> dict[str, FieldFocus]
Map focus group names to their first matching field.
resolve_group_target
¶
resolve_group_target(
terminal: Any, group: str
) -> FieldFocus | None
set_field_focus
¶
set_field_focus(
terminal: Any,
target: FieldFocus | None,
*,
fire_hooks: bool = True
) -> bool
Set the focused field and synchronize component flags.
Source code in xnano/utils/focus.py
clear_field_focus
¶
focus_group
¶
Focus the field registered for a group.
focused_group_name
¶
is_group_focused
¶
focused_component
¶
Return the component inside the focused field.
Source code in xnano/utils/focus.py
sync_input_focus_flags
¶
sync_input_focus_flags(terminal: Any) -> None
Synchronize component and field-state focus flags.
Source code in xnano/utils/focus.py
cycle_field_focus
¶
Move focus forward or backward through focusable fields.
Source code in xnano/utils/focus.py
ensure_default_field_focus
¶
ensure_default_field_focus(terminal: Any) -> None
Apply autofocus or select the first focusable field.
Source code in xnano/utils/focus.py
spatial_focus_enabled
¶
Return whether any focusable field declares autofocus.
Arrow-key and click focus movement is opt-in: it activates only when the
app uses Field(autofocus=True) somewhere, so apps that bind arrow keys
themselves keep their behavior.
Source code in xnano/utils/focus.py
move_field_focus
¶
Move focus to the nearest focusable field in direction.
Uses the live painted geometry of each focusable field; falls back to tab-order cycling when geometry is unavailable.
Source code in xnano/utils/focus.py
apply_text_keyboard
¶
Send keyboard input to a focused text component.
place_cursor_for_focus
¶
place_cursor_for_focus(terminal: Any) -> None
Show and place the terminal caret at the focused input, else hide it.
A focused text input reports an absolute cursor_position during
paint; the caret follows it and is shown. With nothing editable focused
the caret is hidden so a browsing UI shows no stray cursor.
Source code in xnano/utils/focus.py
scroll_handle_for_group
¶
scroll_handle_for_group(
terminal: Any, group: str
) -> ScrollHandle | None
Return mutable scroll state for a grouped scroll field.