}
static gboolean
-gtk_grid_view_get_allocation_along (GtkListBase *base,
- guint pos,
- int *offset,
- int *size)
+gtk_grid_view_get_allocation (GtkListBase *base,
+ guint pos,
+ GdkRectangle *area)
{
GtkGridView *self = GTK_GRID_VIEW (base);
GtkListTile *tile;
- guint remaining;
+ guint offset;
- tile = gtk_list_item_manager_get_nth (self->item_manager, pos, &remaining);
- if (tile->n_items <= self->n_columns)
+ tile = gtk_list_item_manager_get_nth (self->item_manager, pos, &offset);
+ if (tile == NULL || tile->area.width <= 0 || tile->area.height <= 0)
+ return FALSE;
+
+ *area = tile->area;
+
+ if (tile->n_items > self->n_columns)
{
- *offset = tile->area.y;
- *size = tile->area.height;
+ area->height /= (tile->n_items / self->n_columns);
+ area->y += (offset / self->n_columns) * area->height;
+ offset %= self->n_columns;
}
- else
- {
- guint rows_in_tile = tile->n_items / self->n_columns;
- guint row_height = tile->area.height / rows_in_tile;
- guint row_index = remaining / self->n_columns;
- *offset = tile->area.y + row_index * row_height;
- *size = row_height;
+ if (tile->n_items > 1)
+ {
+ guint col = area->x / self->column_width;
+ area->x = ceil ((col + offset) * self->column_width);
+ area->width = ceil ((col + offset + 1) * self->column_width) - area->x;
}
return TRUE;
}
-static gboolean
-gtk_grid_view_get_allocation_across (GtkListBase *base,
- guint pos,
- int *offset,
- int *size)
-{
- GtkGridView *self = GTK_GRID_VIEW (base);
- guint start;
-
- pos %= self->n_columns;
- start = ceil (self->column_width * pos);
-
- if (offset)
- *offset = start;
- if (size)
- *size = ceil (self->column_width * (pos + 1)) - start;
-
- return TRUE;
-}
-
static gboolean
gtk_grid_view_get_position_from_allocation (GtkListBase *base,
int x,
list_base_class->list_item_name = "child";
list_base_class->list_item_role = GTK_ACCESSIBLE_ROLE_GRID_CELL;
list_base_class->split = gtk_grid_view_split;
- list_base_class->get_allocation_along = gtk_grid_view_get_allocation_along;
- list_base_class->get_allocation_across = gtk_grid_view_get_allocation_across;
+ list_base_class->get_allocation = gtk_grid_view_get_allocation;
list_base_class->get_items_in_rect = gtk_grid_view_get_items_in_rect;
list_base_class->get_position_from_allocation = gtk_grid_view_get_position_from_allocation;
list_base_class->move_focus_along = gtk_grid_view_move_focus_along;
}
/*
- * gtk_list_base_get_allocation_along:
+ * gtk_list_base_get_allocation:
* @self: a `GtkListBase`
- * @pos: item to get the size of
- * @offset: (out caller-allocates) (optional): set to the offset
- * of the top/left of the item
- * @size: (out caller-allocates) (optional): set to the size of
- * the item in the direction
+ * @pos: item to get the area of
+ * @area: (out caller-allocates): set to the area
+ * occupied by the item
*
- * Computes the allocation of the item in the direction along the sizing
- * axis.
+ * Computes the allocation of the item in the given position
*
* Returns: %TRUE if the item exists and has an allocation, %FALSE otherwise
**/
static gboolean
-gtk_list_base_get_allocation_along (GtkListBase *self,
- guint pos,
- int *offset,
- int *size)
+gtk_list_base_get_allocation (GtkListBase *self,
+ guint pos,
+ GdkRectangle *area)
{
- return GTK_LIST_BASE_GET_CLASS (self)->get_allocation_along (self, pos, offset, size);
-}
-
-/*
- * gtk_list_base_get_allocation_across:
- * @self: a `GtkListBase`
- * @pos: item to get the size of
- * @offset: (out caller-allocates) (optional): set to the offset
- * of the top/left of the item
- * @size: (out caller-allocates) (optional): set to the size of
- * the item in the direction
- *
- * Computes the allocation of the item in the direction across to the sizing
- * axis.
- *
- * Returns: %TRUE if the item exists and has an allocation, %FALSE otherwise
- **/
-static gboolean
-gtk_list_base_get_allocation_across (GtkListBase *self,
- guint pos,
- int *offset,
- int *size)
-{
- return GTK_LIST_BASE_GET_CLASS (self)->get_allocation_across (self, pos, offset, size);
+ return GTK_LIST_BASE_GET_CLASS (self)->get_allocation (self, pos, area);
}
/*
guint pos)
{
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
- int start, end;
double align_along, align_across;
GtkPackType side_along, side_across;
+ GdkRectangle area;
- /* figure out primary orientation and if position is valid */
- if (!gtk_list_base_get_allocation_along (GTK_LIST_BASE (self), pos, &start, &end))
+ if (!gtk_list_base_get_allocation (GTK_LIST_BASE (self), pos, &area))
return;
- end += start;
gtk_list_base_compute_scroll_align (self,
gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
- start, end,
+ area.y, area.y + area.height,
priv->anchor_align_along, priv->anchor_side_along,
&align_along, &side_along);
- /* now do the same thing with the other orientation */
- if (!gtk_list_base_get_allocation_across (GTK_LIST_BASE (self), pos, &start, &end))
- return;
-
- end += start;
gtk_list_base_compute_scroll_align (self,
gtk_list_base_get_opposite_orientation (GTK_LIST_BASE (self)),
- start, end,
+ area.x, area.x + area.width,
priv->anchor_align_across, priv->anchor_side_across,
&align_across, &side_across);
pos = gtk_list_base_get_focus_position (self);
page_size = gtk_adjustment_get_page_size (priv->adjustment[priv->orientation]);
- if (!gtk_list_base_get_allocation_along (self, pos, &area.y, &area.height) ||
- !gtk_list_base_get_allocation_across (self, pos, &area.x, &area.width))
+ if (!gtk_list_base_get_allocation (self, pos, &area))
return TRUE;
if (!gtk_list_base_get_position_from_allocation (self,
area.x + area.width / 2,
if (end == 0)
return TRUE;
- if (!gtk_list_base_get_allocation_along (self, pos, &area.y, &area.height) ||
- !gtk_list_base_get_allocation_across (self, pos, &area.x, &area.width))
+ if (!gtk_list_base_get_allocation (self, pos, &area))
return TRUE;
if (!gtk_list_base_get_position_from_allocation (self,
}
else
{
+ GdkRectangle area;
guint pos = gtk_list_item_tracker_get_position (priv->item_manager, priv->rubberband->start_tracker);
- if (gtk_list_base_get_allocation_along (self, pos, &y1, &y2) &&
- gtk_list_base_get_allocation_across (self, pos, &x1, &x2))
+ if (gtk_list_base_get_allocation (self, pos, &area))
{
- x1 += x2 * priv->rubberband->start_align_across;
- y1 += y2 * priv->rubberband->start_align_along;
+ x1 = area.x + area.width * priv->rubberband->start_align_across;
+ y1 = area.y + area.height * priv->rubberband->start_align_along;
}
else
{
{
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
GdkRectangle bounds;
- int value_along, value_across, size;
+ int value_along, value_across;
int page_along, page_across;
guint pos;
}
else
{
- if (gtk_list_base_get_allocation_across (self, pos, &value_across, &size))
+ GdkRectangle area;
+
+ if (gtk_list_base_get_allocation (self, pos, &area))
{
+ value_across = area.x;
+ value_along = area.y;
if (priv->anchor_side_across == GTK_PACK_END)
- value_across += size;
- value_across -= priv->anchor_align_across * page_across;
- }
- else
- {
- value_along = 0;
- }
- if (gtk_list_base_get_allocation_along (self, pos, &value_along, &size))
- {
+ value_across += area.width;
if (priv->anchor_side_along == GTK_PACK_END)
- value_along += size;
+ value_along += area.height;
+ value_across -= priv->anchor_align_across * page_across;
value_along -= priv->anchor_align_along * page_along;
}
else
{
+ value_across = 0;
value_along = 0;
}
}
}
static gboolean
-gtk_list_view_get_allocation_along (GtkListBase *base,
- guint pos,
- int *offset,
- int *size)
+gtk_list_view_get_allocation (GtkListBase *base,
+ guint pos,
+ GdkRectangle *area)
{
GtkListView *self = GTK_LIST_VIEW (base);
GtkListTile *tile;
- guint skip;
- int row_height;
+ guint offset;
- tile = gtk_list_item_manager_get_nth (self->item_manager, pos, &skip);
+ tile = gtk_list_item_manager_get_nth (self->item_manager, pos, &offset);
if (tile == NULL)
- {
- if (offset)
- *offset = 0;
- if (size)
- *size = 0;
- return FALSE;
- }
-
- row_height = tile->area.height / tile->n_items;
-
- if (offset)
- *offset = tile->area.y + skip * row_height;
- if (size)
- *size = row_height;
-
- return TRUE;
-}
-
-static gboolean
-gtk_list_view_get_allocation_across (GtkListBase *base,
- guint pos,
- int *offset,
- int *size)
-{
- GtkListView *self = GTK_LIST_VIEW (base);
+ return FALSE;
+ *area = tile->area;
+ if (tile->n_items)
+ area->height /= tile->n_items;
if (offset)
- *offset = 0;
- if (size)
- *size = self->list_width;
+ area->y += offset * area->height;
- return TRUE;
+ return area->width > 0 && area->height > 0;
}
static GtkBitset *
list_base_class->list_item_name = "row";
list_base_class->list_item_role = GTK_ACCESSIBLE_ROLE_LIST_ITEM;
list_base_class->split = gtk_list_view_split;
- list_base_class->get_allocation_along = gtk_list_view_get_allocation_along;
- list_base_class->get_allocation_across = gtk_list_view_get_allocation_across;
+ list_base_class->get_allocation = gtk_list_view_get_allocation;
list_base_class->get_items_in_rect = gtk_list_view_get_items_in_rect;
list_base_class->get_position_from_allocation = gtk_list_view_get_position_from_allocation;
list_base_class->move_focus_along = gtk_list_view_move_focus_along;