[gtk/wip/ebassi/grid-layout: 2/4] Add convenience function for querying a child of GtkGrid



commit faafd23225cc2f5e5e58561efedc086db29a3524
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 4 22:41:19 2019 +0100

    Add convenience function for querying a child of GtkGrid
    
    Getting the layout manager instance out of GtkGrid, and then querying
    all layout properties can be tedious, especially for code that was
    usually calling gtk_container_child_get().
    
    To replace that, we can add a simple query function that returns the two
    attach points and the spans.

 gtk/gtkgrid.c | 38 ++++++++++++++++++++++++++++++++++++++
 gtk/gtkgrid.h |  7 +++++++
 2 files changed, 45 insertions(+)
---
diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c
index 9d4e472559..ce67b00609 100644
--- a/gtk/gtkgrid.c
+++ b/gtk/gtkgrid.c
@@ -1075,3 +1075,41 @@ gtk_grid_get_baseline_row (GtkGrid *grid)
 
   return gtk_grid_layout_get_baseline_row (GTK_GRID_LAYOUT (priv->layout_manager));
 }
+
+/**
+ * gtk_grid_query_child:
+ * @grid: a #GtkGrid
+ * @child: a #GtkWidget child of @grid
+ * @left: (out): the column used to attach the left side of @child
+ * @top: (out): the row used to attach the top side of @child
+ * @width: (out): the number of columns @child spans
+ * @height: (out): the number of rows @child spans
+ *
+ * Queries the attach points and spans of @child inside the given #GtkGrid.
+ */
+void
+gtk_grid_query_child (GtkGrid   *grid,
+                      GtkWidget *child,
+                      gint      *left,
+                      gint      *top,
+                      gint      *width,
+                      gint      *height)
+{
+  GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
+  GtkGridLayoutChild *grid_child;
+
+  g_return_if_fail (GTK_IS_GRID (grid));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  g_return_if_fail (_gtk_widget_get_parent (child) == (GtkWidget *) grid);
+
+  grid_child = GTK_GRID_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (priv->layout_manager, child));
+
+  if (left != NULL)
+    *left = gtk_grid_layout_child_get_left_attach (grid_child);
+  if (top != NULL)
+    *top = gtk_grid_layout_child_get_top_attach (grid_child);
+  if (width != NULL)
+    *width = gtk_grid_layout_child_get_column_span (grid_child);
+  if (height != NULL)
+    *height = gtk_grid_layout_child_get_row_span (grid_child);
+}
diff --git a/gtk/gtkgrid.h b/gtk/gtkgrid.h
index f40ed7e862..2ac97cba4e 100644
--- a/gtk/gtkgrid.h
+++ b/gtk/gtkgrid.h
@@ -137,6 +137,13 @@ void       gtk_grid_set_baseline_row       (GtkGrid         *grid,
 GDK_AVAILABLE_IN_ALL
 gint       gtk_grid_get_baseline_row       (GtkGrid         *grid);
 
+GDK_AVAILABLE_IN_ALL
+void       gtk_grid_query_child            (GtkGrid         *grid,
+                                            GtkWidget       *child,
+                                            gint            *left,
+                                            gint            *top,
+                                            gint            *width,
+                                            gint            *height);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]