[epiphany] ephy-notebook: Set halign depending on notebook position



commit 1c655576082860b0fcbcbec7a381228e1f7f1938
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Tue Feb 26 21:39:08 2019 +0100

    ephy-notebook: Set halign depending on notebook position
    
    Horizontal alignment is now set depending on notebook position. Left/Right are set to FILL and bottom/top 
to CENTER.
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/456

 src/ephy-notebook.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/src/ephy-notebook.c b/src/ephy-notebook.c
index c51d78678..90aa30b2a 100644
--- a/src/ephy-notebook.c
+++ b/src/ephy-notebook.c
@@ -417,12 +417,43 @@ ephy_settings_get_tabs_bar_position (void)
   }
 }
 
+static void
+box_set_halign (GtkWidget       *box,
+                GtkPositionType  type)
+{
+  switch (type) {
+    case GTK_POS_LEFT:
+    case GTK_POS_RIGHT:
+      gtk_widget_set_halign (box, GTK_ALIGN_FILL);
+      break;
+    case GTK_POS_TOP:
+    case GTK_POS_BOTTOM:
+      gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
+      break;
+    default:
+      break;
+  }
+}
+
 static void
 position_changed_cb (GSettings    *settings,
                      char         *key,
                      EphyNotebook *nb)
 {
-  gtk_notebook_set_tab_pos (GTK_NOTEBOOK (nb), ephy_settings_get_tabs_bar_position ());
+  GtkPositionType type = ephy_settings_get_tabs_bar_position ();
+  gint pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb));
+  gint i;
+
+  /* Update halign of all notebook label widgets (sub-box) */
+  for (i = 0; i < pages; i++) {
+    GtkWidget *child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (nb), i);
+    GtkWidget *label_widget = gtk_notebook_get_tab_label (GTK_NOTEBOOK (nb), child);
+    GtkWidget *box = gtk_container_get_children (GTK_CONTAINER (label_widget))->data;
+
+    box_set_halign (box, type);
+  }
+
+  gtk_notebook_set_tab_pos (GTK_NOTEBOOK (nb), type);
 }
 
 static void
@@ -711,6 +742,7 @@ build_tab_label (EphyNotebook *nb, EphyEmbed *embed)
   GtkWidget *hbox, *label, *close_button, *image, *spinner, *icon, *speaker_icon;
   GtkWidget *box;
   EphyWebView *view;
+  GtkPositionType type = ephy_settings_get_tabs_bar_position ();
 
   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
   gtk_widget_show (box);
@@ -719,7 +751,7 @@ build_tab_label (EphyNotebook *nb, EphyEmbed *embed)
    * equal amount of space around the label */
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   gtk_widget_show (hbox);
-  gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
+  box_set_halign (hbox, type);
   gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, TRUE, 0);
 
   /* setup load feedback */


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