forked from opentx/lua-reference-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawCombobox-example.lua
More file actions
77 lines (70 loc) · 1.89 KB
/
drawCombobox-example.lua
File metadata and controls
77 lines (70 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local comboOptions
local selectedOption
local selectedSize
local editMode
local activeField
local fieldMax
local function valueIncDec(event,value,min,max,step)
if editMode then
if event==EVT_PLUS_FIRST or event==EVT_PLUS_REPT then
if value<=max-step then
value=value+step
end
elseif event==EVT_MINUS_FIRST or event==EVT_MINUS_REPT then
if value>=min+step then
value=value-step
end
end
end
return value
end
local function fieldIncDec(event,value,max,force)
if editMode or force==true then
if event==EVT_PLUS_FIRST then
value=value+max
elseif event==EVT_MINUS_FIRST then
value=value+max+2
end
value=value%(max+1)
end
return value
end
local function getFieldFlags(p)
local flg = 0
if activeField==p then
flg=INVERS
if editMode then
flg=INVERS+BLINK
end
end
return flg
end
local function init()
fieldMax = 1
comboOptions = {"Triangle","Circle","Square"}
selectedOption = 0
activeField = 0
selectedSize = 0
end
local function run(event)
lcd.clear()
-- draw from the bottom up so we don't overwrite the combo box if open
lcd.drawText(19, 32, "Pick a size:", 0)
lcd.drawText(lcd.getLastPos() + 2, 32, selectedSize, getFieldFlags(1))
lcd.drawText(1, 1, "drawComboBox() telemetry example",0)
lcd.drawText(1, 17, "Pick an option:", 0)
lcd.drawCombobox(lcd.getLastPos() + 2, 15, 70, comboOptions, selectedOption, getFieldFlags(0))
if event == EVT_ENTER_BREAK then
editMode = not editMode
end
if editMode then
if activeField == 0 then
selectedOption = fieldIncDec(event, selectedOption, 2)
elseif activeField == 1 then
selectedSize = valueIncDec(event, selectedSize, 0, 10, 1)
end
else
activeField = fieldIncDec(event, activeField, fieldMax, true)
end
end
return{run=run, init=init}