@@ -169,61 +169,45 @@ v2.0 - Calling action on every elements
169169 // this kind of information... till there we can not use paralle output devices! RA2016
170170 menuSelect (const char *text,unsigned int sz,menuValue<T>* const data[],T& target):
171171 menuVariant<T>(target,text,sz,data) {menuVariant<T>::sync ();}
172- virtual bool needRedraw (menuOut&p,bool selected) {
173- if (selected) {
174- bool nr=lastDrawnOp!=menu::sel;// ||((menuValue<T>*)pgmPtrNear(menu::data[menu::sel]))->value==menuVariant<T>::target;
175- // T v=((menuValue<T>*)pgmPtrNear(menu::data[menu::sel]))->value;
176- // if (nr) Serial<<"Variant need redraw:"<<*this<<endl
177- /* Serial
178- <<" value:"<<v<<endl
179- <<" target:"<<menuVariant<T>::target
180- <<" sel:"<<menu::sel
181- <<" lastSel:"<<p.lastSel
182- <<" lastDrawnOp:"<<lastDrawnOp
183- <<endl;;*/
184- // p.lastSel=menu::sel;
185- lastDrawnOp=menu::sel;
186- return nr;
187- }
188- return ((menuValue<T>*)pgmPtrNear (menu::data[menu::sel]))->value !=menuVariant<T>::target;
189- }
190172 virtual void printTo (menuOut& p) {
191- // Serial<<"drawing menuSelect"<<endl;
192173 menuVariant<T>::sync ();
193174 print_P (p,menu::text);
194175 p.print (menu::activeNode==this ?' :' :' ' );
195176 ((prompt*)pgmPtrNear (menu::data[menu::sel]))->printTo (p);
196177 }
197- promptFeedback activate (menuOut& p,Stream& c,bool ) {
198- if (menu::activeNode!=this ) {
199- // Serial<<"first select"<<endl;
200- if (menuVariant<T>::action (*this ,p,c)) return true ;
201- this ->setPosition (menuNode::activeNode->ox ,menuNode::activeNode->oy );
202- this ->menu ::previousMenu=(menu*)menu::activeNode;
203- menu::activeNode=this ;
204- this ->canExit =false ;
205- if (p.top >menu::sel) p.top =menu::sel;
206- else if (menu::sel+1 >p.maxY ) p.top =menu::sel-p.maxY +1 ;
207- p.lastSel =-1 ;// redraw only affected option
208- }
209- int op=menu::menuKeys (p,c,false );
210- menu::previousMenu->menu ::printMenu (p,menu::previousMenu->canExit );
211- if (op>=0 &&op<this ->menu ::sz) {
212- // Serial<<"Selecting op:"<<op<<endl;
213- this ->menu ::sel=op;
214- menuValue<T>* cp=(menuValue<T>*)pgmPtrNear (this ->menu ::data[op]);
215- if (cp->enabled ) {
216- this ->menuVariant <T>::target=cp->value ;
217- cp->activate (p,c,true );
218- p.lastSel =-1 ;// redraw only affected option
219- // and exit
220- this ->menu ::activeNode=this ->menu ::previousMenu;
221- c.flush ();// reset the encoder
222- }
223- }
224- // Serial<<"sel:"<<menu::sel<<" op:"<<op<<endl;
225- return false ;
226- }
178+ promptFeedback activate (menuOut& p,Stream& c,bool ) {
179+ if (menu::activeNode!=this ) {
180+ if (menuVariant<T>::action (*this ,p,c)) return true ;
181+ this ->setPosition (menuNode::activeNode->ox ,menuNode::activeNode->oy );
182+ menu::previousMenu=(menu*)menu::activeNode;
183+ menu::activeNode=this ;
184+ this ->canExit =false ;
185+ if (p.top >menu::sel) p.top =menu::sel;
186+ else if (menu::sel+1 >p.maxY ) p.top =menu::sel-p.maxY +1 ;
187+ p.lastSel =-1 ;// redraw only affected option
188+ }
189+ int lsel=menu::sel;
190+ int op=menu::menuKeys (p,c,false );
191+ if (op>=0 &&op<this ->menu ::sz) {
192+ menu::sel=op;
193+ menuValue<T>* cp=(menuValue<T>*)pgmPtrNear (this ->menu ::data[op]);
194+ if (cp->enabled ) {
195+ menuVariant<T>::target=cp->value ;
196+ cp->activate (p,c,true );
197+ p.lastSel =-1 ;// redraw only affected option
198+ // and exit
199+ this ->menu ::activeNode=this ->menu ::previousMenu;
200+ c.flush ();// reset the encoder
201+ }
202+ }
203+ if (menu::sel!=lsel) {
204+ menuVariant<T>::target=((menuValue<T>*)&menu::operator [](menu::sel))->value ;
205+ p.lastSel =-1 ;// redraw only affected option
206+ }
207+ menu::previousMenu->menu ::printMenu (p,menu::previousMenu->canExit );
208+ // Serial<<"sel:"<<menu::sel<<" op:"<<op<<endl;
209+ return false ;
210+ }
227211 };
228212
229213 template <typename T>
0 commit comments