From 860abb83a2db62faebfeb59d2312b148f1112040 Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 6 Nov 2019 13:46:58 +0100 Subject: [PATCH] Better control on MenuList --- src/M5StackSAM.cpp | 53 ++++++++++++++++++++++++---------------------- src/M5StackSAM.h | 14 +++++++----- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/M5StackSAM.cpp b/src/M5StackSAM.cpp index a3cb4c0..8915ef8 100644 --- a/src/M5StackSAM.cpp +++ b/src/M5StackSAM.cpp @@ -35,18 +35,18 @@ void M5SAM::clearList(){ } void M5SAM::addList(String inStr){ - if(inStr.length()<=M5SAM_LIST_MAX_LABEL_SIZE and inStr.length()>0 and list_count < M5SAM_LIST_MAX_COUNT){ + if(inStr.length()<=listMaxLabelSize and inStr.length()>0 and list_count < M5SAM_LIST_MAX_COUNT){ list_labels[list_count] = inStr; list_count++; } if(list_count>0){ - if(list_count > M5SAM_LIST_PAGE_LABELS){ - list_lastpagelines = list_count % M5SAM_LIST_PAGE_LABELS; + if(list_count > listPagination){ + list_lastpagelines = list_count % listPagination; if(list_lastpagelines>0){ - list_pages = (list_count - list_lastpagelines) / M5SAM_LIST_PAGE_LABELS; + list_pages = (list_count - list_lastpagelines) / listPagination; list_pages++; }else{ - list_pages = list_count / M5SAM_LIST_PAGE_LABELS; + list_pages = list_count / listPagination; } }else{ list_pages = 1; @@ -58,10 +58,10 @@ byte M5SAM::getListID(){ return list_idx; } void M5SAM::setListID(byte idx) { - if(idx< list_page * M5SAM_LIST_PAGE_LABELS + list_lines){ + if(idx< list_page * listPagination + list_lines){ list_idx = idx; } - list_page = list_idx / M5SAM_LIST_PAGE_LABELS; + list_page = list_idx / listPagination; } String M5SAM::getListString(){ @@ -69,7 +69,7 @@ String M5SAM::getListString(){ } void M5SAM::nextList( bool renderAfter ){ - if(list_idx< list_page * M5SAM_LIST_PAGE_LABELS + list_lines - 1){ + if(list_idx< list_page * listPagination + list_lines - 1){ list_idx++; }else{ if(list_page",3,80+(postIDX*20),2); + M5.Lcd.drawString(list_labels[inIDX],15,listPageLabelsOffset+(postIDX*20),2); + M5.Lcd.drawString(">",3,listPageLabelsOffset+(postIDX*20),2); }else{ - M5.Lcd.drawString(list_labels[inIDX],15,80+(postIDX*20),2); + M5.Lcd.drawString(list_labels[inIDX],15,listPageLabelsOffset+(postIDX*20),2); } } void M5SAM::showList(){ windowClr(); byte labelid = 0; - M5.Lcd.drawCentreString(listCaption,M5.Lcd.width()/2,45,2); + M5.Lcd.setTextDatum( listCaptionDatum ); + //M5.Lcd.drawCentreString(listCaption,M5.Lcd.width()/2,45,2); + M5.Lcd.drawString(listCaption, listCaptionXPos, listCaptionYPos, 2); + M5.Lcd.setTextDatum( TL_DATUM ); if((list_page + 1) == list_pages){ - if(list_lastpagelines == 0 and list_count >= M5SAM_LIST_PAGE_LABELS){ - list_lines = M5SAM_LIST_PAGE_LABELS; - for(byte i = 0;i= listPagination){ + list_lines = listPagination; + for(byte i = 0;i1){ list_lines = list_lastpagelines; for(byte i = 0;i - +/* +// why was it even here ? #if defined(WIRING) && WIRING >= 100 #include #elif defined(ARDUINO) && ARDUINO >= 100 @@ -7,7 +8,7 @@ #else #include #endif - +*/ #ifndef M5StackSAM_h #define M5StackSAM_h @@ -18,8 +19,6 @@ #ifndef M5SAM_LIST_MAX_COUNT #define M5SAM_LIST_MAX_COUNT 128 #endif -#define M5SAM_LIST_MAX_LABEL_SIZE 36 -#define M5SAM_LIST_PAGE_LABELS 6 volatile static uint8_t _keyboardIRQRcvd; volatile static uint8_t _keyboardChar; @@ -48,6 +47,12 @@ class M5SAM { void setListCaption(String inCaption); String keyboardGetString(); String lastBtnTittle[3]; + uint8_t listMaxLabelSize = 36; // list labels will be trimmed + uint8_t listPagination = 6; + uint8_t listPageLabelsOffset = 80; // initially 80, pixels offset from top screen for list items + uint8_t listCaptionDatum = TC_DATUM; // initially TC_DATUM=top centered, TL_DATUM=top left (default), top/right/bottom/left + uint16_t listCaptionXPos = 160; // initially M5.Lcd.width()/2, text cursor position-x for list caption + uint16_t listCaptionYPos = 45; // initially 45, text cursor position-x for list caption private: String listCaption; @@ -66,7 +71,6 @@ class M5SAM { char btnCtitle[M5SAM_BTN_TITLE_MAX_SIZE + 1]; signed char gotoLevel; void (*function)(); - }; String list_labels[M5SAM_LIST_MAX_COUNT]; byte list_lastpagelines;