Module: Zif::KeyPressable

Included in:
UI::Input
Defined in:
lib/zif/key_pressable.rb

Overview

A mixin to allow compatibility with Services::InputService

Set key down handler attributes #on_key_down to Lambdas accepting the key argument to do something with this object when keyboard events happen.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#on_key_downLambda

Returns Called when the key is pressed down. Called with the key that was pressed.

Returns:

  • (Lambda)

    Called when the key is pressed down. Called with the key that was pressed



9
10
11
# File 'lib/zif/key_pressable.rb', line 9

def on_key_down
  @on_key_down
end

Instance Method Details

#handle_key(text_key, all_keys) ⇒ Object

Returns nil.

Parameters:

  • text_key (<String>)

    a single character from the keyboard, suitable for adding to the field

  • all_keys (Array<Symbol>)

    truthy values from the keyboard includes modifiers like delete and backspace.

Returns:

  • nil



14
15
16
17
# File 'lib/zif/key_pressable.rb', line 14

def handle_key(text_key, all_keys)
  # puts "KeyPressable: handle_key?: #{text_key} :#{all_keys}"
  on_key_down&.call(text_key, all_keys)
end