[gtk/adaptive-emojichooser: 1/3] emojichooser: Make keynav work with != 7 columns




commit 23ea5104d24ad4ef2257f417cb141ef7bca9b549
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 21 22:44:28 2020 -0500

    emojichooser: Make keynav work with != 7 columns
    
    The number of 7 columns was hardcoded in a few places
    related to keynav across sections. The flowbox does
    not have an api for it, but we can find out anyway
    how many columns there are.

 gtk/gtkemojichooser.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c
index 6625599942..2f5d223ccd 100644
--- a/gtk/gtkemojichooser.c
+++ b/gtk/gtkemojichooser.c
@@ -1081,16 +1081,35 @@ keynav_failed (GtkWidget        *box,
                GtkEmojiChooser  *chooser)
 {
   EmojiSection *next;
-  GtkWidget *focus; 
+  GtkWidget *focus;
   GtkWidget *child;
   GtkWidget *sibling;
   int i;
   int column;
+  int n_columns = 7;
+  int child_x;
 
   focus = gtk_root_get_focus (gtk_widget_get_root (box));
   if (focus == NULL)
     return FALSE;
 
+  /* determine the number of columns */
+  child_x = -1;
+  for (i = 0; i < 20; i++)
+    {
+      GtkAllocation alloc;
+
+      gtk_widget_get_allocation (GTK_WIDGET (gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (box), i)),
+                                 &alloc);
+      if (alloc.x > child_x)
+        child_x = alloc.x;
+      else
+        {
+          n_columns = i;
+          break;
+        }
+    }
+
   child = gtk_widget_get_ancestor (focus, GTK_TYPE_EMOJI_CHOOSER_CHILD);
 
   i = 0;
@@ -1099,7 +1118,7 @@ keynav_failed (GtkWidget        *box,
        sibling = gtk_widget_get_next_sibling (sibling))
     i++;
 
-  column = i % 7;
+  column = i % n_columns;
 
   if (direction == GTK_DIR_DOWN)
     {
@@ -1131,7 +1150,7 @@ keynav_failed (GtkWidget        *box,
            sibling;
            sibling = gtk_widget_get_next_sibling (sibling), i++)
         {
-          if ((i % 7) == column)
+          if ((i % n_columns) == column)
             child = sibling;
         }
       if (child)


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