From: Corey Berla Date: Thu, 5 May 2022 04:33:26 +0000 (-0700) Subject: gridview: Limit rectangle to gridview columns X-Git-Tag: archive/raspbian/4.8.3+ds-2+rpi1~3^2~20^2~4^2~38^2~8 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c6f357e44735a25feda5b6404bc62e765bc8f23d;p=gtk4.git gridview: Limit rectangle to gridview columns The function gtk_grid_view_get_items_in_rect() erroneously calculates columns less than 0 and greater than n_columns when the user attempts to rubberband all the way to the left or right respectively. This causes the rubberband to persistent and creates unexpected behavior. Limit the rows to a minimum of 0 and maximum of n_columns - 1. Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3445 --- diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index 6f2b7b0354..c2a4abe9d2 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -484,8 +484,8 @@ gtk_grid_view_get_items_in_rect (GtkListBase *base, if (n_items == 0) return result; - first_column = floor (rect->x / self->column_width); - last_column = floor ((rect->x + rect->width) / self->column_width); + first_column = fmax (floor (rect->x / self->column_width), 0); + last_column = fmin (floor ((rect->x + rect->width) / self->column_width), self->n_columns - 1); if (!gtk_grid_view_get_cell_at_y (self, rect->y, &first_row, NULL, NULL)) first_row = rect->y < 0 ? 0 : n_items - 1; if (!gtk_grid_view_get_cell_at_y (self, rect->y + rect->height, &last_row, NULL, NULL))