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.
This commit is contained in:
Matthias Clasen 2016-04-28 21:27:02 -04:00
parent 71c1e86e62
commit 2919e344ca
2 changed files with 32 additions and 4 deletions

View File

@ -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)
{

View File

@ -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);