[gtk+/wip/csoriano/pathbar-prototype: 176/176] back



commit 1fe124ce40a9ee03b95a95ee3a70f6569353855f
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Oct 27 19:11:37 2015 +0100

    back

 gtk/gtkpathbar.c                         |  155 +++++++++++++++++++++++++++---
 gtk/theme/Adwaita/_common.scss           |    5 +-
 gtk/theme/Adwaita/gtk-contained-dark.css |   23 ++---
 gtk/theme/Adwaita/gtk-contained.css      |   23 ++---
 gtk/ui/gtkpathbar.ui                     |    1 +
 5 files changed, 166 insertions(+), 41 deletions(-)
---
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index e5de066..035515e 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -69,6 +69,7 @@ create_separator ()
 
   label = gtk_label_new ("/");
   gtk_widget_set_sensitive (label, FALSE);
+  gtk_widget_show (label);
 
   return label;
 }
@@ -83,6 +84,7 @@ create_path_chunk (GtkPathBar  *self,
   button = gtk_toggle_button_new_with_label (label);
   g_signal_connect_swapped (button, "clicked",
                             G_CALLBACK (on_path_chunk_button_clicked), self);
+  gtk_widget_show (button);
   style = gtk_widget_get_style_context (button);
   gtk_style_context_add_class (style, "image-button");
   gtk_style_context_add_class (style, "flat");
@@ -95,19 +97,20 @@ void
 gtk_path_bar_set_path (GtkPathBar  *self,
                        const gchar *path)
 {
+  GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
   gchar ** splitted_path;
 
   g_return_if_fail (GTK_IS_PATH_BAR (self));
 
-  gtk_container_foreach (GTK_CONTAINER (self), (GtkCallback) gtk_widget_destroy, NULL);
+  gtk_container_foreach (GTK_CONTAINER (priv->path_box), (GtkCallback) gtk_widget_destroy, NULL);
 
   splitted_path = g_strsplit (path, "/", -1);
   for (guint i = 0; i < g_strv_length (splitted_path); i++)
     {
       if (g_strcmp0 (splitted_path[i], "") == 0)
         continue;
-      gtk_container_add (GTK_CONTAINER (self), create_path_chunk (self, splitted_path[i]));
-      gtk_container_add (GTK_CONTAINER (self), create_separator ());
+      gtk_container_add (GTK_CONTAINER (priv->path_box), create_path_chunk (self, splitted_path[i]));
+      gtk_container_add (GTK_CONTAINER (priv->path_box), create_separator ());
     }
 
   g_object_notify_by_pspec (G_OBJECT (self), path_bar_properties[PROP_PATH]);
@@ -169,26 +172,149 @@ gtk_path_bar_set_property (GObject      *object,
 }
 
 static void
-get_preferred_width_for_height (GtkWidget *self,
-                                gint       for_height,
-                                gint      *min_width,
-                                gint      *nat_width)
+get_path_preferred_width (GtkWidget *self,
+                          gint      *min_width,
+                          gint      *nat_width)
 {
+  GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
   GList *children;
   GList *l;
-  gint children_nat_width;
+  gint child_nat_width;
+  gint child_min_width;
 
-  children = gtk_container_get_children (GTK_CONTAINER (self));
-  children_nat_width = 0;
+  children = gtk_container_get_children (GTK_CONTAINER (priv->path_box));
   *min_width = 0;
   *nat_width = 0;
 
   for (l = children; l != NULL; l = l->next)
     {
-      gtk_widget_get_preferred_width (l->data, NULL, &children_nat_width);
-      *nat_width += children_nat_width;
+      gtk_widget_get_preferred_width (l->data, &child_min_width, &child_nat_width);
+      *min_width += child_min_width;
+      *nat_width += child_nat_width;
     }
-  g_print ("nat width %d\n", *nat_width);
+
+  g_print ("path nat width %d nat_width %d\n", *nat_width, *min_width);
+
+}
+
+static void
+get_preferred_width (GtkWidget *self,
+                     gint      *min_width,
+                     gint      *nat_width)
+{
+  GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+  gint child_nat_width;
+  gint child_min_width;
+
+  child_nat_width = 0;
+  *min_width = 0;
+  *nat_width = 0;
+
+  get_path_preferred_width (self, min_width, nat_width);
+
+  gtk_widget_get_preferred_width (priv->overflow_button, &child_min_width, NULL);
+  *min_width = MIN (child_min_width, *min_width);
+  g_print ("nat width %d nat_width %d\n", *nat_width, *min_width);
+}
+
+static void
+allocate_overflow_button (GtkWidget     *self,
+                          GtkAllocation *container_allocation,
+                          gint          *current_x_pos)
+{
+  GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+  gint overflow_button_min_width;
+  GtkAllocation child_allocation;
+  GtkTextDirection direction;
+
+  direction = gtk_widget_get_direction (self);
+  gtk_widget_get_preferred_width (priv->overflow_button, &overflow_button_min_width, NULL);
+  gtk_widget_set_child_visible (priv->overflow_button, TRUE);
+  child_allocation.y = container_allocation->y;
+  child_allocation.height = container_allocation->height;
+  child_allocation.width = overflow_button_min_width;
+  child_allocation.x = *current_x_pos;
+  gtk_widget_size_allocate (priv->overflow_button, &child_allocation);
+
+  if (direction == GTK_TEXT_DIR_LTR)
+    current_x_pos += overflow_button_min_width;
+  else
+    current_x_pos -= overflow_button_min_width;
+}
+
+static void
+size_allocate (GtkWidget     *self,
+               GtkAllocation *allocation)
+{
+  GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+  GdkWindow *internal_window;
+  gint child_min_width;
+  gint child_nat_width;
+  gint container_min_width;
+  gint container_nat_width;
+  gint path_min_width;
+  gint path_nat_width;
+  gint overflow_button_min_width;
+  gint current_x_pos;
+  GtkAllocation child_allocation;
+  GtkTextDirection direction;
+  gboolean allocate_more_children = TRUE;
+  gboolean overflow;
+  GList *children;
+  GList *l;
+
+  gtk_widget_set_allocation (self, allocation);
+
+  internal_window = gtk_widget_get_window (self);
+  if (internal_window)
+    gdk_window_move_resize (internal_window,
+                            allocation->x, allocation->y,
+                            allocation->width, allocation->height);
+
+  children = gtk_container_get_children (GTK_CONTAINER (priv->path_box));
+
+  if (g_list_length (children) == 0)
+    return;
+
+  get_path_preferred_width (self, &path_min_width, &path_nat_width);
+  overflow = allocation->width < path_min_width;
+  direction = gtk_widget_get_direction (self);
+  g_print ("text dir %d\n", direction);
+  current_x_pos = direction == GTK_TEXT_DIR_LTR ? allocation->x : allocation->width;
+
+  gtk_widget_get_preferred_width (priv->overflow_button, &overflow_button_min_width, NULL);
+  if (overflow && direction == GTK_TEXT_DIR_LTR)
+    allocate_overflow_button (self, allocation, &current_x_pos);
+
+  for (l = children; l != NULL; l = l->next)
+    {
+      gtk_widget_get_preferred_width (l->data, &child_min_width, &child_nat_width);
+      child_allocation.width = overflow ? child_min_width : child_nat_width;
+      child_allocation.y = allocation->y;
+      child_allocation.height = allocation->height;
+      g_print ("current x %d child alloc %d alloc %d\n", current_x_pos, child_allocation.width, 
allocation->width);
+      if (((direction == GTK_TEXT_DIR_LTR && current_x_pos + child_allocation.width < allocation->width) ||
+          (direction == GTK_TEXT_DIR_RTL && current_x_pos - child_allocation.width > allocation->x)) &&
+          allocate_more_children)
+        {
+          child_allocation.x = current_x_pos;
+          gtk_widget_set_child_visible (l->data, TRUE);
+          gtk_widget_size_allocate (l->data, &child_allocation);
+
+          if (direction == GTK_TEXT_DIR_LTR)
+            current_x_pos += child_allocation.width;
+          else
+            current_x_pos -= child_allocation.width;
+        }
+      else
+        {
+          gtk_widget_set_child_visible (l->data, FALSE);
+          allocate_more_children = FALSE;
+        }
+    }
+
+  if (overflow && direction == GTK_TEXT_DIR_RTL)
+    allocate_overflow_button (self, allocation, &current_x_pos);
 }
 
 static void
@@ -201,7 +327,8 @@ gtk_path_bar_class_init (GtkPathBarClass *klass)
   object_class->get_property = gtk_path_bar_get_property;
   object_class->set_property = gtk_path_bar_set_property;
 
-  widget_class->get_preferred_width_for_height = get_preferred_width_for_height;
+  widget_class->get_preferred_width = get_preferred_width;
+  widget_class->size_allocate = size_allocate;
 
   /**
    * GtkPlacesSidebar::populate-popup:
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index b2e6a50..df44d15 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -1241,7 +1241,7 @@ GtkComboBox {
  * Pathbars *
  ************/
 
-.path-bar .button.flat {
+path-bar .button.flat {
     background-image: none;
     border-radius: 0px;
     border-color: transparent;
@@ -1251,12 +1251,11 @@ GtkComboBox {
     padding: 3px 8px 4px;
 
     &:hover {
-      box-shadow: 0px 2px 0px mix($selected_bg_color, $selected_fg_color, 0.25);
+      box-shadow: 0px 2px 0px mix($selected_bg_color, $selected_fg_color, 75%);
     }
 
     &:checked {
       box-shadow: 0px 2px 0px $selected_bg_color;
-      color: $fg_color;
     }
 }
 
diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css
index 60b8afd..3bbbcaa 100644
--- a/gtk/theme/Adwaita/gtk-contained-dark.css
+++ b/gtk/theme/Adwaita/gtk-contained-dark.css
@@ -1825,9 +1825,9 @@ GtkComboBox {
 /************
  * Pathbars *
  ************/
-.path-bar .button.flat, .path-bar .sidebar-button.button, .path-bar .header-bar .titlebutton.button, 
.header-bar .path-bar .titlebutton.button,
-.path-bar .titlebar .titlebutton.button,
-.titlebar .path-bar .titlebutton.button {
+path-bar .button.flat, path-bar .sidebar-button.button, path-bar .header-bar .titlebutton.button, 
.header-bar path-bar .titlebutton.button,
+path-bar .titlebar .titlebutton.button,
+.titlebar path-bar .titlebutton.button {
   background-image: none;
   border-radius: 0px;
   border-color: transparent;
@@ -1835,15 +1835,14 @@ GtkComboBox {
   margin: 0px;
   opacity: 0.55;
   padding: 3px 8px 4px; }
-  .path-bar .button.flat:hover, .path-bar .sidebar-button.button:hover, .path-bar .header-bar 
.titlebutton.button:hover, .header-bar .path-bar .titlebutton.button:hover,
-  .path-bar .titlebar .titlebutton.button:hover,
-  .titlebar .path-bar .titlebutton.button:hover {
-    box-shadow: 0px 2px 0px #feffff; }
-  .path-bar .button.flat:checked, .path-bar .sidebar-button.button:checked, .path-bar .header-bar 
.titlebutton.button:checked, .header-bar .path-bar .titlebutton.button:checked,
-  .path-bar .titlebar .titlebutton.button:checked,
-  .titlebar .path-bar .titlebutton.button:checked {
-    box-shadow: 0px 2px 0px #215d9c;
-    color: #eeeeec; }
+  path-bar .button.flat:hover, path-bar .sidebar-button.button:hover, path-bar .header-bar 
.titlebutton.button:hover, .header-bar path-bar .titlebutton.button:hover,
+  path-bar .titlebar .titlebutton.button:hover,
+  .titlebar path-bar .titlebutton.button:hover {
+    box-shadow: 0px 2px 0px #5986b5; }
+  path-bar .button.flat:checked, path-bar .sidebar-button.button:checked, path-bar .header-bar 
.titlebutton.button:checked, .header-bar path-bar .titlebutton.button:checked,
+  path-bar .titlebar .titlebutton.button:checked,
+  .titlebar path-bar .titlebutton.button:checked {
+    box-shadow: 0px 2px 0px #215d9c; }
 
 /**************
  * Tree Views *
diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css
index dd3a733..c7ffa78 100644
--- a/gtk/theme/Adwaita/gtk-contained.css
+++ b/gtk/theme/Adwaita/gtk-contained.css
@@ -1825,9 +1825,9 @@ GtkComboBox {
 /************
  * Pathbars *
  ************/
-.path-bar .button.flat, .path-bar .sidebar-button.button, .path-bar .header-bar .titlebutton.button, 
.header-bar .path-bar .titlebutton.button,
-.path-bar .titlebar .titlebutton.button,
-.titlebar .path-bar .titlebutton.button {
+path-bar .button.flat, path-bar .sidebar-button.button, path-bar .header-bar .titlebutton.button, 
.header-bar path-bar .titlebutton.button,
+path-bar .titlebar .titlebutton.button,
+.titlebar path-bar .titlebutton.button {
   background-image: none;
   border-radius: 0px;
   border-color: transparent;
@@ -1835,15 +1835,14 @@ GtkComboBox {
   margin: 0px;
   opacity: 0.55;
   padding: 3px 8px 4px; }
-  .path-bar .button.flat:hover, .path-bar .sidebar-button.button:hover, .path-bar .header-bar 
.titlebutton.button:hover, .header-bar .path-bar .titlebutton.button:hover,
-  .path-bar .titlebar .titlebutton.button:hover,
-  .titlebar .path-bar .titlebutton.button:hover {
-    box-shadow: 0px 2px 0px white; }
-  .path-bar .button.flat:checked, .path-bar .sidebar-button.button:checked, .path-bar .header-bar 
.titlebutton.button:checked, .header-bar .path-bar .titlebutton.button:checked,
-  .path-bar .titlebar .titlebutton.button:checked,
-  .titlebar .path-bar .titlebutton.button:checked {
-    box-shadow: 0px 2px 0px #4a90d9;
-    color: #2e3436; }
+  path-bar .button.flat:hover, path-bar .sidebar-button.button:hover, path-bar .header-bar 
.titlebutton.button:hover, .header-bar path-bar .titlebutton.button:hover,
+  path-bar .titlebar .titlebutton.button:hover,
+  .titlebar path-bar .titlebutton.button:hover {
+    box-shadow: 0px 2px 0px #77ace3; }
+  path-bar .button.flat:checked, path-bar .sidebar-button.button:checked, path-bar .header-bar 
.titlebutton.button:checked, .header-bar path-bar .titlebutton.button:checked,
+  path-bar .titlebar .titlebutton.button:checked,
+  .titlebar path-bar .titlebutton.button:checked {
+    box-shadow: 0px 2px 0px #4a90d9; }
 
 /**************
  * Tree Views *
diff --git a/gtk/ui/gtkpathbar.ui b/gtk/ui/gtkpathbar.ui
index b20ca63..f27b331 100644
--- a/gtk/ui/gtkpathbar.ui
+++ b/gtk/ui/gtkpathbar.ui
@@ -4,6 +4,7 @@
     <property name="visible">true</property>
     <property name="orientation">horizontal</property>
     <property name="vexpand">false</property>
+    <property name="valign">GTK_ALIGN_START</property>
     <child>
       <object class="GtkButton" id="overflow_button">
         <property name="visible">true</property>


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