Skip to content

Commit 1101abb

Browse files
committed
fixing "Some problems when editing a text string" #139
1 parent 44ad5a3 commit 1101abb

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ArduinoMenu library
2-
version=4.0.12
2+
version=4.0.13
33
author=Rui Azevedo, [email protected]
44
maintainer=neu-rah, [email protected]
55
sentence=AVR generic menu/interactivity system

src/items.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool menuNode::async(const char *uri,navRoot& root,idx_t lvl) {
6363
#endif
6464

6565
void textField::doNav(navNode& nav,navCmd cmd) {
66-
trace(Serial<<"textField::doNav"<<endl);
66+
trace(Serial<<"textField::doNav:"<<cmd.cmd<<endl);
6767
//Serial.println("textField doNav!");
6868
switch(cmd.cmd) {
6969
case enterCmd:
@@ -116,13 +116,15 @@ void textField::doNav(navNode& nav,navCmd cmd) {
116116
break;
117117
default:break;
118118
}
119+
trace(Serial<<"cursor:"<<cursor<<endl);
119120
}
120121

121122
Used textField::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t panelNr) {
122-
trace(Serial<<"textField::printTo"<<endl);
123+
trace(Serial<<*this<<" textField::printTo"<<endl);
123124
// out.fmtStart(menuOut::fmtPrompt,root.node(),idx);
124125
idx_t at=0;
125126
bool editing=this==root.navFocus;
127+
trace(Serial<<"editing:"<<editing<<" len:"<<len;)
126128
idx_t l=navTarget::printTo(root,sel,out,idx,len,panelNr);
127129
if (l<len) {
128130
out.write(editing?":":" ");
@@ -132,6 +134,8 @@ Used textField::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len
132134
//idx_t top=out.tops[root.level];
133135
idx_t tit=hasTitle(root.node())?1:0;
134136
idx_t line=idx+tit;//-out.tops[root.level];
137+
trace(Serial<<" tit:"<<tit<<" line:"<<line<<" cursor:"<<cursor<<" l:"<<l<<" len:"<<len<<endl;)
138+
idx_t c=l+1;
135139
while(buffer()[at]&&l++<len)
136140
if (at==cursor&&editing) {
137141
// Serial<<"idx:"<<idx<<" line:"<<line<<" at:"<<at<<" l:"<<l<<endl;
@@ -140,7 +144,7 @@ Used textField::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len
140144
out.write(buffer()[at++]);//draw focused character
141145
l+=out.endCursor(root,l,line,charEdit);//draw textual cursor or color code end
142146
} else out.write(buffer()[at++]);
143-
l+=out.editCursor(root,l,line,editing,charEdit);//reposition a non text cursor
147+
out.editCursor(root,c+cursor,line,editing,charEdit);//reposition a non text cursor
144148
return l;
145149
}
146150

@@ -152,8 +156,8 @@ Used textField::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len
152156
////////////////////////////////////////////////////////////////////////////////
153157
bool menuNode::changed(const navNode &nav,const menuOut& out,bool sub) {
154158
trace(Serial<<*this<<" menuNode::changed"<<endl);
155-
bool appd=is((systemStyles)(_asPad|_parentDraw));
156159
if (dirty) return true;
160+
bool appd=has((systemStyles)(_asPad|_parentDraw));
157161
if (appd) {
158162
trace(Serial<<"appd!"<<endl;);
159163
for(int i=0;i<sz();i++)
@@ -163,11 +167,16 @@ bool menuNode::changed(const navNode &nav,const menuOut& out,bool sub) {
163167
trace(Serial<<*this<<"!appd"<<endl;);
164168
if (!(nav.target==this&&sub)) return dirty;// second hand check, just report self
165169
idx_t level=nav.root->level;
166-
if (parentDraw())
170+
if (parentDraw()) {
171+
trace(Serial<<"return changed of parent-draw element"<<endl);
167172
return nav.root->path[level-1].target->changed(nav.root->path[level-1],out,sub);
173+
}
174+
// idx_t tit=hasTitle(nav.root->path[lev])?1:0;//TODO: this might not be correct.. checking
168175
idx_t my=out.maxY()-((has(showTitle)||(nav.root->showTitle&&!has(noTitle)))?1:0);
169-
trace(Serial<<"target:"<<*nav.root->navFocus<<" "<<nav.root->navFocus->has(_parentDraw)<<endl);
170-
idx_t t=out.tops[level-nav.root->navFocus->has(_parentDraw)];
176+
trace(Serial<<"level:"<<level<<" target:"<<*nav.root->navFocus<<" "<<nav.root->navFocus->has(_parentDraw)<<" "<<nav.root->navFocus->has(_asPad)<<endl);
177+
idx_t lev=level-(nav.root->navFocus->has(_parentDraw)&&nav.root->navFocus->isMenu());
178+
// trace(Serial<<"tit:"<<tit<<endl;);
179+
idx_t t=out.tops[lev];
171180
trace(Serial<<"t:"<<t<<endl;);
172181
if (sub) for(int i=0;i<my;i++,t++) {
173182
if (t>=sz()) break;
@@ -181,7 +190,7 @@ bool menuNode::changed(const navNode &nav,const menuOut& out,bool sub) {
181190
void menuNode::clearChanged(const navNode &nav,const menuOut& out,bool sub) {
182191
trace(Serial<<" menuOut::clearChanged "<<nav);
183192
dirty=false;
184-
if (is((systemStyles)(_asPad|_parentDraw))) {
193+
if (has((systemStyles)(_asPad|_parentDraw))) {
185194
for(int i=0;i<sz();i++)
186195
operator[](i).clearChanged(nav,out,false);
187196
} else {
@@ -190,7 +199,8 @@ void menuNode::clearChanged(const navNode &nav,const menuOut& out,bool sub) {
190199
if (parentDraw())
191200
return nav.root->path[level-1].target->clearChanged(nav.root->path[level-1],out,sub);
192201
idx_t my=out.maxY()-((has(showTitle)||(nav.root->showTitle&&!has(noTitle)))?1:0);
193-
idx_t t=out.tops[level-nav.root->navFocus->has(_parentDraw)];
202+
idx_t lev=level-(nav.root->navFocus->has(_parentDraw)&&nav.root->navFocus->isMenu());
203+
idx_t t=out.tops[lev];
194204
for(idx_t i=0;i<my;i++,t++) {//only signal visible
195205
if (t>=sz()) break;//menu ended
196206
operator[](t).clearChanged(nav,out,false);

src/menuIO/PCF8574Out.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
idx_t startCursor(navRoot& root,idx_t x,idx_t y,bool charEdit,idx_t panelNr=0) override {return 0;}
3030
idx_t endCursor(navRoot& root,idx_t x,idx_t y,bool charEdit,idx_t panelNr=0) override {return 0;}
3131
idx_t editCursor(navRoot& root,idx_t x,idx_t y,bool editing,bool charEdit,idx_t panelNr=0) override {
32+
trace(Serial<<"lcdOut::editCursor "<<x<<","<<y<<endl);
3233
//text editor cursor
3334
device->noBlink();
3435
device->noCursor();

src/menuIO/lcdOut.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
idx_t startCursor(navRoot& root,idx_t x,idx_t y,bool charEdit,idx_t panelNr=0) override {return 0;}
3131
idx_t endCursor(navRoot& root,idx_t x,idx_t y,bool charEdit,idx_t panelNr=0) override {return 0;}
3232
idx_t editCursor(navRoot& root,idx_t x,idx_t y,bool editing,bool charEdit,idx_t panelNr=0) override {
33+
trace(Serial<<"lcdOut::editCursor "<<x<<","<<y<<endl);
3334
//text editor cursor
3435
device->noBlink();
3536
device->noCursor();

0 commit comments

Comments
 (0)