From 97e3c652518c66313c9e29dabed92e75b482fd1c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 9 Mar 2023 04:02:22 +0100 Subject: [PATCH] listview: Move bounds check into base class This way, listview and gridview don't need to check if the rect is out of bounds and nothing is selected, a quick rectangle_intersect() does the job for them. --- gtk/gtkgridview.c | 14 ++++---------- gtk/gtklistbase.c | 9 ++++++++- gtk/gtklistview.c | 17 ----------------- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index 6abbfc55da..dcfd1edd68 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -378,22 +378,16 @@ gtk_grid_view_get_items_in_rect (GtkListBase *base, { GtkGridView *self = GTK_GRID_VIEW (base); guint first_row, last_row, first_column, last_column; - GdkRectangle bounds; GtkBitset *result; result = gtk_bitset_new_empty (); - /* limit rect to the region that actually overlaps items */ - gtk_list_item_manager_get_tile_bounds (self->item_manager, &bounds); - if (!gdk_rectangle_intersect (&bounds, rect, &bounds)) - return result; - - first_column = fmax (floor (bounds.x / self->column_width), 0); - last_column = fmin (floor ((bounds.x + bounds.width) / self->column_width), self->n_columns - 1); + 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); /* match y = 0 here because we care about the rows, not the cells */ - if (!gtk_grid_view_get_position_from_allocation (base, 0, bounds.y, &first_row, NULL)) + if (!gtk_grid_view_get_position_from_allocation (base, 0, rect->y, &first_row, NULL)) g_return_val_if_reached (result); - if (!gtk_grid_view_get_position_from_allocation (base, 0, bounds.y + bounds.height - 1, &last_row, NULL)) + if (!gtk_grid_view_get_position_from_allocation (base, 0, rect->y + rect->height - 1, &last_row, NULL)) g_return_val_if_reached (result); gtk_bitset_add_rectangle (result, diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c index 1e4ee499a3..7b781bf3b3 100644 --- a/gtk/gtklistbase.c +++ b/gtk/gtklistbase.c @@ -1454,7 +1454,14 @@ static GtkBitset * gtk_list_base_get_items_in_rect (GtkListBase *self, const GdkRectangle *rect) { - return GTK_LIST_BASE_GET_CLASS (self)->get_items_in_rect (self, rect); + GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self); + GdkRectangle bounds; + + gtk_list_item_manager_get_tile_bounds (priv->item_manager, &bounds); + if (!gdk_rectangle_intersect (&bounds, rect, &bounds)) + return gtk_bitset_new_empty (); + + return GTK_LIST_BASE_GET_CLASS (self)->get_items_in_rect (self, &bounds); } static gboolean diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c index 6765165791..f210ac26ce 100644 --- a/gtk/gtklistview.c +++ b/gtk/gtklistview.c @@ -186,20 +186,6 @@ dump (GtkListView *self) g_print (" => %u widgets in %u list rows\n", n_widgets, n_list_rows); } -static int -gtk_list_view_get_list_height (GtkListView *self) -{ - GtkListTile *tile; - GtkListTileAugment *aug; - - tile = gtk_list_item_manager_get_root (self->item_manager); - if (tile == NULL) - return 0; - - aug = gtk_list_tile_get_augment (self->item_manager, tile); - return aug->area.height; -} - static GtkListTile * gtk_list_view_split (GtkListBase *base, GtkListTile *tile, @@ -297,9 +283,6 @@ gtk_list_view_get_items_in_rect (GtkListBase *base, result = gtk_bitset_new_empty (); - if (rect->y >= gtk_list_view_get_list_height (self)) - return result; - n_items = gtk_list_base_get_n_items (base); if (n_items == 0) return result; -- 2.30.2