To be clear, the TFT GUI is an excellent feature, allowing sophisticated results fairly easily, as seen here:
But usage is greatly restricted by:
- inability for touch events to RETURN
- inability for defining GUI handlers using variables
(both shown in pic below)
Instead of using a single array variable in a FOR TO loop to define multiple objects, they must all be uniquely explicitely declared individually into the script (there are still 20 more lines of unseen code just for the small 'Records' page, and many more pages), and similarly for everything that subsequently references every object.
This makes the resulting script bloated and brittle because even a slight change can break it - making it unsuitable for publishing to a hacker community.
It is actually possible to define handler objects using an array, but a gui.target array bug returns the value of its own indexed target element instead of the users indexed element. Even worse, it fails to recognise any of the defined handlers, so instead of re-using existing handlers it keeps creating new ones until using up its allocation of objects (see the diagnostic script included below).
The situation could be improved enormously if the gui.target bug could be fixed thereby allowing arrays to be used for gui handlers.
Another major restriction is that GUI touch events can only GOSUB to branches, causing memory leaks by always pushing new return addresses onto the stack without being able to RETURN to them by touch button (the wlog window shows decreasing ramfree after using the 'EXIT' button).
A fairly quick and simple solution could be if ontouch events could recognise "RETURN" as a valid reserved word in place of the branch label (to trigger a RETURN back, rather than jump forward to another GOSUB branch).
A less crucial problem is that the graphical width in pixels of gui.textline and gui.button text strings is crucial for displaying the text string correctly, but is not possible to calculate for proportional fonts, causing the widths fields to be discovered by trial and error, and only valid for each item.
The guesswork could be removed by a function which returned the appropriate width and height in pixels of a specified text string and font.
A couple of minor suggestions:
GUI.Textline is not touchable so could benefit from being assigned an event handler.
GUI.Button could benefit from having a transparent background capability, and gui.SETSTYLE ability.
But the TFT Thermostat controller above (which also now reads data from remote ble sensors) shows how amazing Annex already is even without benefit of improvement suggestions.
Diagnostic snippet for showing effects of gui.target bug:
Code: [Local Link Removed for Guests]
'Diagnostic for gui.target bug, should re-use pagefuls of object handles, but TFT shows it failing after running out
'Wlog window shows gui.target bug keeps creating new object handles until running out and erroring with -1.
pagelength=3
pages=5
gui_objects=10 'enough for more than 3 pages of objects, but only 1 pageful of re-used objects should be necessary
dim handler(gui_objects)
gui.init gui_objects, black
gui.autorefresh 50,1
x=0: y=0: w=100: h=30: f=3
for page=1 to pages
for line = 1 to pagelength
handler(line) = GUI.button(x,y+(h*line),w,h,str$(line+((page-1)*pagelength)),f,0,0,1,cyan,black,0,0
wlog handler(line)
next line
pause 2000
next page