mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2024-12-28 20:43:40 +01:00
jlist: add user data pointer
This allows the info and paint functions to access user data associated with the list without going through globals.
This commit is contained in:
parent
12b29f8223
commit
7587dfa17c
2 changed files with 10 additions and 4 deletions
|
@ -77,6 +77,8 @@ typedef struct jlist {
|
|||
|
||||
/* Currently selected item, -1 if none */
|
||||
int cursor;
|
||||
/* User data pointer */
|
||||
void *user;
|
||||
|
||||
} jlist;
|
||||
|
||||
|
@ -91,8 +93,9 @@ jlist *jlist_create(jlist_item_info_function info_function,
|
|||
|
||||
/* jlist_update_model(): Update jlists's information about the model
|
||||
The new model size is passed as parameter. The model is refreshed by
|
||||
repeatedly calling the info function. */
|
||||
void jlist_update_model(jlist *l, int item_count);
|
||||
repeatedly calling the info function. The user pointer is also updated. To
|
||||
keep it unchanged, pass `l->user` as third parameter. */
|
||||
void jlist_update_model(jlist *l, int item_count, void *user);
|
||||
|
||||
/* jlist_clear(): Remove all items */
|
||||
void jlist_clear(jlist *l);
|
||||
|
|
|
@ -37,6 +37,7 @@ jlist *jlist_create(jlist_item_info_function info_function,
|
|||
l->info_function = info_function;
|
||||
l->paint_function = paint_function;
|
||||
l->cursor = -1;
|
||||
l->user = NULL;
|
||||
return l;
|
||||
}
|
||||
|
||||
|
@ -113,8 +114,10 @@ int jlist_selected_item(jlist *l)
|
|||
// Item management
|
||||
//---
|
||||
|
||||
void jlist_update_model(jlist *l, int item_count)
|
||||
void jlist_update_model(jlist *l, int item_count, void *user)
|
||||
{
|
||||
l->user = user;
|
||||
|
||||
if(l->item_count != item_count) {
|
||||
l->items = realloc(l->items, item_count * sizeof *l->items);
|
||||
if(!l->items) {
|
||||
|
@ -138,7 +141,7 @@ void jlist_update_model(jlist *l, int item_count)
|
|||
|
||||
void jlist_clear(jlist *l)
|
||||
{
|
||||
jlist_update_model(l, 0);
|
||||
jlist_update_model(l, 0, NULL);
|
||||
}
|
||||
|
||||
jrect jlist_selected_region(jlist *l)
|
||||
|
|
Loading…
Reference in a new issue