From ba7b0a02d0701bd564294456452b897251bb2768 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Wed, 4 Sep 2024 08:49:52 +0200 Subject: [PATCH] jlist, jscrolledlist: make parent the last constructor argument To stay in line with constructors for other widgets. --- include/justui/jlist.h | 11 +++++++++-- include/justui/jscrolledlist.h | 7 ++++--- src/jlist.c | 4 ++-- src/jscrolledlist.c | 9 +++++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/justui/jlist.h b/include/justui/jlist.h index 4910e3d..cc395d7 100644 --- a/include/justui/jlist.h +++ b/include/justui/jlist.h @@ -39,9 +39,16 @@ typedef struct { struct jlist; +/* Info function: should fill `info` with the data related to list element + #index (starts at 0). `info` is guaranteed to be pre-initialized to 0. */ typedef void (*jlist_item_info_function)(struct jlist *list, int index, jlist_item_info *info); +/* Paint function: should draw element #index on the rectangle of size `w×h` + at position `x,y`. If the item has a selection style that is not + JLIST_SELECTION_MANUAL, the selection effect is handled by jlist. Otherwise, + the paint function should check the `selected` parameter to apply any + relevant styling. */ typedef void (*jlist_item_paint_function)(int x, int y, int w, int h, struct jlist *list, int index, bool selected); @@ -79,8 +86,8 @@ extern uint16_t JLIST_SELECTION_MOVED; extern uint16_t JLIST_MODEL_UPDATED; /* jlist_create(): Create a new (empty) jlist. */ -jlist *jlist_create(void *parent, jlist_item_info_function info_function, - jlist_item_paint_function paint_function); +jlist *jlist_create(jlist_item_info_function info_function, + jlist_item_paint_function paint_function, void *parent); /* jlist_update_model(): Update jlists's information about the model The new model size is passed as parameter. The model is refreshed by diff --git a/include/justui/jscrolledlist.h b/include/justui/jscrolledlist.h index a4a1d9f..6b64472 100644 --- a/include/justui/jscrolledlist.h +++ b/include/justui/jscrolledlist.h @@ -25,9 +25,10 @@ typedef struct { } jscrolledlist; -/* jscrolledlist_create(): Create a scrolled list */ -jscrolledlist *jscrolledlist_create(void *parent, +/* Create a scrolled list; arguments are forwarded to the jlist. */ +jscrolledlist *jscrolledlist_create( jlist_item_info_function info_function, - jlist_item_paint_function paint_function); + jlist_item_paint_function paint_function, + void *parent); #endif /* _J_JSCROLLEDLIST */ diff --git a/src/jlist.c b/src/jlist.c index 57d8d1d..c61baf4 100644 --- a/src/jlist.c +++ b/src/jlist.c @@ -19,8 +19,8 @@ struct jlist_item_info { bool selectable; }; -jlist *jlist_create(void *parent, jlist_item_info_function info_function, - jlist_item_paint_function paint_function) +jlist *jlist_create(jlist_item_info_function info_function, + jlist_item_paint_function paint_function, void *parent) { if(jlist_type_id < 0) return NULL; diff --git a/src/jscrolledlist.c b/src/jscrolledlist.c index f835e42..d4ecc12 100644 --- a/src/jscrolledlist.c +++ b/src/jscrolledlist.c @@ -8,9 +8,10 @@ /* Type identifier for jscrolledlist */ static int jscrolledlist_type_id = -1; -jscrolledlist *jscrolledlist_create(void *parent, +jscrolledlist *jscrolledlist_create( jlist_item_info_function info_function, - jlist_item_paint_function paint_function) + jlist_item_paint_function paint_function, + void *parent) { if(jscrolledlist_type_id < 0) return NULL; @@ -26,7 +27,7 @@ jscrolledlist *jscrolledlist_create(void *parent, jwidget_set_stretch(l->frame, 1, 1, false); jframe_set_align(l->frame, J_ALIGN_LEFT, J_ALIGN_TOP); - l->list = jlist_create(l->frame, info_function, paint_function); + l->list = jlist_create(info_function, paint_function, l->frame); jwidget_set_stretch(l->list, 1, 1, false); return l; @@ -67,7 +68,7 @@ static bool jscrolledlist_poly_event(void *l0, jevent e) if(e.type == JLIST_MODEL_UPDATED && e.source == l->list) shake_scroll(l, true); - /* Allow the evnts to bubble up */ + /* Allow the events to bubble up */ return false; }