[gtk/wip/otte/listview: 934/1040] gridview: Add API for setting number of columns
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 934/1040] gridview: Add API for setting number of columns
- Date: Sun, 2 Feb 2020 23:41:08 +0000 (UTC)
commit 26dbc09b9432e101e6f79ade82aeba6ffe492bca
Author: Benjamin Otte <otte redhat com>
Date: Mon Jan 28 02:24:34 2019 +0100
gridview: Add API for setting number of columns
The API isn't used yet.
docs/reference/gtk/gtk4-sections.txt | 4 +
gtk/gtkgridview.c | 137 +++++++++++++++++++++++++++++++++++
gtk/gtkgridview.h | 10 +++
3 files changed, 151 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 5bc8efef70..c6e38c66ea 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -552,6 +552,10 @@ GtkGridView
gtk_grid_view_new
gtk_grid_view_set_model
gtk_grid_view_get_model
+gtk_grid_view_set_max_columns
+gtk_grid_view_get_max_columns
+gtk_grid_view_set_min_columns
+gtk_grid_view_get_min_columns
<SUBSECTION Standard>
GTK_GRID_VIEW
GTK_GRID_VIEW_CLASS
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index 9c37c6eefb..7d17a9fcb3 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -24,6 +24,8 @@
#include "gtkintl.h"
#include "gtkprivate.h"
+#define DEFAULT_MAX_COLUMNS (7)
+
/**
* SECTION:gtkgridview
* @title: GtkGridView
@@ -38,11 +40,15 @@ struct _GtkGridView
GtkWidget parent_instance;
GListModel *model;
+ guint min_columns;
+ guint max_columns;
};
enum
{
PROP_0,
+ PROP_MAX_COLUMNS,
+ PROP_MIN_COLUMNS,
PROP_MODEL,
N_PROPS
@@ -129,6 +135,14 @@ gtk_grid_view_get_property (GObject *object,
switch (property_id)
{
+ case PROP_MAX_COLUMNS:
+ g_value_set_uint (value, self->max_columns);
+ break;
+
+ case PROP_MIN_COLUMNS:
+ g_value_set_uint (value, self->min_columns);
+ break;
+
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
@@ -149,6 +163,14 @@ gtk_grid_view_set_property (GObject *object,
switch (property_id)
{
+ case PROP_MAX_COLUMNS:
+ gtk_grid_view_set_max_columns (self, g_value_get_uint (value));
+ break;
+
+ case PROP_MIN_COLUMNS:
+ gtk_grid_view_set_min_columns (self, g_value_get_uint (value));
+ break;
+
case PROP_MODEL:
gtk_grid_view_set_model (self, g_value_get_object (value));
break;
@@ -172,6 +194,33 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
gobject_class->get_property = gtk_grid_view_get_property;
gobject_class->set_property = gtk_grid_view_set_property;
+ /**
+ * GtkGridView:max-columns:
+ *
+ * Maximum number of columns per row
+ *
+ * If this number is smaller than GtkGridView:min-columns, that value
+ * is used instead.
+ */
+ properties[PROP_MAX_COLUMNS] =
+ g_param_spec_uint ("max-columns",
+ P_("Max columns"),
+ P_("Maximum number of columns per row"),
+ 1, G_MAXUINT, DEFAULT_MAX_COLUMNS,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * GtkGridView:min-columns:
+ *
+ * Minimum number of columns per row
+ */
+ properties[PROP_MIN_COLUMNS] =
+ g_param_spec_uint ("min-columns",
+ P_("Min columns"),
+ P_("Minimum number of columns per row"),
+ 1, G_MAXUINT, 1,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
/**
* GtkGridView:model:
*
@@ -192,6 +241,8 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
static void
gtk_grid_view_init (GtkGridView *self)
{
+ self->min_columns = 1;
+ self->max_columns = DEFAULT_MAX_COLUMNS;
}
/**
@@ -258,3 +309,89 @@ gtk_grid_view_set_model (GtkGridView *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}
+/**
+ * gtk_grid_view_get_max_columns:
+ * @self: a #GtkGridView
+ *
+ * Gets the maximum number of columns that the grid will use.
+ *
+ * Returns: The maximum number of columns
+ **/
+guint
+gtk_grid_view_get_max_columns (GtkGridView *self)
+{
+ g_return_val_if_fail (GTK_IS_GRID_VIEW (self), DEFAULT_MAX_COLUMNS);
+
+ return self->max_columns;
+}
+
+/**
+ * gtk_grid_view_set_max_columns:
+ * @self: a #GtkGridView
+ * @max_columns: The maximum number of columns
+ *
+ * Sets the maximum number of columns to use. This number must be at least 1.
+ *
+ * If @max_columns is smaller than the minimum set via
+ * gtk_grid_view_set_min_columns(), that value is used instead.
+ **/
+void
+gtk_grid_view_set_max_columns (GtkGridView *self,
+ guint max_columns)
+{
+ g_return_if_fail (GTK_IS_GRID_VIEW (self));
+ g_return_if_fail (max_columns > 0);
+
+ if (self->max_columns == max_columns)
+ return;
+
+ self->max_columns = max_columns;
+
+ gtk_widget_queue_resize (GTK_WIDGET (self));
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MAX_COLUMNS]);
+}
+
+/**
+ * gtk_grid_view_get_min_columns:
+ * @self: a #GtkGridView
+ *
+ * Gets the minimum number of columns that the grid will use.
+ *
+ * Returns: The minimum number of columns
+ **/
+guint
+gtk_grid_view_get_min_columns (GtkGridView *self)
+{
+ g_return_val_if_fail (GTK_IS_GRID_VIEW (self), 1);
+
+ return self->min_columns;
+}
+
+/**
+ * gtk_grid_view_set_min_columns:
+ * @self: a #GtkGridView
+ * @min_columns: The minimum number of columns
+ *
+ * Sets the minimum number of columns to use. This number must be at least 1.
+ *
+ * If @min_columns is smaller than the minimum set via
+ * gtk_grid_view_set_max_columns(), that value is ignored.
+ **/
+void
+gtk_grid_view_set_min_columns (GtkGridView *self,
+ guint min_columns)
+{
+ g_return_if_fail (GTK_IS_GRID_VIEW (self));
+ g_return_if_fail (min_columns > 0);
+
+ if (self->min_columns == min_columns)
+ return;
+
+ self->min_columns = min_columns;
+
+ gtk_widget_queue_resize (GTK_WIDGET (self));
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MIN_COLUMNS]);
+}
+
diff --git a/gtk/gtkgridview.h b/gtk/gtkgridview.h
index 0462c960ce..3bdd6505ba 100644
--- a/gtk/gtkgridview.h
+++ b/gtk/gtkgridview.h
@@ -41,6 +41,16 @@ GListModel * gtk_grid_view_get_model (GtkGridView
GDK_AVAILABLE_IN_ALL
void gtk_grid_view_set_model (GtkGridView *self,
GListModel *model);
+GDK_AVAILABLE_IN_ALL
+guint gtk_grid_view_get_min_columns (GtkGridView *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_grid_view_set_min_columns (GtkGridView *self,
+ guint min_columns);
+GDK_AVAILABLE_IN_ALL
+guint gtk_grid_view_get_max_columns (GtkGridView *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_grid_view_set_max_columns (GtkGridView *self,
+ guint max_columns);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]