[libdazzle] multi-paned: add helper to get at x,y point



commit 1e223a0d55bd97b1ab98048a2212ec9dd45ebbb5
Author: Christian Hergert <chergert redhat com>
Date:   Wed Dec 13 01:32:33 2017 -0800

    multi-paned: add helper to get at x,y point
    
    This is useful so that we can find a widget under a point, such as when
    doing DnD.

 src/widgets/dzl-multi-paned.c |   50 +++++++++++++++++++++++++++++++++++++++++
 src/widgets/dzl-multi-paned.h |    4 +++
 2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/widgets/dzl-multi-paned.c b/src/widgets/dzl-multi-paned.c
index ca040de..fcc8976 100644
--- a/src/widgets/dzl-multi-paned.c
+++ b/src/widgets/dzl-multi-paned.c
@@ -2189,3 +2189,53 @@ dzl_multi_paned_get_nth_child (DzlMultiPaned *self,
 
   return g_array_index (priv->children, DzlMultiPanedChild, nth).widget;
 }
+
+/**
+ * dzl_multi_paned_get_at_point:
+ * @self: a #DzlMultiPaned
+ * @x: x coordinate
+ * @y: y coordinate
+ *
+ * Locates the widget at position x,y within widget.
+ *
+ * @x and @y should be relative to @self.
+ *
+ * Returns: (transfer none) (nullable): a #GtkWidget or %NULL
+ *
+ * Since: 3.28
+ */
+GtkWidget *
+dzl_multi_paned_get_at_point (DzlMultiPaned *self,
+                              gint           x,
+                              gint           y)
+{
+  DzlMultiPanedPrivate *priv = dzl_multi_paned_get_instance_private (self);
+  GtkAllocation alloc;
+
+  g_return_val_if_fail (DZL_IS_MULTI_PANED (self), NULL);
+
+  gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
+
+  if (IS_HORIZONTAL (priv->orientation))
+    {
+      for (guint i = 0; i < priv->children->len; i++)
+        {
+          const DzlMultiPanedChild *child = &g_array_index (priv->children, DzlMultiPanedChild, i);
+
+          if (x >= child->alloc.x && x < (child->alloc.x + child->alloc.width))
+            return child->widget;
+        }
+    }
+  else
+    {
+      for (guint i = 0; i < priv->children->len; i++)
+        {
+          const DzlMultiPanedChild *child = &g_array_index (priv->children, DzlMultiPanedChild, i);
+
+          if (y >= child->alloc.y && y < (child->alloc.y + child->alloc.height))
+            return child->widget;
+        }
+    }
+
+  return NULL;
+}
diff --git a/src/widgets/dzl-multi-paned.h b/src/widgets/dzl-multi-paned.h
index 5a1d148..8303a81 100644
--- a/src/widgets/dzl-multi-paned.h
+++ b/src/widgets/dzl-multi-paned.h
@@ -60,6 +60,10 @@ guint      dzl_multi_paned_get_n_children (DzlMultiPaned *self);
 DZL_AVAILABLE_IN_ALL
 GtkWidget *dzl_multi_paned_get_nth_child  (DzlMultiPaned *self,
                                            guint          nth);
+DZL_AVAILABLE_IN_3_28
+GtkWidget *dzl_multi_paned_get_at_point   (DzlMultiPaned *self,
+                                           gint           x,
+                                           gint           y);
 
 G_END_DECLS
 


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