Skip to content

Commit

Permalink
Place continuous scroll center in middle column
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Davenport <[email protected]>
  • Loading branch information
Nikita Zlobin authored and DaveDavenport committed Jun 6, 2024
1 parent dee97eb commit 753cd1e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions source/widgets/listview.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,17 @@ static unsigned int scroll_per_page(listview *lv) {
}

static unsigned int scroll_continious(listview *lv) {
unsigned int middle = (lv->max_rows - ((lv->max_rows & 1) == 0)) / 2;
unsigned int vmid = (lv->max_rows - 1) / 2;
unsigned int hmid = (lv->menu_columns - 1) / 2;
unsigned int middle = (lv->max_rows * hmid) + vmid;
unsigned int offset = 0;
if (lv->selected > middle) {
if (lv->selected < (lv->req_elements - (lv->max_rows - middle))) {
if (lv->selected < (lv->req_elements - (lv->max_elements - middle))) {
offset = lv->selected - middle;
}
// Don't go below zero.
else if (lv->req_elements > lv->max_rows) {
offset = lv->req_elements - lv->max_rows;
else if (lv->req_elements > lv->max_elements) {
offset = lv->req_elements - lv->max_elements;
}
}
if (offset != lv->cur_page) {
Expand Down

0 comments on commit 753cd1e

Please sign in to comment.