I programmed an example for a 320x240 Display (ESP32-2432S028), that shows two menu pages, with three numerical input fields each.
When you click on an input field, a numpad pops out, where you can input numbers.
Leading zeroes are suppressed, the < button deletes, the = button accepts the input.
Comments welcome, especially if somebody has an idea how to simplify this.
Code: [Local Link Removed for Guests]
' ********** MAIN **********
dim results(6) ' array that holds the values given back by the numpad
results(1)=0 ' Value 0.1, page 0
results(2)=0 ' Value 0.2, page 0
results(3)=0 ' Value 0.3, page 0
results(4)=0 ' Value 1.1, page 1
results(5)=0 ' Value 1.2, page 1
results(6)=0 ' Value 1.3, page 1
numpad_value=0
gosub Page0 ' show Page 0
gui.autorefresh 30,1
wait
' ********* END MAIN *******
' ********* PAGE 0 INIT *****
Page0:
activepage = 0 ' set the number of the active page, so the numpad knows where to return to
numpadrunning = 0 ' Numpad is inactive
GUI.init 50, blue ' Reserve enough elements, as the numpad uses the same page
txt_Title = GUI.textline(0,0,320,30,"Page 0",4,yellow,blue)
btn_next = gui.button(290,0,30,30,">",4)
gui.setevent btn_next, 1, Page1
txt_value1 = gui.textline(130,40, 100,40,"Value 0.1",4,yellow,blue,blue)
but_V1 = gui.button(20,40,100,40,STR$(results(1)),4,0,0,1,black,white,red,red)
gui.setevent but_V1,1,V1click
txt_value2 = gui.textline(130,90, 100,40,"Value 0.2",4,yellow,blue,blue)
but_V2 = gui.button(20,90,100,40,STR$(results(2)),4,0,0,1,black,white,red,red)
gui.setevent but_V2,1,V2click
txt_value3 = gui.textline(130,140, 100,40,"Value 0.3",4,yellow,blue,blue)
but_V3 = gui.button(20,140,100,40,STR$(results(3)),4,0,0,1,black,white,red,red)
gui.setevent but_V3,1,V3click
Return
'********* PAGE 0 END *******
' ********* PAGE 1 INIT *****
Page1:
activepage = 1 ' set the number of the active page, so the numpad knows where to return to
numpadrunning = 0
GUI.init 50, red
txt_Title = GUI.textline(0,0,320,30,"Page 1",4,yellow,red)
btn_prev = gui.button(0,0,30,30,"<",4,0,0,1,yellow,red,red,yellow)
gui.setevent btn_prev, 1, Page0
txt_value4 = gui.textline(130,40, 100,40,"Value 1.1",4,yellow,red,red)
but_V4 = gui.button(20,40,100,40,STR$(results(4)),4,0,0,1,black,white,red,red)
gui.setevent but_V4,1,V4click
txt_value5 = gui.textline(130,90, 100,40,"Value 1.2",4,yellow,red,red)
but_V5 = gui.button(20,90,100,40,STR$(results(5)),4,0,0,1,black,white,red,red)
gui.setevent but_V5,1,V5click
txt_value6 = gui.textline(130,140, 100,40,"Value 1.3",4,yellow,red,red)
but_V6 = gui.button(20,140,100,40,STR$(results(6)),4,0,0,1,black,white,red,red)
gui.setevent but_V6,1,V6click
Return
'********* PAGE 0 END *******
' ******** V1CLICK **********
V1click:
If NOT numpadrunning Then ' activate numpad only when it isn't already running
numpad_limit=6 ' set the limit to 6 digits
numpad_x=150 ' set position of the numpad
numpad_y=30
numpad_target=but_V1 ' tell the numpad what input field to use
resultsindex=1 ' tell the numpad where to store the end value
Gosub numpad ' show numpad
Endif
while gui.getvalue(but_V1)=1 ' prevent V1click from triggering multiple times
wend
Return
'******* V1CLICK END *********
'******* V2CLICK *************
V2click:
If NOT numpadrunning Then
numpad_limit=5
numpad_x=150
numpad_y=40
numpad_target=but_V2
resultsindex=2
Gosub numpad
Endif
while gui.getvalue(but_V2)=1
wend
Return
'******* V2CLICK END **********
'******* V3CLICK *************
V3click:
If NOT numpadrunning Then
numpad_limit=4
numpad_x=150
numpad_y=90
numpad_target=but_V3
resultsindex=3
Gosub numpad
Endif
while gui.getvalue(but_V3)=1
wend
Return
'******* V3CLICK END **********
'******* V4CLICK *************
V4click:
If NOT numpadrunning Then
numpad_limit=4
numpad_x=150
numpad_y=30
numpad_target=but_V4
resultsindex=4
Gosub numpad
Endif
while gui.getvalue(but_V4)=1
wend
Return
'******* V4CLICK END **********
'******* V5CLICK *************
V5click:
If NOT numpadrunning Then
numpad_limit=5
numpad_x=150
numpad_y=40
numpad_target=but_V5
resultsindex=5
Gosub numpad
Endif
while gui.getvalue(but_V5)=1
wend
Return
'******* V5CLICK END **********
'******* V6CLICK *************
V6click:
If NOT numpadrunning Then
numpad_limit=6
numpad_x=150
numpad_y=90
numpad_target=but_V6
resultsindex=6
Gosub numpad
Endif
while gui.getvalue(but_V6)=1
wend
Return
'******* V6CLICK END **********
'******* NUMPAD INIT ************
numpad:
numpadrunning=1 ' numpad is active
numpad_value=0 ' initial value is 0 (could also be anything else)
numstr$=str$(numpad_value) ' the string holding the digits
gui.settext numpad_target, numstr$ ' set the value of the input field
num_box = GUI.Box(numpad_x, numpad_y, 106, 140, white ,black, red) ' draw box
num_7 = gui.button(numpad_x+4, numpad_y+4,30,30,"7",3,4,0,10,black,white,red,black) 'draw keys
num_8 = gui.button(numpad_x+38, numpad_y+4,30,30,"8",3,4,0,10,black,white,red,black)
num_9 = gui.button(numpad_x+72, numpad_y+4,30,30,"9",3,4,0,10,black,white,red,black)
num_4 = gui.button(numpad_x+4, numpad_y+38,30,30,"4",3,4,0,10,black,white,red,black)
num_5 = gui.button(numpad_x+38, numpad_y+38,30,30,"5",3,4,0,10,black,white,red,black)
num_6 = gui.button(numpad_x+72, numpad_y+38,30,30,"6",3,4,0,10,black,white,red,black)
num_1 = gui.button(numpad_x+4, numpad_y+72,30,30,"1",3,4,0,10,black,white,red,black)
num_2 = gui.button(numpad_x+38, numpad_y+72,30,30,"2",3,4,0,10,black,white,red,black)
num_3 = gui.button(numpad_x+72, numpad_y+72,30,30,"3",3,4,0,10,black,white,red,black)
num_0 = gui.button(numpad_x+4, numpad_y+106,30,30,"0",3,4,0,10,black,white,red,black)
num_del = gui.button(numpad_x+38, numpad_y+106,30,30,"<",3,4,0,10,black,white,red,black)
num_OK = gui.button(numpad_x+72, numpad_y+106,30,30,"=",3,4,0,10,black,white,red,black)
gui.setevent num_1, 1, numclick ' set a collective event for all buttons
gui.setevent num_2, 1, numclick
gui.setevent num_3, 1, numclick
gui.setevent num_4, 1, numclick
gui.setevent num_5, 1, numclick
gui.setevent num_6, 1, numclick
gui.setevent num_7, 1, numclick
gui.setevent num_8, 1, numclick
gui.setevent num_9, 1, numclick
gui.setevent num_0, 1, numclick
gui.setevent num_del, 1, numclick
gui.setevent num_OK, 1, numclick
Return
'*********** NUMPAD END **********
'********** NUMCLICK *************
numclick: ' Event handler for keys
num_target = Gui.Target
Select Case num_target
Case num_0: numstr$=numstr$+"0" ' set the digit for the key
Case num_1: numstr$=numstr$+"1"
Case num_2: numstr$=numstr$+"2"
Case num_3: numstr$=numstr$+"3"
Case num_4: numstr$=numstr$+"4"
Case num_5: numstr$=numstr$+"5"
Case num_6: numstr$=numstr$+"6"
Case num_7: numstr$=numstr$+"7"
Case num_8: numstr$=numstr$+"8"
Case num_9: numstr$=numstr$+"9"
Case num_0: numstr$=numstr$+"0"
Case num_del: If len (numstr$)>0 Then numstr$=left$(numstr$,len(numstr$)-1) ' when key pressed is "<", delete the last digit
Case num_OK: ' when key pressed is "=", accept the current value und close the keypad
numpadrunning=0 ' numpad is inactive
results(resultsindex)=numpad_value ' write end result back
If activepage = 0 Then Gosub Page0 ' Redraw the page where we came from
If activepage = 1 Then Gosub Page1
End Select
If numpadrunning Then ' If numpad still active THEN
If len(numstr$) > numpad_limit Then numstr$=left$(numstr$,len(numstr$)-1) ' If more digits than allowed, delete last one
numpad_value = val(numstr$) ' convert string of digits to number
numstr$=STR$(numpad_value) ' convert back, so leading zeroes get deleted
gui.settext numpad_target, numstr$ ' set the text of the input field that called numpad to the current value
while gui.getvalue(num_target)=1 ' prevent double triggering
wend
End If
Return
'******** NUMCLICK END ********