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 ​
new FocusManager(root, bindings?): FocusManager;Defined in: src/ui/FocusManager.ts:53
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
root | Container | undefined |
bindings | NavBindings | DEFAULT_NAV |
Returns ​
FocusManager
Properties ​
bindings ​
readonly bindings: NavBindings = DEFAULT_NAV;Defined in: src/ui/FocusManager.ts:55
Accessors ​
focused ​
Get Signature ​
get focused(): Widget | null;Defined in: src/ui/FocusManager.ts:60
Returns ​
Widget | null
scope ​
Get Signature ​
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() ​
focus(w): void;Defined in: src/ui/FocusManager.ts:90
Parameters ​
| Parameter | Type |
|---|---|
w | Widget | null |
Returns ​
void
handle() ​
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 ​
| Parameter | Type |
|---|---|
input | NavInput |
Returns ​
boolean
invalidate() ​
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() ​
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 ​
| Parameter | Type |
|---|---|
dir | NavDirection |
Returns ​
boolean
popScope() ​
popScope(container): void;Defined in: src/ui/FocusManager.ts:77
Parameters ​
| Parameter | Type |
|---|---|
container | Container |
Returns ​
void
pushScope() ​
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 ​
| Parameter | Type | Default value |
|---|---|---|
container | Container | undefined |
onCancel | (() => boolean) | null | null |
Returns ​
void
step() ​
step(step): boolean;Defined in: src/ui/FocusManager.ts:113
Tab (1) or Shift+Tab (−1), in tree order, wrapping.
Parameters ​
| Parameter | Type |
|---|---|
step | -1 | 1 |
Returns ​
boolean