[gtk/prop-list: 32/83] column: Add a visible property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 32/83] column: Add a visible property
- Date: Mon, 23 Dec 2019 05:43:27 +0000 (UTC)
commit f5dc92852843be2439b28fbd4b36671b46339125
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 16 14:01:42 2019 -0500
column: Add a visible property
This lets us hide columns, which is useful.
docs/reference/gtk/gtk4-sections.txt | 2 +
gtk/gtkcolumnviewcell.c | 1 +
gtk/gtkcolumnviewcolumn.c | 76 ++++++++++++++++++++++++++++++++++++
gtk/gtkcolumnviewcolumn.h | 6 +++
4 files changed, 85 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 83d6dae1ea..a438ebd556 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -624,6 +624,8 @@ gtk_column_view_column_set_title
gtk_column_view_column_get_title
gtk_column_view_column_set_sorter
gtk_column_view_column_get_sorter
+gtk_column_view_column_set_visible
+gtk_column_view_column_get_visible
<SUBSECTION Standard>
GTK_COLUMN_VIEW_COLUMN
GTK_COLUMN_VIEW_COLUMN_CLASS
diff --git a/gtk/gtkcolumnviewcell.c b/gtk/gtkcolumnviewcell.c
index ecaa39dd46..4df02a0194 100644
--- a/gtk/gtkcolumnviewcell.c
+++ b/gtk/gtkcolumnviewcell.c
@@ -156,6 +156,7 @@ gtk_column_view_cell_new (GtkColumnViewColumn *column)
cell = g_object_new (GTK_TYPE_COLUMN_VIEW_CELL,
"factory", gtk_column_view_column_get_factory (column),
+ "visible", gtk_column_view_column_get_visible (column),
NULL);
cell->column = g_object_ref (column);
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
index 0672d86435..7111d0c35f 100644
--- a/gtk/gtkcolumnviewcolumn.c
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -61,6 +61,8 @@ struct _GtkColumnViewColumn
int allocation_offset;
int allocation_size;
+ gboolean visible;
+
/* This list isn't sorted - this is just caching for performance */
GtkColumnViewCell *first_cell; /* no reference, just caching */
};
@@ -77,6 +79,7 @@ enum
PROP_FACTORY,
PROP_TITLE,
PROP_SORTER,
+ PROP_VISIBLE,
N_PROPS
};
@@ -126,6 +129,10 @@ gtk_column_view_column_get_property (GObject *object,
g_value_set_object (value, self->sorter);
break;
+ case PROP_VISIBLE:
+ g_value_set_boolean (value, self->visible);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -154,6 +161,10 @@ gtk_column_view_column_set_property (GObject *object,
gtk_column_view_column_set_sorter (self, g_value_get_object (value));
break;
+ case PROP_VISIBLE:
+ gtk_column_view_column_set_visible (self, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -212,6 +223,18 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
GTK_TYPE_SORTER,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+ /**
+ * GtkColumnViewColumn:visible:
+ *
+ * Whether this column is visible
+ */
+ properties[PROP_VISIBLE] =
+ g_param_spec_boolean ("visible",
+ P_("Visible"),
+ P_("Whether this column is visible"),
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@@ -220,6 +243,7 @@ gtk_column_view_column_init (GtkColumnViewColumn *self)
{
self->minimum_size_request = -1;
self->natural_size_request = -1;
+ self->visible = TRUE;
}
/**
@@ -648,3 +672,55 @@ gtk_column_view_column_notify_sort (GtkColumnViewColumn *self)
if (self->header)
gtk_column_view_title_update (GTK_COLUMN_VIEW_TITLE (self->header));
}
+
+/**
+ * gtk_column_view_column_set_visible:
+ * @self: a #GtkColumnViewColumn
+ * @visible: whether this column should be visible
+ *
+ * Sets whether this column should be visible in views.
+ */
+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)
+ return;
+
+ self->visible = visible;
+
+ self->minimum_size_request = -1;
+ self->natural_size_request = -1;
+
+ 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);
+ }
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VISIBLE]);
+}
+
+/**
+ * gtk_column_view_get_visible:
+ * @self: a #GtkColumnViewColumn
+ *
+ * Returns whether this column is visible.
+ *
+ * Returns: %TRUE if this column is visible
+ */
+gboolean
+gtk_column_view_column_get_visible (GtkColumnViewColumn *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), TRUE);
+
+ return self->visible;
+}
+
+
diff --git a/gtk/gtkcolumnviewcolumn.h b/gtk/gtkcolumnviewcolumn.h
index f74cedaa08..f0005809be 100644
--- a/gtk/gtkcolumnviewcolumn.h
+++ b/gtk/gtkcolumnviewcolumn.h
@@ -72,6 +72,12 @@ void gtk_column_view_column_set_sorter (GtkColu
GDK_AVAILABLE_IN_ALL
GtkSorter * gtk_column_view_column_get_sorter (GtkColumnViewColumn *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_column_view_column_set_visible (GtkColumnViewColumn *self,
+ gboolean visible);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_column_view_column_get_visible (GtkColumnViewColumn *self);
+
G_END_DECLS
#endif /* __GTK_COLUMN_VIEW_COLUMN_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]