This commit is contained in:
djvs 2023-03-29 17:10:06 -04:00
parent 0b3f7f7bb8
commit a382dd03c1
2 changed files with 74 additions and 10 deletions

View File

@ -129,6 +129,21 @@ void listview_set_selected(listview *lv, unsigned int selected);
*/
unsigned int listview_get_selected(listview *lv);
/**
* @param lv The listview handle
*
* Move the selection one row up.
* - Wrap around.
*/
void listview_scroll_prev(listview *lv);
/**
* @param lv listview handle.
*
* Alternate, potentially multi-row alternative to listview_nav_up
* - Wrap around.
*/
void listview_scroll_next(listview *lv);
/**
* @param lv The listview handle
*
@ -143,12 +158,12 @@ void listview_nav_next(listview *lv);
* - Wrap around.
*/
void listview_nav_prev(listview *lv);
/**
* @param lv The listview handle
*
* Move the selection one row up.
* - Wrap around.
* Alternate, potentially multi-row alternative to listview_nav_down
* - No wrap around.
* - Do not move to top row when at start.
*/
void listview_nav_up(listview *lv);
/**

View File

@ -693,10 +693,10 @@ listview_trigger_action(widget *wid, MouseBindingListviewAction action,
listview_nav_right(lv);
break;
case SCROLL_DOWN:
listview_nav_down(lv);
listview_scroll_next(lv);
break;
case SCROLL_UP:
listview_nav_up(lv);
listview_scroll_prev(lv);
break;
}
return WIDGET_TRIGGER_ACTION_RESULT_HANDLED;
@ -816,6 +816,55 @@ listview *listview_create(widget *parent, const char *name,
*/
static void listview_nav_up_int(listview *lv) {
if (lv == NULL) {
return;
}
if (lv->req_elements == 0 || (lv->selected == 0 && !lv->cycle)) {
return;
}
if (lv->selected == 0) {
lv->selected = lv->req_elements;
}
lv->selected--;
lv->barview.direction = RIGHT_TO_LEFT;
if (lv->sc_callback) {
lv->sc_callback(lv, lv->selected, lv->sc_udata);
}
widget_queue_redraw(WIDGET(lv));
}
static void listview_nav_down_int(listview *lv) {
if (lv == NULL) {
return;
}
if (lv->req_elements == 0 ||
(lv->selected == (lv->req_elements - 1) && !lv->cycle)) {
return;
}
lv->selected = lv->selected < lv->req_elements - 1
? MIN(lv->req_elements - 1, lv->selected + 1)
: 0;
lv->barview.direction = LEFT_TO_RIGHT;
if (lv->sc_callback) {
lv->sc_callback(lv, lv->selected, lv->sc_udata);
}
widget_queue_redraw(WIDGET(lv));
}
void listview_nav_next(listview *lv) {
if (lv == NULL) {
return;
}
listview_nav_down_int(lv);
}
void listview_nav_prev(listview *lv) {
if (lv == NULL) {
return;
}
listview_nav_up_int(lv);
}
static void listview_scroll_up_int(listview *lv) {
if (lv == NULL) {
return;
}
@ -839,7 +888,7 @@ static void listview_nav_up_int(listview *lv) {
}
widget_queue_redraw(WIDGET(lv));
}
static void listview_nav_down_int(listview *lv) {
static void listview_scroll_down_int(listview *lv) {
if (lv == NULL) {
return;
}
@ -862,17 +911,17 @@ static void listview_nav_down_int(listview *lv) {
}
widget_queue_redraw(WIDGET(lv));
}
void listview_nav_next(listview *lv) {
void listview_scroll_next(listview *lv) {
if (lv == NULL) {
return;
}
listview_nav_down_int(lv);
listview_scroll_down_int(lv);
}
void listview_nav_prev(listview *lv) {
void listview_scroll_prev(listview *lv) {
if (lv == NULL) {
return;
}
listview_nav_up_int(lv);
listview_scroll_up_int(lv);
}
static void listview_nav_column_left_int(listview *lv) {