mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2025-06-06 21:35:05 +02:00
jlist: add background/inversion selection feature
This commit is contained in:
parent
0c8371edce
commit
3488c6515a
2 changed files with 24 additions and 10 deletions
|
@ -9,10 +9,12 @@
|
||||||
#include <justui/jwidget.h>
|
#include <justui/jwidget.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
/* Selected item is styled by the paint function or delegate */
|
||||||
|
JLIST_SELECTION_MANUAL = 0,
|
||||||
/* Selected item is indicated by inverting its rendered area */
|
/* Selected item is indicated by inverting its rendered area */
|
||||||
JLIST_SELECTION_INVERT = 0,
|
JLIST_SELECTION_INVERT = 1,
|
||||||
/* Selected item is indicated by applying a background color */
|
/* Selected item is indicated by applying a background color */
|
||||||
JLIST_SELECTION_BACKGROUND = 1,
|
JLIST_SELECTION_BACKGROUND = 2,
|
||||||
|
|
||||||
} jlist_selection_style;
|
} jlist_selection_style;
|
||||||
|
|
||||||
|
@ -23,6 +25,10 @@ typedef struct {
|
||||||
bool selectable;
|
bool selectable;
|
||||||
/* Whether item can be triggered */
|
/* Whether item can be triggered */
|
||||||
bool triggerable;
|
bool triggerable;
|
||||||
|
/* Selection style for jlist to draw */
|
||||||
|
int8_t selection_style;
|
||||||
|
/* Selection background color for JLIST_SELECTION_BACKGROUND */
|
||||||
|
uint16_t selection_bg_color;
|
||||||
|
|
||||||
/* The following fields are only applicable if there is no delegate. */
|
/* The following fields are only applicable if there is no delegate. */
|
||||||
|
|
||||||
|
|
24
src/jlist.c
24
src/jlist.c
|
@ -193,16 +193,24 @@ static void jlist_poly_render(void *l0, int x, int y)
|
||||||
|
|
||||||
for(int i = 0; i < l->item_count; i++) {
|
for(int i = 0; i < l->item_count; i++) {
|
||||||
jlist_item_info *info = &l->items[i];
|
jlist_item_info *info = &l->items[i];
|
||||||
|
bool selected = (l->cursor == i);
|
||||||
|
|
||||||
if(info->delegate) {
|
int h = info->delegate
|
||||||
|
? jwidget_full_height(info->delegate)
|
||||||
|
: info->natural_height;
|
||||||
|
|
||||||
|
if(selected && info->selection_style == JLIST_SELECTION_BACKGROUND)
|
||||||
|
drect(x1, y, x2, y + h - 1, info->selection_bg_color);
|
||||||
|
|
||||||
|
if(info->delegate)
|
||||||
jwidget_render(info->delegate, x1, y);
|
jwidget_render(info->delegate, x1, y);
|
||||||
y += jwidget_full_height(info->delegate);
|
else
|
||||||
}
|
l->paint_function(x1, y, x2-x1+1, h, l, i, selected);
|
||||||
else {
|
|
||||||
l->paint_function(x1, y, x2-x1+1, info->natural_height, l, i,
|
if(selected && info->selection_style == JLIST_SELECTION_INVERT)
|
||||||
l->cursor == i);
|
drect(x1, y, x2, y + h - 1, C_INVERT);
|
||||||
y += info->natural_height;
|
|
||||||
}
|
y += h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue