gtkcolumnviewcolumn: Only create cells when the column is visible

It's a big performance drag to create many cells (and their associated
widgets) for columns that may never be shown. Only create cells
is the column is visible, and subsequently create/remove cells
when in column_set_visible.
This commit is contained in:
Corey Berla 2022-12-29 10:56:01 -08:00
parent f3ad6015c6
commit 7ad693f865
2 changed files with 8 additions and 11 deletions

View File

@ -65,10 +65,11 @@ gtk_column_list_item_factory_setup (GtkListItemFactory *factory,
{
GtkColumnViewColumn *column = g_list_model_get_item (columns, i);
gtk_column_list_item_factory_add_column (self,
widget,
column,
FALSE);
if (gtk_column_view_column_get_visible (column))
gtk_column_list_item_factory_add_column (self,
widget,
column,
FALSE);
g_object_unref (column);
}

View File

@ -579,7 +579,8 @@ gtk_column_view_column_remove_header (GtkColumnViewColumn *self)
static void
gtk_column_view_column_ensure_cells (GtkColumnViewColumn *self)
{
if (self->view && gtk_widget_get_root (GTK_WIDGET (self->view)))
if (self->view && gtk_widget_get_root (GTK_WIDGET (self->view)) &&
gtk_column_view_column_get_visible (self))
gtk_column_view_column_create_cells (self);
else
gtk_column_view_column_remove_cells (self);
@ -804,8 +805,6 @@ void
gtk_column_view_column_set_visible (GtkColumnViewColumn *self,
gboolean visible)
{
GtkColumnViewCell *cell;
g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
if (self->visible == visible)
@ -819,10 +818,7 @@ gtk_column_view_column_set_visible (GtkColumnViewColumn *self,
if (self->header)
gtk_widget_set_visible (GTK_WIDGET (self->header), visible);
for (cell = self->first_cell; cell; cell = gtk_column_view_cell_get_next (cell))
{
gtk_widget_set_visible (GTK_WIDGET (cell), visible);
}
gtk_column_view_column_ensure_cells (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VISIBLE]);
}