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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user