[gtk: 2/11] gridview: Limit rectangle to gridview columns




commit c6f357e44735a25feda5b6404bc62e765bc8f23d
Author: Corey Berla <corey berla me>
Date:   Wed May 4 21:33:26 2022 -0700

    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

 gtk/gtkgridview.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
---
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))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]