Skip to content

FocusManager

#include <FocusManager.hpp>

Manages focus among widgets, including traversal and event dispatching.

ReturnNameDescription
voidsetFocusSet focus to any widget.
voidclearFocusClear focus from any widget.
std::shared_ptr< Widget >focused const inlineGet the currently focused widget, if any.
voidfocusNextMove focus to the next focusable widget in the tree.
voidfocusPrevMove focus to the previous focusable widget in the tree.
booldispatchToFocusedDispatch an event to the currently focused widget, if any.
booldispatchDispatch an event This also includes handling of global focus-related keys like Tab and Escape.
voidfocusTopOverlayFocus the top overlay from the overlay stack.

void setFocus(std::shared_ptr< Widget > w)

Set focus to any widget.

  • w The widget to receive focus.

void clearFocus()

Clear focus from any widget.


const inline

inline std::shared_ptr< Widget > focused() const

Get the currently focused widget, if any.


void focusNext(std::shared_ptr< Widget > root)

Move focus to the next focusable widget in the tree.

  • root The root widget for focus traversal

void focusPrev(std::shared_ptr< Widget > root)

Move focus to the previous focusable widget in the tree.

  • root The root widget for focus traversal

bool dispatchToFocused(const events::Event & e)

Dispatch an event to the currently focused widget, if any.

  • e The event to dispatch

bool dispatch(const events::Event & e, std::shared_ptr< Widget > root)

Dispatch an event This also includes handling of global focus-related keys like Tab and Escape.

  • e The event to dispatch

  • root The root widget for focus traversal if needed (e.g. on Tab key))


void focusTopOverlay()

Focus the top overlay from the overlay stack.

ReturnNameDescription
std::weak_ptr< Widget >currentThe currently focused Widget.

std::weak_ptr< Widget > current

The currently focused Widget.

ReturnNameDescription
voidcollectFocusableCollect the focusable widgets Recursively traverses the widget tree to find all focusable widgets and adds them to the output vector.

void collectFocusable(std::shared_ptr< Widget > w, std::vector< std::shared_ptr< Widget > > & out)

Collect the focusable widgets Recursively traverses the widget tree to find all focusable widgets and adds them to the output vector.

  • w The widget to start traversal from

  • out The output vector to collect focusable widgets into