[gtk+/gtk-3-20] box gadget: allow reversing alignments



commit fc04d6613a6a2c994b151f7704693417d7a2a794
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 28 21:27:02 2016 -0400

    box gadget: allow reversing alignments
    
    In RTL, we want to interpret GTK_ALIGN_START and _END
    in the opposite way. Since we don't give gadgets a text
    direction, just allow setting an align_reverse flag
    to the box gadget.

 gtk/gtkboxgadget.c        |   34 ++++++++++++++++++++++++++++++----
 gtk/gtkboxgadgetprivate.h |    2 ++
 2 files changed, 32 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkboxgadget.c b/gtk/gtkboxgadget.c
index 6533b6e..e8198d7 100644
--- a/gtk/gtkboxgadget.c
+++ b/gtk/gtkboxgadget.c
@@ -38,9 +38,10 @@ struct _GtkBoxGadgetPrivate {
   GtkOrientation orientation;
   GArray *children;
 
-  guint draw_focus : 1;
-  guint draw_reverse : 1;
+  guint draw_focus       : 1;
+  guint draw_reverse     : 1;
   guint allocate_reverse : 1;
+  guint align_reverse    : 1;
 };
 
 typedef gboolean (* ComputeExpandFunc) (GObject *object, GtkOrientation orientation);
@@ -84,6 +85,21 @@ gtk_box_gadget_child_get_align (GtkBoxGadget      *gadget,
   return align;
 }
 
+static GtkAlign
+effective_align (GtkAlign align,
+                 gboolean reverse)
+{
+  switch (align)
+    {
+    case GTK_ALIGN_START:
+      return reverse ? GTK_ALIGN_END : GTK_ALIGN_START;
+    case GTK_ALIGN_END:
+      return reverse ? GTK_ALIGN_START : GTK_ALIGN_END;
+    default:
+      return align;
+    }
+}
+
 static void
 gtk_box_gadget_measure_child (GObject        *child,
                               GtkOrientation  orientation,
@@ -304,6 +320,7 @@ gtk_box_gadget_allocate_child (GObject        *child,
                                              allocation->width,
                                              &minimum, &natural,
                                              &minimum_baseline, &natural_baseline);
+
           switch (child_align)
             {
             case GTK_ALIGN_FILL:
@@ -407,7 +424,7 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
           child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
           gtk_box_gadget_allocate_child (child->object,
                                          priv->orientation,
-                                         child_align,
+                                         effective_align (child_align, priv->align_reverse),
                                          &child_allocation,
                                          baseline,
                                          &child_clip);
@@ -441,7 +458,7 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
           child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
           gtk_box_gadget_allocate_child (child->object,
                                          priv->orientation,
-                                         child_align,
+                                         effective_align (child_align, priv->align_reverse),
                                          &child_allocation,
                                          -1,
                                          &child_clip);
@@ -595,6 +612,15 @@ gtk_box_gadget_set_allocate_reverse (GtkBoxGadget *gadget,
   priv->allocate_reverse = allocate_reverse;
 }
 
+void
+gtk_box_gadget_set_align_reverse (GtkBoxGadget *gadget,
+                                  gboolean      align_reverse)
+{
+  GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
+
+  priv->align_reverse = align_reverse;
+}
+
 static GtkCssNode *
 get_css_node (GObject *child)
 {
diff --git a/gtk/gtkboxgadgetprivate.h b/gtk/gtkboxgadgetprivate.h
index 008fd16..ce1a667 100644
--- a/gtk/gtkboxgadgetprivate.h
+++ b/gtk/gtkboxgadgetprivate.h
@@ -63,6 +63,8 @@ void                    gtk_box_gadget_set_draw_reverse         (GtkBoxGadget
 void                    gtk_box_gadget_set_allocate_reverse     (GtkBoxGadget           *gadget,
                                                                  gboolean                allocate_reverse);
 
+void                    gtk_box_gadget_set_align_reverse        (GtkBoxGadget           *gadget,
+                                                                 gboolean                align_reverse);
 void                    gtk_box_gadget_insert_widget            (GtkBoxGadget           *gadget,
                                                                  int                     pos,
                                                                  GtkWidget              *widget);


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