Skip to content

Commit e4d2e77

Browse files
authored
Merge pull request #120 from neu-rah/dev
fixed text edit cursor position on u8g2
2 parents f421a77 + 5198bb0 commit e4d2e77

File tree

11 files changed

+104
-97
lines changed

11 files changed

+104
-97
lines changed

TODO.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Arduino Menu Library
22

3+
- put navRoot.sleepTask as protected and add `bool suspended()` function
4+
- make clipping out of menu logic! check with hardware on gfx
5+
=> do so with panels independence!
6+
- simplify showTitle! current requires checking root and local overrides (and to be correct output size)
7+
- use setFont (API extension)
38
- password fields
49
- scroll long prompts (not for serial)
510
- allow disabled items to receive events! for help print purposes
@@ -20,7 +25,10 @@ Arduino Menu Library
2025
- constructing the callback table...
2126
a) navRoot.begin() but then webmenu had to register
2227
b) * use esp8266Out.begin()
23-
28+
-problems:
29+
index what? actions, prompts? fields are templates!
30+
the esp8266Out is not related to a menu
31+
=> put the table into navRoot... but only if we have a web output
2432
- central menu init by calling menu begin
2533
=> check's ex: if numeric input available then output numeric indexes
2634
- help texts

examples/U8G2/U8G2/U8G2.ino

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ using namespace Menu;
6363
#elif (U8G2OUT==SSD1306)
6464
#include <Wire.h>
6565
#define fontName u8g2_font_5x7_tf
66-
#define fontX 5
66+
#define fontX 6
6767
#define fontY 8
6868
#define offsetX 0
6969
#define offsetY 0
@@ -89,27 +89,8 @@ const colorDef<uint8_t> colors[] MEMMODE={
8989

9090
result doAlert(eventMask e, prompt &item);
9191

92-
result showEvent(eventMask e,navNode& nav,prompt& item) {
93-
Serial.print("event: ");
94-
Serial.println(e);
95-
return proceed;
96-
}
97-
9892
int test=55;
9993

100-
result action1(eventMask e) {
101-
Serial.print(e);
102-
Serial.println(" action1 executed, proceed menu");
103-
Serial.flush();
104-
return proceed;
105-
}
106-
107-
result action2(eventMask e,navNode& nav, prompt &item) {
108-
Serial.print(e);
109-
Serial.print(" action2 executed, quiting menu");
110-
return quit;
111-
}
112-
11394
int ledCtrl=HIGH;
11495

11596
result ledOn() {
@@ -141,21 +122,19 @@ CHOOSE(chooseTest,chooseMenu,"Choose",doNothing,noEvent,noStyle
141122
,VALUE("Last",-1,doNothing,noEvent)
142123
);
143124

144-
//customizing a prompt look!
145-
//by extending the prompt class
146-
class altPrompt:public prompt {
147-
public:
148-
altPrompt(constMEM promptShadow& p):prompt(p) {}
149-
Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t panelNr) override {
150-
return out.printRaw("special prompt!",len);;
151-
}
152-
};
153-
154-
MENU(subMenu,"Sub-Menu",showEvent,anyEvent,noStyle
155-
,OP("Sub1",showEvent,anyEvent)
156-
,OP("Sub2",showEvent,anyEvent)
157-
,OP("Sub3",showEvent,anyEvent)
158-
,altOP(altPrompt,"",showEvent,anyEvent)
125+
// //customizing a prompt look!
126+
// //by extending the prompt class
127+
// class altPrompt:public prompt {
128+
// public:
129+
// altPrompt(constMEM promptShadow& p):prompt(p) {}
130+
// Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t panelNr) override {
131+
// return out.printRaw("special prompt!",len);;
132+
// }
133+
// };
134+
135+
MENU(subMenu,"Sub-Menu",doNothing,noEvent,noStyle
136+
,OP("Sub1",doNothing,noEvent)
137+
// ,altOP(altPrompt,"",doNothing,noEvent)
159138
,EXIT("<Back")
160139
);
161140

@@ -164,9 +143,9 @@ char* constMEM hexNr[] MEMMODE={"0","x",hexDigit,hexDigit};
164143
char buf1[]="0x11";
165144

166145
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
167-
,OP("Op1",action1,anyEvent)
168-
,OP("Op2",action2,enterEvent)
169-
,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
146+
,OP("Op1",doNothing,noEvent)
147+
,OP("Op2",doNothing,noEvent)
148+
//,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
170149
,SUBMENU(subMenu)
171150
,SUBMENU(setLed)
172151
,OP("LED On",ledOn,enterEvent)
@@ -175,7 +154,7 @@ MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
175154
,SUBMENU(chooseMenu)
176155
,OP("Alert test",doAlert,enterEvent)
177156
,EDIT("Hex",buf1,hexNr,doNothing,noEvent,noStyle)
178-
,EXIT("<Back")
157+
,EXIT("<Exit")
179158
);
180159

181160
#define MAX_DEPTH 2
@@ -243,6 +222,7 @@ void setup() {
243222
#endif
244223
u8g2.begin();
245224
u8g2.setFont(fontName);
225+
u8g2.setBitmapMode(0);
246226

247227
//disable second option
248228
mainMenu[1].enabled=disabledStatus;

examples/adafruitGfx/lcdMono/lcdMono/lcdMono.ino

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,17 @@ TOGGLE(ledCtrl,setLed,"Led: ",doNothing,noEvent,noStyle//,doExit,enterEvent,noSt
6363
,VALUE("Off",LOW,doNothing,noEvent)
6464
);
6565

66+
char* constMEM hexDigit MEMMODE="0123456789ABCDEF";
67+
char* constMEM hexNr[] MEMMODE={"0","x",hexDigit,hexDigit};
68+
char buf1[]="0x11";
69+
6670
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
6771
,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
6872
,SUBMENU(setLed)
6973
,OP("LED On",ledOn,enterEvent)
7074
,OP("LED Off",ledOff,enterEvent)
7175
,OP("Alert test",doAlert,enterEvent)
76+
,EDIT("Hex",buf1,hexNr,doNothing,noEvent,noStyle)
7277
,EXIT("<Back")
7378
);
7479

@@ -86,7 +91,8 @@ const colorDef<uint16_t> colors[] MEMMODE={
8691

8792
#define gfxWidth 84
8893
#define gfxHeight 48
89-
#define fontX 5
94+
#define fontX 6
95+
//5
9096
#define fontY 9
9197
#define MAX_DEPTH 2
9298

@@ -182,6 +188,7 @@ void setup() {
182188
delay(2000);
183189
gfx.clearDisplay();
184190
gfx.display(); // show splashscreen
191+
// gfx.drawRect(0, 0, 84, 48, 1);
185192
}
186193

187194
void loop() {

examples/adafruitGfx/tft/tft/tft.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ char buf1[]="0x11";
113113
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
114114
,OP("Op1",doNothing,noEvent)
115115
,OP("Op2",doNothing,noEvent)
116-
,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
116+
// ,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
117117
,SUBMENU(subMenu)
118118
,SUBMENU(setLed)
119119
,OP("LED On",ledOn,enterEvent)

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name=ArduinoMenu library
2-
version=4.0.1
2+
version=4.0.2
33
author=Rui Azevedo, [email protected]
44
maintainer=neu-rah, [email protected]
55
sentence=AVR generic menu/interactivity system
66
paragraph=Easy to define menu system with sub-menus and associated function to call. Works either over serial or nultiple combinations of IO
77
category=Display
88
url=https://github.com/neu-rah/ArduinoMenu
9-
dot_a_linkage=false
9+
dot_a_linkage=true
1010
architectures=*
1111
includes=menu.h

src/menu.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ result Menu::inaction(menuOut& o,idleEvent) {
1212
return proceed;
1313
}
1414

15+
bool prompt::hasTitle(navNode& nav) const {return (nav.target->has(showTitle)||(nav.root->showTitle&&!nav.target->has(noTitle)));}
16+
1517
idx_t prompt::printRaw(menuOut& out,idx_t len) const {
1618
trace(Serial<<"prompt::printRaw"<<endl);
1719
return print_P(out,getText(),len);
@@ -131,18 +133,19 @@ Used textField::printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len
131133
out.write(editing?":":" ");
132134
l++;
133135
}
134-
idx_t c=l;
136+
// idx_t c=l;
135137
//idx_t top=out.tops[root.level];
136-
idx_t tit=root.showTitle?1:0;
137-
idx_t line=idx+tit;
138+
idx_t tit=hasTitle(root.node())?1:0;
139+
idx_t line=idx+tit;//-out.tops[root.level];
138140
while(buffer()[at]&&l++<len)
139141
if (at==cursor&&editing) {
140-
c=l;
141-
l+=out.startCursor(root,c,line,charEdit);//draw textual cursor or color code start
142+
// Serial<<"idx:"<<idx<<" line:"<<line<<" at:"<<at<<" l:"<<l<<endl;
143+
// c=l+1;
144+
l+=out.startCursor(root,l,line,charEdit);//draw textual cursor or color code start
142145
out.write(buffer()[at++]);//draw focused character
143-
l+=out.endCursor(root,c,line,charEdit);//draw textual cursor or color code end
146+
l+=out.endCursor(root,l,line,charEdit);//draw textual cursor or color code end
144147
} else out.write(buffer()[at++]);
145-
l+=out.editCursor(root,c,line,editing,charEdit);//reposition a non text cursor
148+
l+=out.editCursor(root,l,line,editing,charEdit);//reposition a non text cursor
146149
return l;
147150
}
148151

src/menu.h

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ for correcting unsigned values validation
1919
#define RSITE_ARDUINO_MENU_SYSTEM
2020
#include <Arduino.h>
2121
#if defined(DEBUG)
22-
#include <streamFlow.h>
22+
// #ifdef _U8G2LIB_HH
23+
//because U8G2 already uses Streaming
24+
#include <Streaming.h>
25+
// #else
26+
// #include <streamFlow.h>
27+
// #endif
2328
#endif
2429
#include "menuBase.h"
2530
#include "shadows.h"
@@ -80,12 +85,15 @@ for correcting unsigned values validation
8085
inline bool is(eventMask chk) const {return (events()&chk)==chk;}
8186
inline bool has(eventMask chk) const {return events()&chk;}
8287

88+
8389
inline bool canWrap() const {return style()&wrapStyle;}
8490
inline bool canNav() const {return sysStyles()&_canNav;}//can receive navigation focus and process keys
8591
inline bool isMenu() const {return sysStyles()&_menuData;}//has menu data list and can be a navNode target
8692
inline bool isVariant() const {return sysStyles()&_isVariant;}//a menu as an enumerated field, connected to a variable value
8793
inline bool parentDraw() const {return sysStyles()&_parentDraw;}//a menu as an enumerated field, connected to a variable value
8894
inline bool asPad() const {return sysStyles()&_asPad;}//a menu as an enumerated field, connected to a variable value
95+
inline bool hasTitle(navNode& nav) const;
96+
8997
virtual Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t panelNr=0);//raw print to output device
9098
virtual bool changed(const navNode &nav,const menuOut& out,bool sub=true) {return dirty;}
9199
//this is the system version of enter handler, its used by elements like toggle
@@ -574,22 +582,22 @@ for correcting unsigned values validation
574582
void refresh() {//force redraw of all outputs on next output call
575583
for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->drawn=NULL;
576584
}
577-
void clearLine(idx_t ln,idx_t panelNr=0,colorDefs color=bgColor,bool selected=false,status stat=enabledStatus) const {
578-
for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->clearLine(ln,panelNr,color,selected,stat);
579-
}
585+
// void clearLine(idx_t ln,idx_t panelNr=0,colorDefs color=bgColor,bool selected=false,status stat=enabledStatus) const {
586+
// for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->clearLine(ln,panelNr,color,selected,stat);
587+
// }
580588
void clearChanged(navNode& nav) const {
581589
for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->clearChanged(nav);
582590
}
583591
void clear() {for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->clear();}
584-
void setCursor(idx_t x,idx_t y) {
585-
for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->setCursor(x,y);
586-
}
587-
void setColor(colorDefs c,bool selected=false,status s=enabledStatus) {
588-
for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->setColor(c,selected,s);
589-
}
590-
void drawCursor(idx_t ln,bool selected,status stat,idx_t panelNr=0) {
591-
for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->drawCursor(ln,selected,stat,panelNr);
592-
}
592+
// void setCursor(idx_t x,idx_t y) {
593+
// for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->setCursor(x,y);
594+
// }
595+
// void setColor(colorDefs c,bool selected=false,status s=enabledStatus) {
596+
// for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->setColor(c,selected,s);
597+
// }
598+
// void drawCursor(idx_t ln,bool selected,status stat,idx_t panelNr=0) {
599+
// for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->drawCursor(ln,selected,stat,panelNr);
600+
// }
593601
void doNav(navCmd cmd,class navNode &nav) {for(int n=0;n<cnt;n++) ((menuOut*)memPtr(outs[n]))->doNav(cmd,nav);}
594602
result idle(idleFunc f,idleEvent e) {
595603
#ifdef DEBUG
@@ -677,7 +685,7 @@ for correcting unsigned values validation
677685
for(idx_t n=0;n<=d;n++)//initialize path chain for this root (v4.0)
678686
path[n].root=this;
679687
}
680-
void useMenu(constMEM menuNode &menu) {
688+
void useMenu(menuNode &menu) {
681689
navFocus=&menu;
682690
path[0].target=&menu;
683691
reset();
@@ -812,7 +820,7 @@ for correcting unsigned values validation
812820
#ifdef DEBUG
813821
inline String& operator<<(String&s,prompt &p) {return s+=p.getText();}
814822
inline Stream& operator<<(Stream&o,prompt& p) {print_P(o,p.getText());return o;}
815-
inline Stream& operator<<(Stream&o,const navNode& p) {return o<<*p.target;}
823+
inline Stream& operator<<(Stream&o,const navNode& p) {return o<<*(prompt*)p.target;}
816824
inline Stream& operator<<(Stream&o,const navRoot& p) {return o<<p.node();}
817825
#endif
818826
}//namespace Menu

src/menuBase.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -188,29 +188,29 @@ www.r-site.net
188188

189189
#ifdef DRAW_2D
190190
typedef class Area {
191-
protected:
192-
inline Area op(Area& (Area::*o)(const Area&),const Area&p) const {
193-
Area tmp(*this);
194-
return (tmp.*o)(p);
195-
}
196-
public:
197-
idx_t w;
198-
idx_t h;
199-
inline Area() {}
200-
inline Area(idx_t w,idx_t h):w(w),h(h) {}
201-
inline Area(const Area& o):w(o.w),h(o.h) {}
202-
inline Area(idx_t x):w(x),h(0) {}
203-
inline operator idx_t() {return w;}
204-
inline Area operator-() {return Area(-h,-w);}
205-
inline Area& operator+=(const Area& o) {w+=o.w;h+=o.h;return *this;}
206-
inline Area& operator-=(const Area& o) {w-=o.w;h-=o.h;return *this;}
207-
inline Area& operator&=(const Area& o) {
208-
if (w<o.w) w=o.w;
209-
if (h<o.h) h=o.h;
210-
return *this;
211-
}
212-
inline Area operator+ (const Area& o) const {return op(&Area::operator+=,o);}
213-
inline Area operator- (const Area& o) const {return op(&Area::operator-=,o);}
191+
protected:
192+
inline Area op(Area& (Area::*o)(const Area&),const Area&p) const {
193+
Area tmp(*this);
194+
return (tmp.*o)(p);
195+
}
196+
public:
197+
idx_t w;
198+
idx_t h;
199+
inline Area() {}
200+
inline Area(idx_t w,idx_t h):w(w),h(h) {}
201+
inline Area(const Area& o):w(o.w),h(o.h) {}
202+
inline Area(idx_t x):w(x),h(0) {}
203+
inline operator idx_t() {return w;}
204+
inline Area operator-() {return Area(-h,-w);}
205+
inline Area& operator+=(const Area& o) {w+=o.w;h+=o.h;return *this;}
206+
inline Area& operator-=(const Area& o) {w-=o.w;h-=o.h;return *this;}
207+
inline Area& operator&=(const Area& o) {
208+
if (w<o.w) w=o.w;
209+
if (h<o.h) h=o.h;
210+
return *this;
211+
}
212+
inline Area operator+ (const Area& o) const {return op(&Area::operator+=,o);}
213+
inline Area operator- (const Area& o) const {return op(&Area::operator-=,o);}
214214
} Used;
215215
#else
216216
typedef idx_t Used;

src/menuIO/esp8266Out.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@
1111
#include <ESP8266mDNS.h>
1212
//#include <Hash.h>
1313
//#include <FS.h>
14+
#include <vector>
15+
16+
using namespace std;
1417

1518
namespace Menu {
1619

1720
class esp8266Out:public menuOut {
1821
public:
19-
//typedef const char* webColor;
20-
//const colorDef<webColor> (&colors)[nColors];
2122
esp8266Out(
2223
//const colorDef<webColor> (&c)[nColors],
2324
idx_t* t,
2425
panelsList& p,
2526
menuOut::styles styles=(menuOut::styles)(redraw|expandEnums)
2627
):menuOut(t,p,styles) {}
27-
//size_t write(uint8_t ch) override {return client->write(ch);}
28-
/*inline webColor getColor(colorDefs color=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) const {
29-
return (webColor)memPtr(&(stat==enabledStatus?colors[color].enabled[selected+edit]:colors[color].disabled[selected]));
30-
}*/
3128
menuOut& fill(
3229
int x1, int y1, int x2, int y2,char ch=' ',
3330
colorDefs color=bgColor,

src/menuIO/serialIO.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* -*- C++ -*- */
2+
#include "serialIn.h"
3+
#include "serialOut.h"

0 commit comments

Comments
 (0)