Skip to content

Commit 4141049

Browse files
authored
Merge pull request #245 from boydm/docs_cleanup
Fix docs for Scenic.Driver.KeyMap
2 parents be91165 + 9d84b18 commit 4141049

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lib/scenic/driver/key_map.ex

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
#
55

66
defmodule Scenic.Driver.KeyMap do
7-
@moduledoc false
7+
@moduledoc """
8+
Behaviour and support functions for mapping physical keys to characters.
9+
10+
This module is meant to be implemented elsewhere and provided to a driver
11+
in order to localize key presses into the correct characters.
12+
13+
The `:scenic_driver_local` driver comes with a USEnglish key map, which it
14+
uses by default. Look at that one as an example on how to make a custom
15+
key mapping.
16+
"""
817

918
# @doc """
1019
# Map of current key state. A key with a value of 1 is pressed. A key with
@@ -15,7 +24,15 @@ defmodule Scenic.Driver.KeyMap do
1524
# """
1625
@type keys :: %{atom => integer}
1726

18-
@type mods :: [:meta | :alt | :ctrl | :shift | :caps_lock | :num_lock | :scroll_lock]
27+
@type mod_keys :: [
28+
:meta
29+
| :alt
30+
| :ctrl
31+
| :shift
32+
| :caps_lock
33+
| :num_lock
34+
| :scroll_lock
35+
]
1936

2037
@doc """
2138
Translate a key to a codepoint, which is really just a string.
@@ -25,7 +42,7 @@ defmodule Scenic.Driver.KeyMap do
2542
2643
If the mapping is successful, i.e. the key press results in a valid character,
2744
Then this function should return `{ :ok, codepoint, state }`. The returned
28-
codepoint will be sent on to the ViewPort as a codepoint intput event.
45+
codepoint will be sent on to the ViewPort as a codepoint input event.
2946
3047
If the key press does not map to a string (this is common), then the function
3148
should return `{ :ok, nil, state }`. This will not result in a codepoint input
@@ -115,7 +132,7 @@ defmodule Scenic.Driver.KeyMap do
115132
@doc """
116133
Generate the list of pressed modifier keys
117134
"""
118-
@spec mods(keys :: keys) :: mods
135+
@spec mods(keys :: keys) :: mod_keys
119136
def mods(keys) do
120137
[]
121138
|> add_if_set(:meta, meta?(keys))

lib/scenic/view_port/input.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ defmodule Scenic.ViewPort.Input do
7474
# import IEx
7575

7676
@type t ::
77-
{:codepoint, {codepoint :: String.t(), mods :: KeyMap.mods()}}
78-
| {:key, {key :: atom, value :: integer, mods :: KeyMap.mods()}}
77+
{:codepoint, {codepoint :: String.t(), mods :: KeyMap.mod_keys()}}
78+
| {:key, {key :: atom, value :: integer, mods :: KeyMap.mod_keys()}}
7979
| {:cursor_button,
80-
{button :: atom, value :: integer, mods :: KeyMap.mods(), position :: Math.point()}}
80+
{button :: atom, value :: integer, mods :: KeyMap.mod_keys(),
81+
position :: Math.point()}}
8182
| {:cursor_scroll, {offset :: Math.point(), position :: Math.point()}}
8283
| {:cursor_pos, position :: Math.point()}
8384
| {:viewport, {:enter | :exit | :reshape, xy :: Math.point()}}

0 commit comments

Comments
 (0)