Skip to content

Commit

Permalink
fixed failing changed state report
Browse files Browse the repository at this point in the history
  • Loading branch information
neu-rah committed Dec 2, 2017
1 parent 3ea6d83 commit 44ad5a3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ArduinoMenu library
version=4.0.11
version=4.0.12
author=Rui Azevedo, [email protected]
maintainer=neu-rah, [email protected]
sentence=AVR generic menu/interactivity system
Expand Down
13 changes: 9 additions & 4 deletions src/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace Menu;
bool prompt::hasTitle(navNode& nav) const {return (nav.target->has(showTitle)||(nav.root->showTitle&&!nav.target->has(noTitle)));}

idx_t prompt::printRaw(menuOut& out,idx_t len) const {
trace(Serial<<"prompt::printRaw"<<endl);
trace(Serial<<"prompt::printRaw"<<endl;print_P(Serial,getText(),len));
return print_P(out,getText(),len);
}

Expand Down Expand Up @@ -155,26 +155,31 @@ bool menuNode::changed(const navNode &nav,const menuOut& out,bool sub) {
bool appd=is((systemStyles)(_asPad|_parentDraw));
if (dirty) return true;
if (appd) {
trace(Serial<<"appd!"<<endl;);
for(int i=0;i<sz();i++)
if (operator[](i).changed(nav,out,false))
return true;
} else {
trace(Serial<<*this<<"!appd"<<endl;);
if (!(nav.target==this&&sub)) return dirty;// second hand check, just report self
idx_t level=nav.root->level;
if (parentDraw())
return nav.root->path[level-1].target->changed(nav.root->path[level-1],out,sub);
idx_t my=out.maxY()-((has(showTitle)||(nav.root->showTitle&&!has(noTitle)))?1:0);
idx_t t=out.tops[level];
trace(Serial<<"target:"<<*nav.root->navFocus<<" "<<nav.root->navFocus->has(_parentDraw)<<endl);
idx_t t=out.tops[level-nav.root->navFocus->has(_parentDraw)];
trace(Serial<<"t:"<<t<<endl;);
if (sub) for(int i=0;i<my;i++,t++) {
if (t>=sz()) break;
trace(Serial<<"checking:"<<operator[](t)<<endl);
if (operator[](t).changed(nav,out,false)) return true;
}
}
return false;
}

void menuNode::clearChanged(const navNode &nav,const menuOut& out,bool sub) {
trace(Serial<<endl<<*this<<" menuOut::clearChanged "<<nav);
trace(Serial<<" menuOut::clearChanged "<<nav);
dirty=false;
if (is((systemStyles)(_asPad|_parentDraw))) {
for(int i=0;i<sz();i++)
Expand All @@ -185,7 +190,7 @@ void menuNode::clearChanged(const navNode &nav,const menuOut& out,bool sub) {
if (parentDraw())
return nav.root->path[level-1].target->clearChanged(nav.root->path[level-1],out,sub);
idx_t my=out.maxY()-((has(showTitle)||(nav.root->showTitle&&!has(noTitle)))?1:0);
idx_t t=out.tops[level];
idx_t t=out.tops[level-nav.root->navFocus->has(_parentDraw)];
for(idx_t i=0;i<my;i++,t++) {//only signal visible
if (t>=sz()) break;//menu ended
operator[](t).clearChanged(nav,out,false);
Expand Down
6 changes: 0 additions & 6 deletions src/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,5 @@
return proceed;
}
}

#ifdef DEBUG
inline String& operator<<(String&s,prompt &p) {return s+=p.getText();}
inline Stream& operator<<(Stream&o,prompt& p) {print_P(o,p.getText());return o;}
#endif

}//namespace Menu
#endif
6 changes: 6 additions & 0 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ result Menu::maxDepthError(menuOut& o,idleEvent e) {
o.print(F("Error: maxDepth reached!\n\rincrease maxDepth on your scketch."));
return proceed;
}

#ifdef DEBUG
String& operator<<(String&s,prompt &p) {return s+=p.getText();}
Stream& operator<<(Stream&o,prompt& p) {print_P(o,p.getText());return o;}
Print& operator<<(Print&o,prompt& p) {print_P(o,p.getText());return o;}
#endif
19 changes: 16 additions & 3 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,27 @@ warranty, express or implied, as to its usefulness for any purpose.
#ifndef RSITE_ARDUINO_MENU_SYSTEM
#define RSITE_ARDUINO_MENU_SYSTEM
#include <Arduino.h>
#if defined(DEBUG)
#include <Streaming.h>
#endif

#include "menuBase.h"
#include "shadows.h"

using namespace Menu;

#ifdef DEBUG
String& operator<<(String&s,prompt &p);
Stream& operator<<(Stream&o,prompt& p);
Print& operator<<(Print&o,prompt& p);
#endif

#if defined(DEBUG)
#ifndef ARDUINO_STREAMING
#include <streamFlow.h>
#else
#include <Streaming.h>
#endif
#endif


#if defined(DEBUG) && defined(TRACE)
#define trace(x) x
#else
Expand Down
17 changes: 13 additions & 4 deletions src/nav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ navCmd navNode::doNavigation(navCmd cmd) {
idx_t nsel=sel;
navCmd rCmd=cmd;
bool changed=false;
// trace(if(cmd.cmd!=noCmd) Serial<<"navigate "<<*target<<" with command:"<<cmd.cmd<<" index:"<<nsel<<endl);
switch(cmd.cmd) {
/*case scrlDownCmd:
if (!target->isVariant())
root->out.doNav(cmd,*this);*/
case upCmd:
nsel++;
if (nsel>=sz()) {if(wrap()) nsel=0; else nsel=sz()-1;}
break;
// trace(Serial<<"up"<<endl;);
nsel++;
if (nsel>=sz()) {if(wrap()) nsel=0; else nsel=sz()-1;}
// trace(Serial<<"new sel:"<<nsel<<endl);
break;
/*case scrlUpCmd:
if (!target->isVariant())
root->out.doNav(cmd,*this);*/
case downCmd:
// trace(Serial<<"down"<<endl);
if (nsel||!target->is(_asPad)) {
nsel--;
if (nsel<0) {if(wrap()) nsel=sz()-1; else nsel=0;}
Expand All @@ -62,9 +66,14 @@ navCmd navNode::doNavigation(navCmd cmd) {
case noCmd:
default: break;
}
if(osel!=nsel||changed) {//selection changed, must have been and idx/sel or an up/down movement
// trace(Serial<<"changed:"<<changed<<" sels?"<<(osel!=nsel)<<endl);
if((osel!=nsel)||changed) {//selection changed, must have been and idx/sel or an up/down movement
// trace(Serial<<"changed"<<endl);
if (target->sysStyles()&(_parentDraw|_isVariant)) {
trace(Serial<<"setting dirty"<<endl);
target->dirty=true;
//this works but might be too much, we dont want to invaludate all the menu!
// if (_parentDraw/*&&root->level*/) root->path[root->level-1].target->dirty=true;
} else {
operator[](osel).dirty=true;
operator[](nsel).dirty=true;
Expand Down

0 comments on commit 44ad5a3

Please sign in to comment.