ElixirOpentui.Focus (ElixirOpentui v0.2.0)

Copy Markdown View Source

Focus management for the element tree.

Tracks which element is currently focused, supports tab navigation (next/prev focusable), and resolves focus targets from mouse clicks by walking up the tree to find the nearest focusable ancestor.

Focus state is a simple value — no process needed. The Runtime holds the current focus state in its model.

Summary

Functions

Clear focus.

Set focus to a specific element id.

Move focus to the next focusable element (Tab).

Move focus to the previous focusable element (Shift+Tab).

Build focus state from an element tree.

Resolve focus target from a hit_id by walking up the tree.

Update focus state when the tree changes (e.g., elements added/removed).

Types

t()

@type t() :: %ElixirOpentui.Focus{focusable_ids: [term()], focused_id: term() | nil}

Functions

blur(state)

@spec blur(t()) :: t()

Clear focus.

focus(state, id)

@spec focus(t(), term()) :: t()

Set focus to a specific element id.

focus_next(state)

@spec focus_next(t()) :: t()

Move focus to the next focusable element (Tab).

focus_prev(state)

@spec focus_prev(t()) :: t()

Move focus to the previous focusable element (Shift+Tab).

from_tree(tree)

@spec from_tree(ElixirOpentui.Element.t()) :: t()

Build focus state from an element tree.

resolve_focus_target(tree, hit_id)

@spec resolve_focus_target(ElixirOpentui.Element.t(), term()) :: term() | nil

Resolve focus target from a hit_id by walking up the tree.

update_tree(state, tree)

@spec update_tree(t(), ElixirOpentui.Element.t()) :: t()

Update focus state when the tree changes (e.g., elements added/removed).