-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
231 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
local icon_mappings = { | ||
keyboard = { | ||
a = "Key A", | ||
b = "Key B", | ||
c = "Key C", | ||
d = "Key D", | ||
e = "Key E", | ||
f = "Key F", | ||
g = "Key G", | ||
h = "Key H", | ||
i = "Key I", | ||
j = "Key J", | ||
k = "Key K", | ||
l = "Key L", | ||
m = "Key M", | ||
n = "Key N", | ||
o = "Key O", | ||
p = "Key P", | ||
q = "Key Q", | ||
r = "Key R", | ||
s = "Key S", | ||
t = "Key T", | ||
u = "Key U", | ||
v = "Key V", | ||
w = "Key W", | ||
x = "Key X", | ||
y = "Key Y", | ||
z = "Key Z", | ||
[0] = "Key 0", | ||
[1] = "Key 1", | ||
[2] = "Key 2", | ||
[3] = "Key 3", | ||
[4] = "Key 4", | ||
[5] = "Key 5", | ||
[6] = "Key 6", | ||
[7] = "Key 7", | ||
[8] = "Key 8", | ||
[9] = "Key 9", | ||
space = "Space", | ||
["!"] = "ASCII !", | ||
['"'] = 'ASCII "', | ||
["#"] = "ASCII #", | ||
["$"] = "ASCII $", | ||
["&"] = "ASCII &", | ||
["'"] = "ASCII '", | ||
["("] = "ASCII (", | ||
[")"] = "ASCII )", | ||
["*"] = "ASCII *", | ||
["+"] = "ASCII +", | ||
[","] = "ASCII ,", | ||
["-"] = "ASCII -", | ||
["."] = "ASCII .", | ||
["/"] = "ASCII /", | ||
[":"] = "ASCII :", | ||
[";"] = "ASCII ;", | ||
["<"] = "ASCII <", | ||
["="] = "ASCII =", | ||
[">"] = "ASCII >", | ||
["?"] = "ASCII ?", | ||
["@"] = "ASCII @", | ||
["["] = "ASCII [", | ||
["\\"] = "ASCII \\", | ||
["]"] = "ASCII ]", | ||
["^"] = "ASCII ^", | ||
["_"] = "ASCII _", | ||
["`"] = "ASCII `", | ||
kp0 = "", | ||
kp1 = "", | ||
kp2 = "", | ||
kp3 = "", | ||
kp4 = "", | ||
kp5 = "", | ||
kp6 = "", | ||
kp7 = "", | ||
kp8 = "", | ||
kp9 = "", | ||
["kp."] = "", | ||
["kp,"] = "", | ||
["kp/"] = "", | ||
["kp*"] = "", | ||
["kp-"] = "", | ||
["kp+"] = "", | ||
kpenter = "", | ||
["kp="] = "", | ||
up = "Arrow Up", | ||
down = "Arrow Down", | ||
right = "Arrow Right", | ||
left = "Arrow Left", | ||
home = "Home", | ||
["end"] = "End", | ||
pageup = "Page Up", | ||
pagedown = "Page Down", | ||
insert = "Insert", | ||
backspace = "Backspace", | ||
tab = "Tab", | ||
clear = "", | ||
["return"] = "Enter", | ||
delete = "Delete", | ||
f1 = "F1", | ||
f2 = "F2", | ||
f3 = "F3", | ||
f4 = "F4", | ||
f5 = "F5", | ||
f6 = "F6", | ||
f7 = "F7", | ||
f8 = "F8", | ||
f9 = "F9", | ||
f10 = "F10", | ||
f11 = "F11", | ||
f12 = "F12", | ||
f13 = "", | ||
f14 = "", | ||
f15 = "", | ||
f16 = "", | ||
f17 = "", | ||
f18 = "", | ||
numlock = "NumLock", | ||
capslock = "Caps", | ||
scrolllock = "ScrLk", | ||
rshift = "", | ||
lshift = "Shift", | ||
rctrl = "", | ||
lctrl = "Ctrl", | ||
ralt = "", | ||
lalt = "Alt", | ||
rgui = "", | ||
lgui = "Super", | ||
mode = "", | ||
www = "", | ||
mail = "", | ||
calculator = "", | ||
computer = "", | ||
appsearch = "", | ||
apphome = "", | ||
appback = "", | ||
appforward = "", | ||
apprefresh = "", | ||
appbookmarks = "", | ||
pause = "Pause", | ||
escape = "Esc", | ||
help = "", | ||
printscreen = "PrtSc", | ||
sysreq = "", | ||
menu = "", | ||
application = "", | ||
power = "", | ||
currencyunit = "", | ||
undo = "", | ||
}, | ||
mouse = { | ||
l = "Mouse Button 1", | ||
m = "Mouse Button 3", | ||
r = "Mouse Button 2", | ||
wd = "Scroll Down", | ||
wu = "Scroll Up", | ||
x1 = "Mouse Button 4", | ||
x2 = "Mouse Button 5", | ||
}, | ||
touch = { | ||
left = "square-half", | ||
right = "square-half:mirror", | ||
}, | ||
} | ||
local icon = require("ui.elements.icon") | ||
local input_schemes = require("input_schemes") | ||
local async = require("async") | ||
|
||
local input = {} | ||
input.__index = setmetatable(input, icon) | ||
|
||
function input:new(scheme, id, options) | ||
local icon_id = icon_mappings[scheme][id] | ||
if icon_id == "" then | ||
-- set it to something known for now to change later | ||
icon_id = "circle" -- no input has this icon | ||
end | ||
local obj = icon:new(icon_id, options) | ||
setmetatable(obj, input) | ||
if icon_id == "circle" then | ||
-- no icon found for input, display text instead | ||
obj.raw_text = id | ||
end | ||
obj.scheme = scheme | ||
obj.waiting = false | ||
return obj | ||
end | ||
|
||
function input:set_icon(id) | ||
local icon_id = icon_mappings[self.scheme][id] | ||
if icon_id ~= "" then | ||
self:set(icon_id) | ||
else | ||
self.raw_text = id | ||
self.changed = true | ||
end | ||
end | ||
|
||
function input:process_event(name, ...) | ||
icon.process_event(self, name, ...) | ||
if self.waiting and self.resolve then | ||
for id in pairs(icon_mappings[self.scheme]) do | ||
if input_schemes[self.scheme].is_down(id) then | ||
self.resolve(id) | ||
self.resolve = nil | ||
break | ||
end | ||
end | ||
else | ||
require("ui").only_interactable_element = nil | ||
end | ||
end | ||
|
||
input.wait_for_input = async(function(self) | ||
self.waiting = true | ||
self.text:set("") | ||
local ui = require("ui") | ||
ui.only_interactable_element = self | ||
local id = async.await(async.promise:new(function(resolve) | ||
self.resolve = resolve | ||
end)) | ||
self.waiting = false | ||
self:set_icon(id) | ||
end) | ||
|
||
return input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters