Commit b2f87211 authored by Matthias Clasen's avatar Matthias Clasen

Make GtkWidget::halign RTL-save

This commit makes GTK_ALIGN_START/_END pay attention to
the text direction when used in horizontal context.

This is how similar parameters in GtkMisc and GtkAlignment work,
and is generally expected of GTK+ positioning parameters. And this
is new GTK+ 3 api, so it is basically still unused at this point.

If explicit right/left turn out to be needed at some point, we
can expand the enumeration with new values.
parent 9334f177
......@@ -63,6 +63,9 @@ G_BEGIN_DECLS
* you have for example a 16x16 icon inside a 32x32 space, the icon
* could be scaled and stretched, it could be centered, or it could be
* positioned to one side of the space.
*
* Note that in horizontal context @GTK_ALIGN_START and @GTK_ALIGN_END
* are interpreted relative to text direction.
*/
typedef enum
{
......
......@@ -5115,11 +5115,27 @@ gtk_widget_real_size_allocate (GtkWidget *widget,
}
}
/* translate initial/final into start/end */
static GtkAlign
effective_align (GtkAlign align,
GtkTextDirection direction)
{
switch (align)
{
case GTK_ALIGN_START:
return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
case GTK_ALIGN_END:
return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
default:
return align;
}
}
static void
adjust_for_align(GtkAlign align,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size)
adjust_for_align (GtkAlign align,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size)
{
switch (align)
{
......@@ -5177,18 +5193,18 @@ gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
{
adjust_for_margin (aux_info->margin.left,
aux_info->margin.right,
minimum_size, natural_size,
allocated_pos, allocated_size);
adjust_for_align (aux_info->halign,
minimum_size, natural_size,
allocated_pos, allocated_size);
adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
natural_size, allocated_pos, allocated_size);
}
else
{
adjust_for_margin (aux_info->margin.top,
aux_info->margin.bottom,
minimum_size, natural_size,
allocated_pos, allocated_size);
adjust_for_align (aux_info->valign,
minimum_size, natural_size,
allocated_pos, allocated_size);
adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
natural_size, allocated_pos, allocated_size);
}
}
......
......@@ -436,6 +436,9 @@ main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
if (g_getenv ("RTL"))
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
open_test_window ();
open_control_window ();
open_alignment_window ();
......
......@@ -200,6 +200,9 @@ main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
if (g_getenv ("RTL"))
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
create_box_window ();
create_table_window ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment