list work in progress

ugfx_release_2.6
Joel Bodenmann 2013-07-27 15:23:52 +02:00
parent 57eeb16aba
commit 9dfcbef848
1 changed files with 16 additions and 5 deletions

View File

@ -40,17 +40,28 @@ and use gw->pstyle->pressed->text for the selected text color
typedef struct ListItem { typedef struct ListItem {
gfxQueueASyncItem q_item; // This must be the first member in the struct gfxQueueASyncItem q_item; // This must be the first member in the struct
uint16_t id;
uint16_t flags; uint16_t flags;
#define LISTITEM_ALLOCEDTEXT 0x0001 #define LISTITEM_ALLOCEDTEXT 0x0001
#define LISTITEM_SELECTED 0x0002 #define LISTITEM_SELECTED 0x0002
uint16_t uparam; uint16_t param; // A parameter the user can specify himself
const char* text; const char* text;
#if GWIN_LIST_IMAGES #if GWIN_LIST_IMAGES
gdispImage* pimg; gdispImage* pimg;
#endif #endif
} ListItem; } ListItem;
static int _getSelected(GWidgetObject *gw) {
gfxQueueASyncItem* qi;
uint16_t i;
for(qi = gfxQueueASyncPeek(&((GListObject*)gw)->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
if (((ListItem*)qi)->flags & GLIST_FLG_SELECTED)
return i;
}
return -1;
}
static void sendListEvent(GWidgetObject *gw) { static void sendListEvent(GWidgetObject *gw) {
GSourceListener* psl; GSourceListener* psl;
GEvent* pe; GEvent* pe;
@ -58,17 +69,18 @@ static void sendListEvent(GWidgetObject *gw) {
// Trigger a GWIN list event // Trigger a GWIN list event
psl = 0; psl = 0;
while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) { while ((psl = geventGetSourceListener(GWIDGET_SOURCE, psl))) {
if (!(pe = geventGetEventBuffer(psl))) if (!(pe = geventGetEventBuffer(psl)))
continue continue
pse->type = GEVENT_GWIN_SLIDER; pse->type = GEVENT_GWIN_SLIDER;
pse->list = (GHandle)gw; pse->list = (GHandle)gw;
pse->item = 42; pse->item = _getSelected(gw);
geventSendEvent(psl); geventSendEvent(psl);
} }
#undef pse #undef pse
} }
@ -104,7 +116,6 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) {
item_height = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight) + 2; item_height = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight) + 2;
item_id = (y - gw->g.y) / item_height; item_id = (y - gw->g.y) / item_height;
printf("item_id = %d\r\n", item_id);
for(qi = gfxQueueASyncPeek(&gcw->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) { for(qi = gfxQueueASyncPeek(&gcw->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
if (item_id == i) if (item_id == i)