ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::ui::FocusManager Class Reference

Manages focus navigation for UI widgets. More...

#include <context.h>

Collaboration diagram for asw::ui::FocusManager:
[legend]

Public Member Functions

Widget * focused () const
 Get the currently focused widget.
 
void set_focus (Context &ctx, Widget *w)
 Set focus to a specific widget.
 
void focus_next (Context &ctx)
 Move focus to the next focusable widget.
 
void focus_prev (Context &ctx)
 Move focus to the previous focusable widget.
 
bool focus_start (Context &ctx)
 Focus default_focus, or the first focusable widget, when nothing has focus.
 
void focus_dir (Context &ctx, int dx, int dy)
 Move focus in a direction based on widget positions.
 

Public Attributes

Widget * default_focus = nullptr
 Widget focused by the first navigation press when nothing has focus. The first focusable widget when null.
 

Private Member Functions

void rebuild (Context &ctx, Widget &root)
 
void dfs (Widget &w)
 

Private Attributes

std::vector< Widget * > _focusables
 
Widget * _focused = nullptr
 
bool _focused_found = false
 
std::optional< float > _lane_x
 
std::optional< float > _lane_y
 

Friends

class Root
 

Detailed Description

Manages focus navigation for UI widgets.

Definition at line 23 of file context.h.

Member Function Documentation

◆ dfs()

void asw::ui::FocusManager::dfs ( Widget & w)
private

Definition at line 197 of file context.cpp.

◆ focus_dir()

void asw::ui::FocusManager::focus_dir ( Context & ctx,
int dx,
int dy )

Move focus in a direction based on widget positions.

A widget's nav_up, nav_down, nav_left or nav_right wins when set. Otherwise widgets in the same lane (overlapping across the direction) win over the rest, then the nearest edge to edge, then the one closest to the lane repeated moves started in.

Parameters
ctxThe UI context.
dxHorizontal direction (-1, 0, or 1).
dyVertical direction (-1, 0, or 1).

Definition at line 94 of file context.cpp.

◆ focus_next()

void asw::ui::FocusManager::focus_next ( Context & ctx)

Move focus to the next focusable widget.

Parameters
ctxThe UI context.

Definition at line 50 of file context.cpp.

◆ focus_prev()

void asw::ui::FocusManager::focus_prev ( Context & ctx)

Move focus to the previous focusable widget.

Parameters
ctxThe UI context.

Definition at line 71 of file context.cpp.

◆ focus_start()

bool asw::ui::FocusManager::focus_start ( Context & ctx)

Focus default_focus, or the first focusable widget, when nothing has focus.

Parameters
ctxThe UI context.
Returns
True if focus was set.

Definition at line 19 of file context.cpp.

◆ focused()

Widget * asw::ui::FocusManager::focused ( ) const
inline

Get the currently focused widget.

Returns
Pointer to the focused widget, or nullptr.

Definition at line 29 of file context.h.

◆ rebuild()

void asw::ui::FocusManager::rebuild ( Context & ctx,
Widget & root )
private

Definition at line 7 of file context.cpp.

◆ set_focus()

void asw::ui::FocusManager::set_focus ( Context & ctx,
Widget * w )

Set focus to a specific widget.

Parameters
ctxThe UI context.
wThe widget to focus.

Definition at line 31 of file context.cpp.

Friends And Related Symbol Documentation

◆ Root

friend class Root
friend

Definition at line 77 of file context.h.

Member Data Documentation

◆ _focusables

std::vector<Widget*> asw::ui::FocusManager::_focusables
private

Definition at line 84 of file context.h.

◆ _focused

Widget* asw::ui::FocusManager::_focused = nullptr
private

Definition at line 85 of file context.h.

◆ _focused_found

bool asw::ui::FocusManager::_focused_found = false
private

Definition at line 88 of file context.h.

◆ _lane_x

std::optional<float> asw::ui::FocusManager::_lane_x
private

Definition at line 91 of file context.h.

◆ _lane_y

std::optional<float> asw::ui::FocusManager::_lane_y
private

Definition at line 92 of file context.h.

◆ default_focus

Widget* asw::ui::FocusManager::default_focus = nullptr

Widget focused by the first navigation press when nothing has focus. The first focusable widget when null.

Definition at line 43 of file context.h.


The documentation for this class was generated from the following files: