listview: Simplify allocation

With the Tile changes, a lot of stuff does no longer need to be
duplicated between listview and gridview. Move it to ListBase instead.
This commit is contained in:
Benjamin Otte 2023-03-02 21:27:52 +01:00 committed by Benjamin Otte
parent 8aea6fc1b5
commit f3c53ae69d
4 changed files with 45 additions and 71 deletions

View File

@ -624,21 +624,19 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
GtkListTile *tile, *start;
GArray *heights;
int min_row_height, unknown_row_height, row_height, col_min, col_nat;
GtkOrientation orientation, opposite_orientation;
GtkOrientation orientation;
GtkScrollablePolicy scroll_policy;
GdkRectangle bounds;
int x, y;
int y;
guint i;
orientation = gtk_list_base_get_orientation (GTK_LIST_BASE (self));
scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), orientation);
opposite_orientation = OPPOSITE_ORIENTATION (orientation);
min_row_height = ceil ((double) height / GTK_GRID_VIEW_MAX_VISIBLE_ROWS);
/* step 0: exit early if list is empty */
if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
{
gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
gtk_list_base_allocate (GTK_LIST_BASE (self));
return;
}
@ -756,19 +754,8 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
}
}
gtk_list_item_manager_get_tile_bounds (self->item_manager, &bounds);
/* step 4: update the adjustments */
gtk_list_base_update_adjustments (GTK_LIST_BASE (self),
bounds.width,
bounds.height,
gtk_widget_get_size (widget, opposite_orientation),
gtk_widget_get_size (widget, orientation),
&x, &y);
gtk_list_base_allocate_children (GTK_LIST_BASE (widget));
gtk_list_base_allocate_rubberband (GTK_LIST_BASE (widget));
/* step 4: allocate the rest */
gtk_list_base_allocate (GTK_LIST_BASE (self));
}
static void

View File

