View Source KeyboardLayout (keyboard_layout v0.1.1)
Describes a keyboard layout.
The layout can be created dynamically, or it can be predefined in the Config
for the application.
Example of a layout defined in Config
:
import Config
config :keyboard_layout,
layout: [
leds: [
%{id: :l1, x: 0, y: 0},
%{id: :l2, x: 2, y: 1.5},
%{id: :l3, x: 3, y: 3}
],
keys: [
%{id: :k1, x: 0, y: 0, opts: [led: :l1]},
%{id: :k2, x: 2, y: 1.5, opts: [width: 1.5, height: 2, led: :l2]},
%{id: :k3, x: 5, y: 0}
]
]
Link to this section Summary
Link to this section Types
@type t() :: %KeyboardLayout{ keys: [KeyboardLayout.Key.t()], keys_by_leds: %{required(KeyboardLayout.LED.id()) => KeyboardLayout.Key.t()}, leds: [KeyboardLayout.LED.t()], leds_by_keys: %{required(KeyboardLayout.Key.id()) => KeyboardLayout.LED.t()} }
Link to this section Functions
@spec key_for_led(layout :: t(), KeyboardLayout.LED.id()) :: KeyboardLayout.Key.t() | nil
Returns the corresponding key from the provided layout and LED id.
Returns nil
if the key has no LED.
@spec keys(layout :: t()) :: [KeyboardLayout.Key.t()]
@spec led_for_key(layout :: t(), KeyboardLayout.Key.id()) :: KeyboardLayout.LED.t() | nil
Returns the corresponding LED from the provided layout and key id.
Returns nil
if the LED does not belong to a key.
@spec leds(layout :: t()) :: [KeyboardLayout.LED.t()]
@spec load_from_config() :: t()
@spec new(keys :: [KeyboardLayout.Key.t()], leds :: [KeyboardLayout.LED.t()]) :: t()
Creates a new KeyboardLayout from a list of keys and LEDs. LEDs are optional.
Example:
iex> keys = [KeyboardLayout.Key.new(:k1, 0, 0, led: :l1)]
[%KeyboardLayout.Key{height: 1, id: :k1, led: :l1, width: 1, x: 0, y: 0}]
iex> leds = [KeyboardLayout.LED.new(:l1, 0, 0)]
[%KeyboardLayout.LED{id: :l1, x: 0, y: 0}]
iex> KeyboardLayout.new(keys, leds)
%KeyboardLayout{
keys: [
%KeyboardLayout.Key{height: 1, id: :k1, led: :l1, width: 1, x: 0, y: 0}
],
keys_by_leds: %{
l1: %KeyboardLayout.Key{height: 1, id: :k1, led: :l1, width: 1, x: 0, y: 0}
},
leds: [
%KeyboardLayout.LED{id: :l1, x: 0, y: 0}
],
leds_by_keys: %{
k1: %KeyboardLayout.LED{id: :l1, x: 0, y: 0}
}
}