Jump to content

New function for List


TriZet

Recommended Posts

Hi again! :)

I do some device and I was needed functions for select/deselect item. And for scroll to the item in List.

I don't find how it can be do in uGFX. If it can be please say how )) But for now I added this functions.

Maybe some people this functions can help too. Or maybe you add them to uGFX to improve functionality. :)


//===============================================================
// item - is item to modify
// param - TRUE to select, FALSE to deselect
//
void gwinListSetSelected(GHandle gh, int item, bool_t param) {
const gfxQueueASyncItem * qi;
int i;

// is it a valid handle?
if (gh->vmt != (gwinVMT *)&listVMT)
return;

// watch out for an invalid item
if (item < 0 || item > (gh2obj->cnt) - 1)
return;

// If not a multiselect mode - clear previous selected item
if (!(gh->flags & GLIST_FLG_MULTISELECT)) {
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
if (qi2li->flags & GLIST_FLG_SELECTED) {
qi2li->flags &= ~GLIST_FLG_SELECTED;
break; // or without break to deselect all
}
}
}

// Find item and set selected or not
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
if (i == item) {
if(param == TRUE )qi2li->flags |= GLIST_FLG_SELECTED;
else qi2li->flags &= ~GLIST_FLG_SELECTED;
break;
}
}
_gwinUpdate(gh);
}

//===============================================================
// item - scrool to him
void gwinListScroollToItem(GHandle gh, int item) {
int iheight, oldtop;
// is it a valid handle?
if (gh->vmt != (gwinVMT *)&listVMT)
return;

// watch out for an invalid item
if (item < 0 || item > (gh2obj->cnt) - 1)
return;

iheight = gdispGetFontMetric(gh->font, fontHeight) + VERTICAL_PADDING;
gh2obj->top = iheight * item;

if (gh2obj->top >= gh2obj->cnt * iheight - (gh->height-2))
gh2obj->top = gh2obj->cnt * iheight - (gh->height-2) - 1;

if (gh2obj->top < 0)
gh2obj->top = 0;

_gwinUpdate(gh);
}

//===============================================================

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...