[gtk+] box gadget: Add a way to allocate in reverse



commit c581259e06df735057fa3d606ae0b80bdb9f6feb
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Mar 3 21:24:20 2016 -0500

    box gadget: Add a way to allocate in reverse
    
    This is needed to preserve expected allocation behavior
    in rtl mode.

 gtk/gtkboxgadget.c        |   36 ++++++++++++++++++++++++++++++------
 gtk/gtkboxgadgetprivate.h |    2 ++
 2 files changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkboxgadget.c b/gtk/gtkboxgadget.c
index 2380236..6533b6e 100644
--- a/gtk/gtkboxgadget.c
+++ b/gtk/gtkboxgadget.c
@@ -40,6 +40,7 @@ struct _GtkBoxGadgetPrivate {
 
   guint draw_focus : 1;
   guint draw_reverse : 1;
+  guint allocate_reverse : 1;
 };
 
 typedef gboolean (* ComputeExpandFunc) (GObject *object, GtkOrientation orientation);
@@ -390,12 +391,18 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
     {
       gtk_box_gadget_distribute (GTK_BOX_GADGET (gadget), allocation->height, allocation->width, sizes);
 
+      if (priv->allocate_reverse)
+        child_allocation.x = allocation->x + allocation->width;
+
       for (i = 0; i < priv->children->len; i++)
         {
-          GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
-          child_allocation.width = sizes[i].minimum_size;
+          guint idx = priv->allocate_reverse ? priv->children->len - 1 - i : i;
+          GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, idx);
+          child_allocation.width = sizes[idx].minimum_size;
           child_allocation.height = allocation->height;
           child_allocation.y = allocation->y;
+          if (priv->allocate_reverse)
+            child_allocation.x -= child_allocation.width;
 
           child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
           gtk_box_gadget_allocate_child (child->object,
@@ -410,19 +417,26 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
           else
             gdk_rectangle_union (out_clip, &child_clip, out_clip);
 
-          child_allocation.x += sizes[i].minimum_size;
+          if (!priv->allocate_reverse)
+            child_allocation.x += sizes[idx].minimum_size;
         }
     }
   else
     {
       gtk_box_gadget_distribute (GTK_BOX_GADGET (gadget), allocation->width, allocation->height, sizes);
 
+      if (priv->allocate_reverse)
+        child_allocation.y = allocation->y + allocation->height;
+
       for (i = 0 ; i < priv->children->len; i++)
         {
-          GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
-          child_allocation.height = sizes[i].minimum_size;
+          guint idx = priv->allocate_reverse ? priv->children->len - 1 - i : i;
+          GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, idx);
+          child_allocation.height = sizes[idx].minimum_size;
           child_allocation.width = allocation->width;
           child_allocation.x = allocation->x;
+          if (priv->allocate_reverse)
+            child_allocation.y -= child_allocation.height;
 
           child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
           gtk_box_gadget_allocate_child (child->object,
@@ -437,7 +451,8 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
           else
             gdk_rectangle_union (out_clip, &child_clip, out_clip);
 
-          child_allocation.y += sizes[i].minimum_size;
+          if (!priv->allocate_reverse)
+            child_allocation.y += sizes[idx].minimum_size;
         }
     }
 }
@@ -571,6 +586,15 @@ gtk_box_gadget_set_draw_reverse (GtkBoxGadget *gadget,
   priv->draw_reverse = draw_reverse;
 }
 
+void
+gtk_box_gadget_set_allocate_reverse (GtkBoxGadget *gadget,
+                                     gboolean      allocate_reverse)
+{
+  GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
+
+  priv->allocate_reverse = allocate_reverse;
+}
+
 static GtkCssNode *
 get_css_node (GObject *child)
 {
diff --git a/gtk/gtkboxgadgetprivate.h b/gtk/gtkboxgadgetprivate.h
index c970a3b..008fd16 100644
--- a/gtk/gtkboxgadgetprivate.h
+++ b/gtk/gtkboxgadgetprivate.h
@@ -60,6 +60,8 @@ void                    gtk_box_gadget_set_draw_focus           (GtkBoxGadget
                                                                  gboolean                draw_focus);
 void                    gtk_box_gadget_set_draw_reverse         (GtkBoxGadget           *gadget,
                                                                  gboolean                draw_reverse);
+void                    gtk_box_gadget_set_allocate_reverse     (GtkBoxGadget           *gadget,
+                                                                 gboolean                allocate_reverse);
 
 void                    gtk_box_gadget_insert_widget            (GtkBoxGadget           *gadget,
                                                                  int                     pos,


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