Skip to content

Commit

Permalink
Fix scrolling for vertical layout with horizontal packing
Browse files Browse the repository at this point in the history
Current scrolling effect looks interesting, but impractical, when with
multiple columns.

Signed-off-by: Dave Davenport <[email protected]>
  • Loading branch information
Nikita Zlobin authored and DaveDavenport committed Jun 6, 2024
1 parent 753cd1e commit bd0ba45
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions source/widgets/listview.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ static unsigned int scroll_per_page(listview *lv) {
return offset;
}

static unsigned int scroll_continious(listview *lv) {
// For vertical packing flow
static unsigned int scroll_continious_elements(listview *lv) {
unsigned int vmid = (lv->max_rows - 1) / 2;
unsigned int hmid = (lv->menu_columns - 1) / 2;
unsigned int middle = (lv->max_rows * hmid) + vmid;
Expand All @@ -315,6 +316,31 @@ static unsigned int scroll_continious(listview *lv) {
return offset;
}

// For horizontal packing flow
static unsigned int scroll_continious_rows(listview *lv) {
unsigned int middle, selected, req_rows, offset;
middle = (lv->max_rows - 1) / 2;
selected = lv->selected / lv->menu_columns;
req_rows = (lv->req_elements + lv->menu_columns - 1) / lv->menu_columns;
offset = 0;
if (selected > middle) {
if (selected < (req_rows - (lv->max_rows - middle))) {
offset = selected - middle;
}
// Don't go below zero.
else if (req_rows > lv->max_rows) {
offset = req_rows - lv->max_rows;
}
}
offset *= lv->menu_columns;
if (offset != lv->cur_page) {
// scrollbar_set_handle ( lv->scrollbar, offset );
lv->cur_page = offset;
lv->rchanged = TRUE;
}
return offset;
}

static void update_element(listview *lv, unsigned int tb, unsigned int index,
gboolean full) {
// Select drawing mode
Expand Down Expand Up @@ -419,10 +445,12 @@ static void barview_draw(widget *wid, cairo_t *draw) {
static void listview_draw(widget *wid, cairo_t *draw) {
unsigned int offset = 0;
listview *lv = (listview *)wid;
if (lv->scroll_type == LISTVIEW_SCROLL_CONTINIOUS) {
offset = scroll_continious(lv);
} else {
if (lv->scroll_type == LISTVIEW_SCROLL_PER_PAGE) {
offset = scroll_per_page(lv);
} else if (lv->pack_direction == ROFI_ORIENTATION_VERTICAL) {
offset = scroll_continious_elements(lv);
} else {
offset = scroll_continious_rows(lv);
}
// Set these all together to make sure they update consistently.
scrollbar_set_max_value(lv->scrollbar, lv->req_elements);
Expand Down

0 comments on commit bd0ba45

Please sign in to comment.