focus_manager (cellium v0.1.0)
View SourceSummary
Functions
Checks if a widget with the given ID is registered and focusable. Returns true if the widget is focusable, false otherwise.
Returns the ID of the currently focused widget. Returns {ok, WidgetId} or {error, no_focus} if no widget has focus.
Moves focus to the previous focusable widget in reverse tab order. If at the beginning of the list, wraps around to the end. Returns ok on success or {error, no_widgets} if no focusable widgets registered.
Moves focus to the next focusable widget in tab order. If at the end of the list, wraps around to the beginning. Returns ok on success or {error, no_widgets} if no focusable widgets registered.
Registers a widget as focusable in the application. WidgetId is a unique identifier for the widget. WidgetRef is a reference or handle to the actual widget. Returns ok on success or {error, Reason} on failure.
Sets focus to a specific widget by its ID. Sends a focus_changed event with {lost, PreviousId} and {gained, NewId}. Returns ok on success or {error, not_found} if widget doesn't exist.
Starts the focus manager gen_server. Initializes with an empty list of focusable widgets.
Starts the focus manager with initial configuration. Config can contain initial focusable widget list and starting focus.
Unregisters a widget from the focusable widget list. If the unregistered widget had focus, focus moves to the next widget. Returns ok on success or {error, not_found} if widget not registered.
Functions
-spec can_focus(WidgetId :: term()) -> true | false.
Checks if a widget with the given ID is registered and focusable. Returns true if the widget is focusable, false otherwise.
-spec get_focused() -> {ok, WidgetId :: term()} | {error, no_focus}.
Returns the ID of the currently focused widget. Returns {ok, WidgetId} or {error, no_focus} if no widget has focus.
-spec list_all() -> [WidgetId :: term()].
-spec move_focus_backward() -> ok | {error, no_widgets}.
Moves focus to the previous focusable widget in reverse tab order. If at the beginning of the list, wraps around to the end. Returns ok on success or {error, no_widgets} if no focusable widgets registered.
-spec move_focus_forward() -> ok | {error, no_widgets}.
Moves focus to the next focusable widget in tab order. If at the end of the list, wraps around to the beginning. Returns ok on success or {error, no_widgets} if no focusable widgets registered.
-spec register_widget(WidgetId :: term()) -> ok | {error, already_registered | invalid_widget}.
Registers a widget as focusable in the application. WidgetId is a unique identifier for the widget. WidgetRef is a reference or handle to the actual widget. Returns ok on success or {error, Reason} on failure.
Widgets are registered in the order they can be focused (tab order).
-spec remove_all() -> reset.
-spec set_focus(WidgetId :: term()) -> ok | {error, not_found}.
Sets focus to a specific widget by its ID. Sends a focus_changed event with {lost, PreviousId} and {gained, NewId}. Returns ok on success or {error, not_found} if widget doesn't exist.
Starts the focus manager gen_server. Initializes with an empty list of focusable widgets.
Starts the focus manager with initial configuration. Config can contain initial focusable widget list and starting focus.
-spec unregister_widget(WidgetId :: term()) -> ok | {error, not_found}.
Unregisters a widget from the focusable widget list. If the unregistered widget had focus, focus moves to the next widget. Returns ok on success or {error, not_found} if widget not registered.