@@ -50,10 +50,11 @@ static const PROGMEM char _chartbl[TABLECOUNT][ROWCOUNT][COLUMNCOUNT]
5050 , {' Z' , ' X' , ' C' , ' V' , ' B' , ' N' , ' M' , ' ' , ' .' , ' @' ,RIGH}
5151 }
5252 , {{' !' , ' "' , ' #' , ' $' , ' %' , ' &' ,' \' ' , ' `' , ' ^' , ' ~' , BS }
53- , {' <' , ' >' , ' [' , ' ]' , ' {' , ' }' , ' (' , ' )' , ' = ' , ' \\ ' , DEL}
54- , {' _ ' , ' |' , ' , ' , ' ; ' , ' : ' , ' ? ' , ' +' , ' * ' , ' - ' , ' /' ,LEFT}
55- , {' . ' , ' .' , ' .' , ' .' , ' .' , ' . ' , ' . ' , ' ' , ' .' , ' @' ,RIGH}
53+ , {' \t ' , ' <' , ' >' , ' [' , ' ]' , ' {' , ' }' , ' (' , ' )' , ' \\ ' , DEL}
54+ , {' \r ' , ' |' , ' ; ' , ' : ' , ' _ ' , ' = ' , ' +' , ' - ' , ' * ' , ' /' ,LEFT}
55+ , {' \n ' , ' .' , ' .' , ' .' , ' .' , ' ? ' , ' , ' , ' ' , ' .' , ' @' ,RIGH}
5656 }
57+
5758 , {{0x80 , 0x84 , 0x88 , 0x8c , 0x90 , 0x94 , 0x98 , 0x9c , 0xa0 , 0xa4 , BS }
5859 , {0x81 , 0x85 , 0x89 , 0x8d , 0x91 , 0x95 , 0x99 , 0x9d , 0xa1 , 0xa5 , DEL}
5960 , {0x82 , 0x86 , 0x8a , 0x8e , 0x92 , 0x96 , 0x9a , 0x9e , 0xa2 , 0xa6 , LEFT}
@@ -66,11 +67,12 @@ static const PROGMEM uint8_t _morsetbl[TABLECOUNT][ROWCOUNT][COLUMNCOUNT]
6667 , {0x06 , 0x0f , 0x0b , 0x1d , 0x09 , 0x1f , 0x18 , 0x0a , 0x1b , 0x2d , 0 }
6768 , {0x13 , 0x16 , 0x15 , 0x1e , 0x17 , 0x05 , 0x04 , 0x1c , 0x6a , 0x65 , 0 }
6869 }
69- , {{0x54 , 0x6d , 0x25 , 0x7b , 0x22 , 0x37 , 0x61 , 0x5a , 0x7f , 0x63 , 0x10 }
70- , {0x28 , 0x50 , 0x33 , 0x66 , 0x32 , 0x64 , 0x29 , 0x52 , 0x2e , 0x2a , 0 }
71- , {0x72 , 0x4a , 0x4c , 0x55 , 0x47 , 0x73 , 0x35 , 0x3d , 0x5e , 0x2d , 0 }
72- , {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0x1c , 0x6a , 0x65 , 0 }
70+ , {{0x54 , 0x6d , 0x25 , 0x7b , 0x22 , 0x37 , 0x61 , 0x5a , 0x7f , 0x63 , 0x10 }
71+ , {0 , 0x28 , 0x50 , 0x33 , 0x66 , 0x32 , 0x64 , 0x29 , 0x52 , 0x2a , 0 }
72+ , {0x1a , 0x4a , 0x55 , 0x47 , 0x72 , 0x2e , 0x35 , 0x5e , 0x3d , 0x2d , 0 }
73+ , {0 , 0 , 0 , 0 , 0 , 0x73 , 0x4c , 0x1c , 0x6a , 0x65 , 0 }
7374 }
75+
7476 , {{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0x10 }
7577 , {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
7678 , {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
@@ -93,6 +95,28 @@ static uint8_t calcMorse(uint8_t m)
9395 return res;
9496}
9597
98+ static void drawCodeSymbol (uint8_t code, int x, int y, uint16_t color)
99+ {
100+ switch (code) {
101+ case ' \t ' :
102+ M5.Lcd .drawFastHLine (x , y + 3 , 5 , color);
103+ M5.Lcd .drawFastVLine (x + 3 , y + 2 , 3 , color);
104+ break ;
105+ case ' \n ' :
106+ M5.Lcd .drawFastVLine (x + 2 , y + 1 , 5 , color);
107+ M5.Lcd .drawFastHLine (x + 1 , y + 4 , 3 , color);
108+ break ;
109+ case ' \r ' :
110+ M5.Lcd .drawFastHLine (x , y + 3 , 5 , color);
111+ M5.Lcd .drawFastVLine (x + 1 , y + 2 , 3 , color);
112+ break ;
113+ default :
114+ M5.Lcd .drawRect (x + 1 , y + 2 , 4 , 4 , color);
115+ break ;
116+ }
117+ M5.Lcd .setCursor (x + 6 , y);
118+ }
119+
96120void M5OnScreenKeyboard::setString (const String& value) {
97121 _string = value;
98122 _cursorPos = _string.length ();
@@ -292,8 +316,7 @@ bool M5OnScreenKeyboard::loop() {
292316 }
293317 // draw blink cursor.
294318 if (useTextbox) {
295- int x = M5.Lcd .textWidth (_string.substring (0 , _cursorPos), font);
296- M5.Lcd .drawFastVLine ( x
319+ M5.Lcd .drawFastVLine ( _cursorX
297320 , getY (-1 ) + (keyHeight - M5.Lcd .fontHeight (font)) / 2
298321 , M5.Lcd .fontHeight (font)
299322 , (_msec / 150 ) % 2 ? textboxBackColor : textboxFontColor);
@@ -340,6 +363,7 @@ bool M5OnScreenKeyboard::inputKB(char key)
340363 case 0x0D : return false ;
341364 case 0x81 : case 0xB4 : pressKey (LEFT); break ;
342365 case 0x83 : case 0xB7 : pressKey (RIGH); break ;
366+ case ' \t ' :
343367 case BS: pressKey (key); break ;
344368 default :
345369 if (0x20 <= key && key < 0x80 ) {
@@ -450,8 +474,11 @@ void M5OnScreenKeyboard::drawKeyTop(int c, int r, int x, int y, int kh)
450474 char * str = tbl;
451475 char code = _chartbl[_tbl][r][c];
452476 switch (code) {
477+ case ' \t ' : str = " TAB" ; break ;
478+ case ' \r ' : str = " CR" ; break ;
479+ case ' \n ' : str = " LF" ; break ;
453480 case BS : str = " BS" ; break ;
454- case DEL : str = " DEL" ; break ;
481+ case DEL : str = " DEL" ; break ;
455482 case LEFT: str = " <<" ; break ;
456483 case RIGH: str = " >>" ; break ;
457484 }
@@ -494,10 +521,23 @@ void M5OnScreenKeyboard::draw() {
494521
495522void M5OnScreenKeyboard::drawTextbox () {
496523 int y = getY (-1 );
524+ int ty = y + (keyHeight - M5.Lcd .fontHeight (font)) / 2 ;
525+ int oldX = M5.Lcd .getCursorX ();
526+ int oldY = M5.Lcd .getCursorY ();
497527 M5.Lcd .setTextColor (textboxFontColor);
498528 M5.Lcd .drawFastHLine (0 , y, M5.Lcd .width (), frameColor[0 ]);
499529 M5.Lcd .fillRect (0 , y + 1 , M5.Lcd .width (), keyHeight - 1 , textboxBackColor);
500- M5.Lcd .drawString (_string, 1 , y + (keyHeight - M5.Lcd .fontHeight (font)) / 2 , font);
530+ M5.Lcd .setCursor (1 , ty, font);
531+ _cursorX = 0 ;
532+ for (int i = 0 ; i < _string.length (); ++i) {
533+ if (_string[i] < 0x20 ) {
534+ drawCodeSymbol (_string[i], M5.Lcd .getCursorX (), y + (keyHeight - 8 ) / 2 , textboxFontColor);
535+ } else {
536+ M5.Lcd .print (_string[i]);
537+ }
538+ if (_cursorPos == i + 1 ) _cursorX = M5.Lcd .getCursorX () - 1 ;
539+ }
540+ M5.Lcd .setCursor (oldX, oldY);
501541}
502542
503543void M5OnScreenKeyboard::drawKeyboard (int h) {
0 commit comments