123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #include "dotListBox.h"
- #include "gui.h"
- #include "uiEntry.h"
- #include "board.h"
- #include "log.h"
- #include "app.h"
- #define LIST_ITEM_NUM_MAX 100
- #define LIST_MAX_ROW_BYTE (20+1+2)
- #define LIST_MAX_SHOW_BYTE 16
- typedef struct{
- unsigned short itemnum; //item number
- unsigned short total; //user total
- unsigned short handle; //current item
- unsigned short page;
- char **item;
- char title[16+1];
- }SUT_DOT_LISTBOX;
- static SUT_DOT_LISTBOX dotHandle;
- void dotListBoxShow(void){
- unsigned short handle;
- char info[20];
- if(dotHandle.handle>=dotHandle.total){
- MSG_WARN(1,"handle over!", dotHandle.total, dotHandle.handle);
- dotHandle.handle=0;
- }
- handle=dotHandle.handle;
- if(dotHandle.total==0) snprintf(info, sizeof(info), "%d/%d", dotHandle.total,0);
- else snprintf(info, sizeof(info), "%d/%d", dotHandle.total, dotHandle.page*5+handle+1);
- newGuiClearMainPage();
- newGuiShowStr(0, STATUS_BAR_HEIGH, dotHandle.title,REVERSED_NO,FONT_MODE_16X16);
- newGuiShowStr(0, STATUS_BAR_HEIGH+16, info,REVERSED_NO,FONT_MODE_16X16);
- getRealShow(info, dotHandle.item[handle],LIST_MAX_SHOW_BYTE);//不显示超界,多的后面会滚动
- newGuiShowStr(0, STATUS_BAR_HEIGH+32, info,REVERSED_NO,FONT_MODE_16X16);
- }
- //title:标题
- //total: >=0 强制用于显示为总数,否则总数从计数条目得出
- //forcehandle: >=0 强制显示此索引项目
- void dotListBoxInit(char **itemlist,char *title,int total,int forcehandle,unsigned short pindex){
- UI_STACKDEF *uiPtr=getStackStruct();
- unsigned char i,ch,index;
- //统计item
- dotHandle.item = itemlist;
-
- i = 0;
- while(i<LIST_ITEM_NUM_MAX)
- {
- ch=dotHandle.item[i][0];
- if(ch==0)break;
- i ++;
- }
- i=i-1;
- dotHandle.itemnum = i+1;
- dotHandle.page=pindex;
- if(total>=0) dotHandle.total=total;
- else dotHandle.total=dotHandle.itemnum;
- if(uiPtr->esc || uiPtr->ok_back){
- uiPtr->esc=0;
- uiPtr->ok_back=0;
- dotHandle.handle=uiPullStack();
- if(dotHandle.handle<0) dotHandle.handle=0;
- }else dotHandle.handle=0;
- if(forcehandle>=0) dotHandle.handle=forcehandle;
- snprintf(dotHandle.title, sizeof(dotHandle.title), "%s",title);
- //显示
- dotListBoxShow();
- }
- unsigned short dotListBoxResponse(void){
- unsigned char needShow=1;
- unsigned short key=getKeyValue();
- if(dotHandle.itemnum<=0) return key;
-
- switch(key){
- case MKEY_VALUE_DOWN:
- if(++dotHandle.handle>=dotHandle.itemnum){
- dotHandle.handle=0;
- if(dotHandle.total>dotHandle.itemnum) needShow=0;//翻页时是否要显示
- }
- if(needShow) dotListBoxShow();
- break;
- default:
- return key;
- }
- return key;
- }
- void dotLeftMoveSelectedItem(void){
- static char item[LIST_MAX_ROW_BYTE];
- static unsigned short sum;
- unsigned short tsum;
- int len,i;
- char showMax[LIST_MAX_ROW_BYTE];
- char *str=dotHandle.item[dotHandle.handle];
- static unsigned int cnt=0xffff;
-
- if(++cnt<500/APP_SUB_DIV_TIME) return;
- cnt=0;
- if(strlen(str)<=LIST_MAX_SHOW_BYTE-1) return;
- snprintf(showMax, sizeof(showMax), "%s ", str);
- len=strlen(showMax);
- tsum=0;
- for(i=0;i<len;i++) tsum += showMax[i];
- if(len>LIST_MAX_SHOW_BYTE){
- if(sum != tsum){
- sum=tsum;
- memcpy(item, showMax, LIST_MAX_ROW_BYTE);
- }else leftMoveStr(item, strlen(item));
- getRealShow(showMax, item,LIST_MAX_SHOW_BYTE);
- newGuiClearPage(0, ROW_FOUR);
- newGuiShowStr(0, 48, showMax,REVERSED_NO,FONT_MODE_16X16);
- }
- }
- unsigned short dotListGetHandle(void){return dotHandle.handle;}
- unsigned short dotListGetItemNum(void){return dotHandle.itemnum;}
|