@@ -50,10 +50,11 @@ static const PROGMEM char _chartbl[TABLECOUNT][ROWCOUNT][COLUMNCOUNT]
50
50
, {' Z' , ' X' , ' C' , ' V' , ' B' , ' N' , ' M' , ' ' , ' .' , ' @' ,RIGH}
51
51
}
52
52
, {{' !' , ' "' , ' #' , ' $' , ' %' , ' &' ,' \' ' , ' `' , ' ^' , ' ~' , BS }
53
- , {' <' , ' >' , ' [' , ' ]' , ' {' , ' }' , ' (' , ' )' , ' = ' , ' \\ ' , DEL}
54
- , {' _ ' , ' |' , ' , ' , ' ; ' , ' : ' , ' ? ' , ' +' , ' * ' , ' - ' , ' /' ,LEFT}
55
- , {' . ' , ' .' , ' .' , ' .' , ' .' , ' . ' , ' . ' , ' ' , ' .' , ' @' ,RIGH}
53
+ , {' \t ' , ' <' , ' >' , ' [' , ' ]' , ' {' , ' }' , ' (' , ' )' , ' \\ ' , DEL}
54
+ , {' \r ' , ' |' , ' ; ' , ' : ' , ' _ ' , ' = ' , ' +' , ' - ' , ' * ' , ' /' ,LEFT}
55
+ , {' \n ' , ' .' , ' .' , ' .' , ' .' , ' ? ' , ' , ' , ' ' , ' .' , ' @' ,RIGH}
56
56
}
57
+
57
58
, {{0x80 , 0x84 , 0x88 , 0x8c , 0x90 , 0x94 , 0x98 , 0x9c , 0xa0 , 0xa4 , BS }
58
59
, {0x81 , 0x85 , 0x89 , 0x8d , 0x91 , 0x95 , 0x99 , 0x9d , 0xa1 , 0xa5 , DEL}
59
60
, {0x82 , 0x86 , 0x8a , 0x8e , 0x92 , 0x96 , 0x9a , 0x9e , 0xa2 , 0xa6 , LEFT}
@@ -66,11 +67,12 @@ static const PROGMEM uint8_t _morsetbl[TABLECOUNT][ROWCOUNT][COLUMNCOUNT]
66
67
, {0x06 , 0x0f , 0x0b , 0x1d , 0x09 , 0x1f , 0x18 , 0x0a , 0x1b , 0x2d , 0 }
67
68
, {0x13 , 0x16 , 0x15 , 0x1e , 0x17 , 0x05 , 0x04 , 0x1c , 0x6a , 0x65 , 0 }
68
69
}
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 }
73
74
}
75
+
74
76
, {{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0x10 }
75
77
, {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
76
78
, {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
@@ -93,6 +95,28 @@ static uint8_t calcMorse(uint8_t m)
93
95
return res;
94
96
}
95
97
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
+
96
120
void M5OnScreenKeyboard::setString (const String& value) {
97
121
_string = value;
98
122
_cursorPos = _string.length ();
@@ -292,8 +316,7 @@ bool M5OnScreenKeyboard::loop() {
292
316
}
293
317
// draw blink cursor.
294
318
if (useTextbox) {
295
- int x = M5.Lcd .textWidth (_string.substring (0 , _cursorPos), font);
296
- M5.Lcd .drawFastVLine ( x
319
+ M5.Lcd .drawFastVLine ( _cursorX
297
320
, getY (-1 ) + (keyHeight - M5.Lcd .fontHeight (font)) / 2
298
321
, M5.Lcd .fontHeight (font)
299
322
, (_msec / 150 ) % 2 ? textboxBackColor : textboxFontColor);
@@ -340,6 +363,7 @@ bool M5OnScreenKeyboard::inputKB(char key)
340
363
case 0x0D : return false ;
341
364
case 0x81 : case 0xB4 : pressKey (LEFT); break ;
342
365
case 0x83 : case 0xB7 : pressKey (RIGH); break ;
366
+ case ' \t ' :
343
367
case BS: pressKey (key); break ;
344
368
default :
345
369
if (0x20 <= key && key < 0x80 ) {
@@ -450,8 +474,11 @@ void M5OnScreenKeyboard::drawKeyTop(int c, int r, int x, int y, int kh)
450
474
char * str = tbl;
451
475
char code = _chartbl[_tbl][r][c];
452
476
switch (code) {
477
+ case ' \t ' : str = " TAB" ; break ;
478
+ case ' \r ' : str = " CR" ; break ;
479
+ case ' \n ' : str = " LF" ; break ;
453
480
case BS : str = " BS" ; break ;
454
- case DEL : str = " DEL" ; break ;
481
+ case DEL : str = " DEL" ; break ;
455
482
case LEFT: str = " <<" ; break ;
456
483
case RIGH: str = " >>" ; break ;
457
484
}
@@ -494,10 +521,23 @@ void M5OnScreenKeyboard::draw() {
494
521
495
522
void M5OnScreenKeyboard::drawTextbox () {
496
523
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 ();
497
527
M5.Lcd .setTextColor (textboxFontColor);
498
528
M5.Lcd .drawFastHLine (0 , y, M5.Lcd .width (), frameColor[0 ]);
499
529
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);
501
541
}
502
542
503
543
void M5OnScreenKeyboard::drawKeyboard (int h) {
0 commit comments