Skip to content

1681-engine / ui / FocusManager

Class: FocusManager ​

Defined in: src/ui/FocusManager.ts:48

Keyboard and gamepad navigation between widgets: directions move spatially (to the nearest widget that way), Tab steps in tree order, Accept activates, Cancel asks the innermost scope. A modal pushes a scope, and focus cannot leave it until it is popped (the focus trap). The list of focusable widgets is collected only when stale.

Constructors ​

Constructor ​

ts
new FocusManager(root, bindings?): FocusManager;

Defined in: src/ui/FocusManager.ts:53

Parameters ​

ParameterTypeDefault value
rootContainerundefined
bindingsNavBindingsDEFAULT_NAV

Returns ​

FocusManager

Properties ​

bindings ​

ts
readonly bindings: NavBindings = DEFAULT_NAV;

Defined in: src/ui/FocusManager.ts:55

Accessors ​

focused ​

Get Signature ​

ts
get focused(): Widget | null;

Defined in: src/ui/FocusManager.ts:60

Returns ​

Widget | null


scope ​

Get Signature ​

ts
get scope(): Container;

Defined in: src/ui/FocusManager.ts:86

The innermost scope's container (the open dialog, or the root).

Returns ​

Container

Methods ​

focus() ​

ts
focus(w): void;

Defined in: src/ui/FocusManager.ts:90

Parameters ​

ParameterType
wWidget | null

Returns ​

void


handle() ​

ts
handle(input): boolean;

Defined in: src/ui/FocusManager.ts:125

Reads one step of input; call it between the game's actions.poll() and endStep(). True when the UI used a press, so the game leaves it alone.

Parameters ​

ParameterType
inputNavInput

Returns ​

boolean


invalidate() ​

ts
invalidate(): void;

Defined in: src/ui/FocusManager.ts:65

The focusable widgets changed (added, removed, shown, hidden, enabled): collect them again on the next move.

Returns ​

void


move() ​

ts
move(dir): boolean;

Defined in: src/ui/FocusManager.ts:101

Moves focus one way; the first press with nothing focused lands on the top-left widget.

Parameters ​

ParameterType
dirNavDirection

Returns ​

boolean


popScope() ​

ts
popScope(container): void;

Defined in: src/ui/FocusManager.ts:77

Parameters ​

ParameterType
containerContainer

Returns ​

void


pushScope() ​

ts
pushScope(container, onCancel?): void;

Defined in: src/ui/FocusManager.ts:71

Traps focus inside container until popScope; onCancel answers Cancel there (true when it used it).

Parameters ​

ParameterTypeDefault value
containerContainerundefined
onCancel(() => boolean) | nullnull

Returns ​

void


step() ​

ts
step(step): boolean;

Defined in: src/ui/FocusManager.ts:113

Tab (1) or Shift+Tab (−1), in tree order, wrapping.

Parameters ​

ParameterType
step-1 | 1

Returns ​

boolean

Released under the MIT License.