Skip to content

Commit c1d828f

Browse files
committed
fix field clearChanged
now sets reflex=target() to avoid recursivity of changed() this was causing repetitive redraw
1 parent 5e18e86 commit c1d828f

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

src/items.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,31 @@ Used textField::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len
154154
// menuNode - any menu object that has a list of members
155155
//
156156
////////////////////////////////////////////////////////////////////////////////
157-
bool menuNode::changed(const navNode &nav,const menuOut& out,bool sub) {
157+
bool menuNode::changed(const navNode &nav,const menuOut& out,bool sub,bool test) {
158158
trace(Serial<<*this<<" menuNode::changed"<<endl);
159-
if (dirty) return true;
159+
if (dirty) {
160+
trace(if (test) Serial<<"just dirty!"<<endl);
161+
return true;
162+
}
160163
bool appd=has((systemStyles)(_asPad|_parentDraw));
161164
if (appd) {
162165
trace(Serial<<"appd!"<<endl;);
163166
for(int i=0;i<sz();i++)
164-
if (operator[](i).changed(nav,out,false))
167+
if (operator[](i).changed(nav,out,false,test)) {
168+
trace(if (test) Serial<<"APPD! "<<operator[](i).type()<<endl);
165169
return true;
170+
}
166171
} else {
167172
trace(Serial<<*this<<"!appd"<<endl;);
168-
if (!(nav.target==this&&sub)) return dirty;// second hand check, just report self
173+
if (!(nav.target==this&&sub)) {
174+
trace(if (test&&dirty) Serial<<"indirect!"<<endl);
175+
return dirty;// second hand check, just report self
176+
}
169177
idx_t level=nav.root->level;
170178
if (parentDraw()) {
171179
trace(Serial<<"return changed of parent-draw element"<<endl);
172-
return nav.root->path[level-1].target->changed(nav.root->path[level-1],out,sub);
180+
trace(if (test) Serial<<"parentDraw()!"<<endl);
181+
return nav.root->path[level-1].target->changed(nav.root->path[level-1],out,sub,test);
173182
}
174183
// idx_t tit=hasTitle(nav.root->path[lev])?1:0;//TODO: this might not be correct.. checking
175184
idx_t my=out.maxY()-((has(showTitle)||(nav.root->showTitle&&!has(noTitle)))?1:0);
@@ -181,7 +190,10 @@ bool menuNode::changed(const navNode &nav,const menuOut& out,bool sub) {
181190
if (sub) for(int i=0;i<my;i++,t++) {
182191
if (t>=sz()) break;
183192
trace(Serial<<"checking:"<<operator[](t)<<endl);
184-
if (operator[](t).changed(nav,out,false)) return true;
193+
if (operator[](t).changed(nav,out,false,test)) {
194+
trace(if (test) Serial<<"sub changed!"<<endl);
195+
return true;
196+
}
185197
}
186198
}
187199
return false;
@@ -206,6 +218,16 @@ void menuNode::clearChanged(const navNode &nav,const menuOut& out,bool sub) {
206218
operator[](t).clearChanged(nav,out,false);
207219
}
208220
}
221+
#ifdef DEBUG
222+
if(changed(nav,out,sub,true)) {
223+
Serial<<"ERROR clear changed fail!"<<endl;
224+
Serial<<*this<<endl;
225+
Serial<<"level:"<<nav.root->level<<endl;
226+
Serial<<"type:"<<type()<<endl;
227+
Serial.flush();
228+
while(1);
229+
}
230+
#endif
209231
}
210232

211233
////////////////////////////////////////////////////////////////////////////////

src/items.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
virtual void clearChanged(const navNode &nav,const menuOut& out,bool sub) {dirty=false;}
6060
virtual Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t panelNr=0);//raw print to output device
61-
virtual bool changed(const navNode &nav,const menuOut& out,bool sub=true) {return dirty;}
61+
virtual bool changed(const navNode &nav,const menuOut& out,bool sub=true,bool test=false) {return dirty;}
6262
//this is the system version of enter handler, its used by elements like toggle
6363
virtual result sysHandler(SYS_FUNC_PARAMS) {return proceed;}
6464
virtual result eventHandler(eventMask e,navNode& nav,idx_t i) {
@@ -174,7 +174,13 @@
174174
inline T high() const {return ((menuFieldShadow<T>*)shadow)->_high();}
175175
inline T step() const {return ((menuFieldShadow<T>*)shadow)->_step();}
176176
inline T tune() const {return ((menuFieldShadow<T>*)shadow)->_tune();}
177-
bool changed(const navNode &nav,const menuOut& out,bool sub=true) override {
177+
virtual void clearChanged(const navNode &nav,const menuOut& out,bool sub) {
178+
fieldBase::clearChanged(nav,out,sub);
179+
reflex=target();
180+
}
181+
bool changed(const navNode &nav,const menuOut& out,bool sub=true,bool test=false) override {
182+
trace(if (test&&dirty) Serial<<"field dirty"<<endl);
183+
trace(if (test&&(reflex!=target())) Serial<<"reflex!=target reflex:"<<reflex<<" target:"<<target()<<endl);
178184
return dirty||(reflex!=target());
179185
}
180186
#ifdef DEBUG
@@ -228,7 +234,7 @@
228234
virtual classes type() const {return menuClass;}
229235
#endif
230236
inline prompt& operator[](idx_t i) const {return ((menuNodeShadow*)shadow)->operator[](i);}
231-
bool changed(const navNode &nav,const menuOut& out,bool sub=true) override;
237+
bool changed(const navNode &nav,const menuOut& out,bool sub=true,bool test=false) override;
232238
void clearChanged(const navNode &nav,const menuOut& out,bool sub) override;
233239
inline idx_t sz() const {return ((menuNodeShadow*)shadow)->_sz();}
234240
inline prompt* constMEM* data() const {return ((menuNodeShadow*)shadow)->_data();}
@@ -290,7 +296,7 @@
290296
return i;
291297
}
292298
inline T& target() const {return ((menuVariantShadow<T>*)shadow)->target();}
293-
bool changed(const navNode &nav,const menuOut& out,bool sub=true) override;
299+
bool changed(const navNode &nav,const menuOut& out,bool sub=true,bool test=false) override;
294300
#ifdef MENU_ASYNC
295301
virtual idx_t selected() const {return reflex;}
296302
#endif
@@ -425,7 +431,7 @@
425431
}
426432

427433
template<typename T>
428-
bool menuVariant<T>::changed(const navNode &nav,const menuOut& out,bool sub) {
434+
bool menuVariant<T>::changed(const navNode &nav,const menuOut& out,bool sub,bool test) {
429435
return dirty||((menuValue<T>*)&operator[](reflex))->target()!=target();
430436
}
431437

0 commit comments

Comments
 (0)