@ -1355,7 +1355,7 @@ update_autoscroll (GtkListBase *self,
remove_autoscroll (self);
}
/**
/*
* gtk_list_base_size_allocate_child:
* @self: The listbase
* @child: The child
@ -1368,7 +1368,7 @@ update_autoscroll (GtkListBase *self,
* but with the coordinates already offset by the scroll
* offset.
**/
void
static void
gtk_list_base_size_allocate_child (GtkListBase *self,
GtkWidget *child,
int x,
@ -1432,7 +1432,7 @@ gtk_list_base_size_allocate_child (GtkListBase *self,
gtk_widget_size_allocate (child, &child_allocation, -1);
}
void
static void
gtk_list_base_allocate_children (GtkListBase *self)
{
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
@ -1537,7 +1537,7 @@ gtk_list_base_get_rubberband_coords (GtkListBase *self,
return TRUE;
}
void
static void
gtk_list_base_allocate_rubberband (GtkListBase *self)
{
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
@ -1912,7 +1912,7 @@ gtk_list_base_init_real (GtkListBase *self,
gtk_widget_add_controller (GTK_WIDGET (self), controller);
}
static int
static void
gtk_list_base_set_adjustment_values (GtkListBase *self,
GtkOrientation orientation,
int value,
@ -1940,23 +1940,24 @@ gtk_list_base_set_adjustment_values (GtkListBase *self,
g_signal_handlers_unblock_by_func (priv->adjustment[orientation],
gtk_list_base_adjustment_value_changed_cb,
self);
return value;
}
void
gtk_list_base_update_adjustments (GtkListBase *self,
int total_across,
int total_along,
int page_across,
int page_along,
int *across,
int *along)
static void
gtk_list_base_update_adjustments (GtkListBase *self)
{
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
GdkRectangle bounds;
int value_along, value_across, size;
int page_along, page_across;
guint pos;
gtk_list_item_manager_get_tile_bounds (priv->item_manager, &bounds);
g_assert (bounds.x == 0);
g_assert (bounds.y == 0);
page_across = gtk_widget_get_size (GTK_WIDGET (self), OPPOSITE_ORIENTATION (priv->orientation));
page_along = gtk_widget_get_size (GTK_WIDGET (self), priv->orientation);
pos = gtk_list_item_tracker_get_position (priv->item_manager, priv->anchor);
if (pos == GTK_INVALID_LIST_POSITION)
{
@ -1987,16 +1988,25 @@ gtk_list_base_update_adjustments (GtkListBase *self,
}
}
*across = gtk_list_base_set_adjustment_values (self,
OPPOSITE_ORIENTATION (priv->orientation),
value_across,
total_across,
page_across);
*along = gtk_list_base_set_adjustment_values (self,
priv->orientation,
value_along,
total_along,
page_along);
gtk_list_base_set_adjustment_values (self,
OPPOSITE_ORIENTATION (priv->orientation),
value_across,
bounds.width,
page_across);
gtk_list_base_set_adjustment_values (self,
priv->orientation,
value_along,
bounds.height,
page_along);
}
void
gtk_list_base_allocate (GtkListBase *self)
{
gtk_list_base_update_adjustments (self);
gtk_list_base_allocate_children (self);
gtk_list_base_allocate_rubberband (self);
}
GtkScrollablePolicy

View File

@ -76,13 +76,6 @@ guint gtk_list_base_get_n_items (GtkListBase
GtkSelectionModel * gtk_list_base_get_model (GtkListBase *self);
gboolean gtk_list_base_set_model (GtkListBase *self,
GtkSelectionModel *model);
void gtk_list_base_update_adjustments (GtkListBase *self,
int total_across,
int total_along,
int page_across,
int page_along,
int *across,
int *along);
guint gtk_list_base_get_anchor (GtkListBase *self);
void gtk_list_base_set_anchor (GtkListBase *self,
@ -107,14 +100,7 @@ gboolean gtk_list_base_grab_focus_on_item (GtkListBase
void gtk_list_base_set_enable_rubberband (GtkListBase *self,
gboolean enable);
gboolean gtk_list_base_get_enable_rubberband (GtkListBase *self);
void gtk_list_base_allocate_rubberband (GtkListBase *self);
void gtk_list_base_allocate_children (GtkListBase *self);
void gtk_list_base_size_allocate_child (GtkListBase *self,
GtkWidget *child,
int x,
int y,
int width,
int height);
void gtk_list_base_allocate (GtkListBase *self);
#endif /* __GTK_LIST_BASE_PRIVATE_H__ */

View File

@ -506,8 +506,7 @@ gtk_list_view_size_allocate (GtkWidget *widget,
GtkListView *self = GTK_LIST_VIEW (widget);
GtkListTile *tile;
GArray *heights;
int min, nat, row_height;
int x, y;
int min, nat, row_height, y;
GtkOrientation orientation, opposite_orientation;
GtkScrollablePolicy scroll_policy, opposite_scroll_policy;
@ -519,7 +518,7 @@ gtk_list_view_size_allocate (GtkWidget *widget,
/* step 0: exit early if list is empty */
if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
{
gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
gtk_list_base_allocate (GTK_LIST_BASE (self));
return;
}
@ -570,16 +569,8 @@ gtk_list_view_size_allocate (GtkWidget *widget,
y += tile->area.height;
}
/* step 4: update the adjustments */
gtk_list_base_update_adjustments (GTK_LIST_BASE (self),
self->list_width,
gtk_list_view_get_list_height (self),
gtk_widget_get_size (widget, opposite_orientation),
gtk_widget_get_size (widget, orientation),
&x, &y);
gtk_list_base_allocate_children (GTK_LIST_BASE (self));
gtk_list_base_allocate_rubberband (GTK_LIST_BASE (self));
/* step 4: allocate the rest */
gtk_list_base_allocate (GTK_LIST_BASE (self));
}
static void