From bd0ba45db84c5172b33558a657e82e0841798fe7 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 6 Jun 2024 21:31:28 +0500 Subject: [PATCH] Fix scrolling for vertical layout with horizontal packing Current scrolling effect looks interesting, but impractical, when with multiple columns. Signed-off-by: Dave Davenport --- source/widgets/listview.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 224396d38..ed64dfda6 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -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; @@ -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 @@ -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);