Scenic Scrollable v0.1.0 Scenic.Scrollable.Hotkeys View Source

This module handles key mappings and keypress events for Scenic.Scrollable components.

Link to this section Summary

Types

The keymap used internally to determine if, and what key is set for a certain movement. TODO support multiple keys for a single movement

Button state containing information on if a key is currently pressed or released

Data structure containing information on the pressed state of all available hotkeys

A keycode represented by a string. The string corresponds to the character as seen on the keyboard, rather than a numeric keycode. Special keys are generally spelled out in lower case characters, such as "enter" or "escape"

The hotkey settings which can be passed in as style when creating a scrollable component. Hotkeys are optional and available for 'up', 'down', 'left' and 'right' scroll movements

t()

The data structure used as state by this module. It contains information on what keys are mapped to what functionality, and which keys are currently being pressed

Functions

Obtain the current scroll direction based on the keys currently being pressed as a t:Scenic.Math.vector_2. For example, when the 'left' key and the 'up' key are currently being pressed, the vector {-1, 1} describing the corresponding direction will be returned

Modifies the hotkey state accordingly to the key mappings and the keycode passed. When the passed keycode is set as one of the mapped keys, that key will be flagged as being pressed

Modifies the hotkey state accordingly to the key mappings and the keycode passed. When the passed keycode is set as one of the mapped keys, that key will be flagged as being released

Initialize the state this module acts upon, by passing it the Scenic.Scrollable.Hotkeys.settings/0 settings map. When nil is passed as argument, the default settings will be used. Returns a Scenic.Scrollable.Hotkeys.t/0

Verify if one or more hotkeys are currently being pressed

Link to this section Types

Link to this type

key_map() View Source
key_map() :: %{
  up: :none | {:some, keycode()},
  down: :none | {:some, keycode()},
  left: :none | {:some, keycode()},
  right: :none | {:some, keycode()}
}

The keymap used internally to determine if, and what key is set for a certain movement. TODO support multiple keys for a single movement.

Link to this type

key_pressed_state() View Source
key_pressed_state() :: :released | :pressed

Button state containing information on if a key is currently pressed or released.

Link to this type

key_pressed_states() View Source
key_pressed_states() :: %{
  up: key_pressed_state(),
  down: key_pressed_state(),
  left: key_pressed_state(),
  right: key_pressed_state()
}

Data structure containing information on the pressed state of all available hotkeys.

A keycode represented by a string. The string corresponds to the character as seen on the keyboard, rather than a numeric keycode. Special keys are generally spelled out in lower case characters, such as "enter" or "escape".

Link to this type

settings() View Source
settings() :: %{
  optional(:up) => keycode(),
  optional(:down) => keycode(),
  optional(:left) => keycode(),
  optional(:right) => keycode()
}

The hotkey settings which can be passed in as style when creating a scrollable component. Hotkeys are optional and available for 'up', 'down', 'left' and 'right' scroll movements.

Link to this type

t() View Source
t() :: %Scenic.Scrollable.Hotkeys{
  key_map: key_map(),
  key_pressed_states: key_pressed_states()
}

The data structure used as state by this module. It contains information on what keys are mapped to what functionality, and which keys are currently being pressed.

Link to this section Functions

Obtain the current scroll direction based on the keys currently being pressed as a t:Scenic.Math.vector_2. For example, when the 'left' key and the 'up' key are currently being pressed, the vector {-1, 1} describing the corresponding direction will be returned.

Link to this function

handle_key_press(state, key) View Source
handle_key_press(t(), keycode()) :: t()

Modifies the hotkey state accordingly to the key mappings and the keycode passed. When the passed keycode is set as one of the mapped keys, that key will be flagged as being pressed.

Link to this function

handle_key_release(state, key) View Source

Modifies the hotkey state accordingly to the key mappings and the keycode passed. When the passed keycode is set as one of the mapped keys, that key will be flagged as being released.

Link to this function

init(settings) View Source
init(settings() | nil) :: t()

Initialize the state this module acts upon, by passing it the Scenic.Scrollable.Hotkeys.settings/0 settings map. When nil is passed as argument, the default settings will be used. Returns a Scenic.Scrollable.Hotkeys.t/0.

Link to this function

is_any_key_pressed?(map) View Source
is_any_key_pressed?(t()) :: boolean()

Verify if one or more hotkeys are currently being pressed.