Skip to content

Commit e84321f

Browse files
committed
textFields consider enter and backspace
added this special cases for easy keyboard input
1 parent 89ffe59 commit e84321f

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

examples/codeCtrl/codeCtrl/codeCtrl.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,9 @@ void loop() {
184184
// or deal with charater input directly... (if you have your own input driver)
185185
if (Serial.available()) {
186186
//of course menu can read from Serial or even stringIn (se above how to use stringIn as a regular menu input)
187-
//but here we demonstrate the use of stringIn in direct call, by writing the data to stream and then call parseInput
187+
//but here we demonstrate the use of stringIn in direct call, by writing the data to stream and then call doInput with that stream
188188
if (strIn.write(Serial.read()))//so we just transfer data from serial to strIn
189-
// nav.active().parseInput(nav.node(),strIn);//and then let target parse input
190-
nav.doInput(strIn);
189+
nav.doInput(strIn);//and then let target parse input
191190
}
192191
nav.doOutput();//if not doing poll the we need to do output "manualy"
193192
digitalWrite(LEDPIN, ledCtrl);

src/items.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,39 @@ void navTarget::parseInput(navNode& nav,menuIn& in) {
248248
}
249249

250250
void textField::parseInput(navNode& nav,menuIn& in) {
251-
_trace(Serial<<"navTarget::parseInput"<<endl);
251+
trace(Serial<<"navTarget::parseInput"<<endl);
252252
if (/*charEdit&&*/in.available()) {
253253
char c=in.peek();
254-
const char* v=validator(cursor);
255-
char *at=strchr(v,c);
256-
if (at) {
257-
in.read();
258-
buffer()[cursor]=c;
259-
if (cursor<(idx_t)strlen(buffer())-1) cursor++;
260-
//else charEdit=false;
261-
dirty=true;
262-
return;
254+
switch(c) {//special cases
255+
case 0x0D://enter
256+
in.read();
257+
charEdit=false;
258+
dirty=true;
259+
// edited=false;
260+
cursor=0;
261+
nav.root->exit();
262+
return;
263+
case 0x08://backspace
264+
in.read();
265+
buffer()[cursor]=validator(cursor)[0];
266+
if (cursor) cursor--;
267+
dirty=true;
268+
return;
269+
default: {
270+
const char* v=validator(cursor);
271+
char *at=strchr(v,c);
272+
if (at) {
273+
in.read();
274+
buffer()[cursor]=c;
275+
if (cursor<(idx_t)strlen(buffer())-1) cursor++;
276+
dirty=true;
277+
return;
278+
}
279+
// Serial<<hex(c)<<endl;
280+
navTarget::parseInput(nav,in);
281+
}
263282
}
264283
}
265-
navTarget::parseInput(nav,in);
266284
}
267285

268286

@@ -326,22 +344,22 @@ Used fieldBase::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len
326344
l++;
327345
if (l<len) {
328346
#ifdef MENU_FMT_WRAPS
329-
out.fmtStart(menuOut::fmtField,root.node(),idx);
347+
out.fmtStart(menuOut::fmtField,root.node(),idx);
330348
#endif
331349
out.setColor(valColor,sel,enabled,ed);
332350
//out<<reflex;
333351
l+=printReflex(out);//NOTE: this can exceed the limits!
334352
#ifdef MENU_FMT_WRAPS
335-
out.fmtEnd(menuOut::fmtField,root.node(),idx);
353+
out.fmtEnd(menuOut::fmtField,root.node(),idx);
336354
#endif
337355
if (l<len) {
338356
#ifdef MENU_FMT_WRAPS
339-
out.fmtStart(menuOut::fmtUnit,root.node(),idx);
357+
out.fmtStart(menuOut::fmtUnit,root.node(),idx);
340358
#endif
341359
out.setColor(unitColor,sel,enabled,ed);
342360
l+=print_P(out,units(),len);
343361
#ifdef MENU_FMT_WRAPS
344-
out.fmtEnd(menuOut::fmtUnit,root.node(),idx);
362+
out.fmtEnd(menuOut::fmtUnit,root.node(),idx);
345363
#endif
346364
}
347365
}

0 commit comments

Comments
 (0)