Keyboard focus - Factor Documentation (original) (raw)

The gadget with keyboard focus is the current receiver of keyboard gestures and user input. Gadgets that wish to receive keyboard input should request focus when clicked:
request-focus ( gadget -- )

The following example demonstrates defining a handler for a mouse click gesture which requests focus:

my-gadget H{ { T{ button-down } [ request-focus ] } } set-gestures

To nominate a single child as the default focusable child, implement a method on a generic word:
focusable-child* ( gadget -- child/f )

Gestures are sent to a gadget when it gains or loses focus; this can be used to change the gadget's appearance, for example by displaying a border:
gain-focus
lose-focus