Post by tsh73 on Nov 3, 2022 20:18:51 GMT
Here's the demo that eats it's own dogfood
reads / interprets keys all by itself
draws stuff in a graphicbox (including caret)
* supports Tab - ShiftTab for moving between positions
* filters only digits
* works in OVERTYPE mode
* supports BACKSPACE, DELETE, Left and Right arrows
* limits text to 7 digits
* shows summary on Enter
So it actually comes really short of writing own texteditor
(and I remember seeing here some advanced texteditors in graphicbox!)
(btw, most useful commented line is PRINT after FETCH. It shows what are you just pressed)
But I really doubt it will play well with another controls.
I remember one can TAB to graphicbox, but cannot TAB out
Then again - may be setfocus?
reads / interprets keys all by itself
draws stuff in a graphicbox (including caret)
* supports Tab - ShiftTab for moving between positions
* filters only digits
* works in OVERTYPE mode
* supports BACKSPACE, DELETE, Left and Right arrows
* limits text to 7 digits
* shows summary on Enter
So it actually comes really short of writing own texteditor
(and I remember seeing here some advanced texteditors in graphicbox!)
(btw, most useful commented line is PRINT after FETCH. It shows what are you just pressed)
But I really doubt it will play well with another controls.
I remember one can TAB to graphicbox, but cannot TAB out
Then again - may be setfocus?
'tsh73 Oct 2022
'simulating tabbing between fields.
'and overtyping
'in a graphicbox
nomainwin
tab$=chr$(_VK_TAB)
shiftTab$=chr$(7) 'not actually sure
bs$=chr$(8) 'backspace
del$=chr$(0)+chr$(_VK_DELETE)
left$=chr$(0)+chr$(_VK_LEFT)
right$=chr$(0)+chr$(_VK_RIGHT)
OK$=chr$(_VK_RETURN)
maxLen=7 'arbitrary limit text length
N=5
font$= "Arial_black 20"
data 3,14,15,9,26
dim a$(N)
for i = 1 to N
read a$
a$(i)=a$
next
open "test" for graphics_nsb_nf as #gr
#gr "home; down; posxy cx cy"
#gr "trapclose [quit]"
#gr "when characterInput [fetch]"
#gr "setfocus"
#gr " font ";font$
#gr "place 0 0"
#gr "\"
#gr "posxy dummy ch"
chh=int(ch/5)
xx=cx
yy=1*ch
curY=1 'line wise
curX=0 'charwise
[redraw]
#gr "cls" 'or have to think how to clear caret
for i = 1 to N
#gr "place ";xx;" ";yy+i*ch
#gr "\";a$(i)
next
'draw caret
caretY = yy+curY*ch+chh 'just a bit lower
caretX = xx+stringWidth(left$(a$(curY), curX))
#gr "line ";caretX;" ";caretY;" ";caretX;" ";caretY-ch
wait
[fetch] 'a character was typed!
key$ = Inkey$
'print len(key$); " ";asc(key$); " ";asc(mid$(key$,2))
if key$ =tab$ then
'do tab
curY=curY+1 'line wise
if curY>N then curY=1
curX=0 'charwise
goto [redraw]
end if
if key$ =shiftTab$ then
'do tab but backwards
curY=curY-1 'line wise
if curY<1 then curY=N
curX=0 'charwise
goto [redraw]
end if
'else
if instr("0123456789", key$)<>0 then '!! valid filtered characters !!
if curX>=maxLen then wait 'text length limit
'overtype
'print left$(a$(curY), curX),mid$(a$(curY), curX+2)
a$(curY)=left$(a$(curY), curX)+key$+mid$(a$(curY), curX+2)
curX=curX+1
goto [redraw]
end if
'else still
if key$=bs$ then 'remove character before caret, move move care back
if curX<=0 then wait 'nowhere to move
'print left$(a$(curY), curX-1),mid$(a$(curY), curX+1)
a$(curY)=left$(a$(curY), curX-1)+mid$(a$(curY), curX+1)
curX=curX-1
goto [redraw]
end if
'else still
if key$=del$ then 'remove character after caret
'print left$(a$(curY), curX-1),mid$(a$(curY), curX+1)
a$(curY)=left$(a$(curY), curX)+mid$(a$(curY), curX+2)
goto [redraw]
end if
'else still
if key$=left$ then 'just move the caret
if curX<=0 then wait 'nowhere to move
curX=curX-1
goto [redraw]
end if
'else still
if key$=right$ then 'just move the caret
'print curX, len(a$(curY))
if curX>=len(a$(curY)) then wait 'nowhere to move
curX=curX+1
goto [redraw]
end if
if key$=OK$ then 'state current
#gr "flush"
msg$="Numbers entered so far:"
for i = 1 to N
msg$=msg$+chr$(13)+a$(i)
next
notice msg$
end if
wait
[quit]
timer 0
close #gr
end
function stringWidth(s$)
#gr "stringwidth? s$ w"
stringWidth = w
end function