[gtk/wip/antoniof/columnview-rtl] columnview: Invert columns on RTL




commit 91e6f8e4b9d504ead3cee50fe6f763ac71d7f0b0
Author: António Fernandes <antoniof gnome org>
Date:   Fri Sep 2 15:44:59 2022 +0100

    columnview: Invert columns on RTL
    
    Respect text direction.
    
    Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2302

 gtk/gtkcolumnview.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index d16a4373b0..c46b7d8309 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -376,17 +376,24 @@ static int
 gtk_column_view_allocate_columns (GtkColumnView *self,
                                   int            width)
 {
+  gboolean rtl;
   guint i, n;
-  int x;
+  int total_width, x;
   GtkRequestedSize *sizes;
 
+  rtl = gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL;
+
   n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
 
   sizes = g_newa (GtkRequestedSize, n);
 
   gtk_column_view_distribute_width (self, width, sizes);
 
-  x = 0;
+  total_width = 0;
+  for (i = 0; i < n; i++)
+    total_width += sizes[i].minimum_size;
+
+  x = rtl ? total_width : 0;
   for (i = 0; i < n; i++)
     {
       GtkColumnViewColumn *column;
@@ -397,17 +404,21 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
         {
           col_size = sizes[i].minimum_size;
 
+          if (rtl)
+            x -= col_size;
+
           gtk_column_view_column_allocate (column, x, col_size);
           if (self->in_column_reorder && i == self->drag_pos)
             gtk_column_view_column_set_header_position (column, self->drag_x);
 
-          x += col_size;
+          if (!rtl)
+            x += col_size;
         }
 
       g_object_unref (column);
     }
 
-  return x;
+  return total_width;
 }
 
 static void


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