popover: Support vertical aligment
authorMatthias Clasen <mclasen@redhat.com>
Thu, 5 Sep 2019 19:29:19 +0000 (15:29 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 8 Sep 2019 23:02:06 +0000 (19:02 -0400)
We already support horizontal alignment, and
we should do the same for vertical alignment.

gtk/gtkpopover.c

index 031e606c4c1797d8355e472d5cf37bb6b3ee7833..3f487a1172e9895326c664256996e3794a9749a2 100644 (file)
@@ -246,14 +246,50 @@ move_to_rect (GtkPopover *popover)
   switch (priv->position)
     {
     case GTK_POS_LEFT:
-      parent_anchor = GDK_GRAVITY_WEST;
-      surface_anchor = GDK_GRAVITY_EAST;
+      switch (gtk_widget_get_valign (GTK_WIDGET (popover)))
+        {
+        case GTK_ALIGN_START:
+          parent_anchor = GDK_GRAVITY_NORTH_WEST;
+          surface_anchor = GDK_GRAVITY_NORTH_EAST;
+          break;
+
+        case GTK_ALIGN_END:
+          parent_anchor = GDK_GRAVITY_SOUTH_WEST;
+          surface_anchor = GDK_GRAVITY_SOUTH_EAST;
+          break;
+
+        case GTK_ALIGN_FILL:
+        case GTK_ALIGN_CENTER:
+        case GTK_ALIGN_BASELINE:
+        default:
+          parent_anchor = GDK_GRAVITY_WEST;
+          surface_anchor = GDK_GRAVITY_EAST;
+          break;
+        }
       anchor_hints = GDK_ANCHOR_FLIP_X | GDK_ANCHOR_SLIDE_Y;
       break;
 
     case GTK_POS_RIGHT:
-      parent_anchor = GDK_GRAVITY_EAST;
-      surface_anchor = GDK_GRAVITY_WEST;
+      switch (gtk_widget_get_valign (GTK_WIDGET (popover)))
+        {
+        case GTK_ALIGN_START:
+          parent_anchor = GDK_GRAVITY_NORTH_EAST;
+          surface_anchor = GDK_GRAVITY_NORTH_WEST;
+          break;
+
+        case GTK_ALIGN_END:
+          parent_anchor = GDK_GRAVITY_SOUTH_EAST;
+          surface_anchor = GDK_GRAVITY_SOUTH_WEST;
+          break;
+
+        case GTK_ALIGN_FILL:
+        case GTK_ALIGN_CENTER:
+        case GTK_ALIGN_BASELINE:
+        default:
+          parent_anchor = GDK_GRAVITY_EAST;
+          surface_anchor = GDK_GRAVITY_WEST;
+          break;
+        }
       anchor_hints = GDK_ANCHOR_FLIP_X | GDK_ANCHOR_SLIDE_Y;
       break;