[gtk+/wip/csoriano/pathbar-bin-view-window] using gtkpathbarbox



commit 226a804538b32e71382b55b3f9a9e204cdeedc9b
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Jun 24 15:19:56 2016 +0200

    using gtkpathbarbox

 gtk/gtkpathbar.c             |   19 +++++++++
 gtk/gtkpathbarbox.c          |   22 +++++-----
 gtk/gtkpathbarcontainer.c    |   86 ++++++++++++++++++++++++++----------------
 gtk/ui/gtkpathbar.ui         |   51 +------------------------
 tests/testpathbarcontainer.c |   16 ++++++-
 5 files changed, 97 insertions(+), 97 deletions(-)
---
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index ec58bfb..8742b7a 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -571,6 +571,16 @@ update_selected_path (GtkPathBar  *self)
 }
 
 static void
+on_overflow_clicked (GtkButton *button,
+                     gpointer   user_data)
+{
+  GtkPathBar *self = GTK_PATH_BAR (user_data);
+
+  gtk_path_bar_set_inverted (self, !gtk_path_bar_get_inverted (self));
+
+}
+
+static void
 gtk_path_bar_finalize (GObject *object)
 {
   GtkPathBar *self = (GtkPathBar *)object;
@@ -729,6 +739,15 @@ gtk_path_bar_init (GtkPathBar *self)
   g_type_ensure (GTK_TYPE_PATH_BAR_CONTAINER);
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  g_signal_connect (priv->path_bar_overflow_root_1, "clicked",
+                    (GCallback) on_overflow_clicked, self);
+  g_signal_connect (priv->path_bar_overflow_root_2, "clicked",
+                    (GCallback) on_overflow_clicked, self);
+  g_signal_connect (priv->path_bar_overflow_tail_1, "clicked",
+                    (GCallback) on_overflow_clicked, self);
+  g_signal_connect (priv->path_bar_overflow_tail_2, "clicked",
+                    (GCallback) on_overflow_clicked, self);
+
   priv->inverted = FALSE;
 }
 
diff --git a/gtk/gtkpathbarbox.c b/gtk/gtkpathbarbox.c
index 324931a..05d1ce0 100644
--- a/gtk/gtkpathbarbox.c
+++ b/gtk/gtkpathbarbox.c
@@ -68,6 +68,7 @@ gtk_path_bar_box_add (GtkContainer *container,
   GtkPathBarBoxPrivate *priv = gtk_path_bar_box_get_instance_private (self);
 
   priv->children = g_list_append (priv->children, widget);
+  gtk_widget_set_parent (widget, GTK_WIDGET (self));
 
   gtk_widget_queue_resize (GTK_WIDGET (self));
 }
@@ -80,6 +81,7 @@ gtk_path_bar_box_remove (GtkContainer *container,
   GtkPathBarBoxPrivate *priv = gtk_path_bar_box_get_instance_private (self);
 
   priv->children = g_list_remove (priv->children, widget);
+  gtk_widget_unparent (widget);
 
   gtk_widget_queue_resize (GTK_WIDGET (self));
 }
@@ -102,7 +104,7 @@ gtk_path_bar_box_size_allocate (GtkWidget     *widget,
   GtkAllocation child_allocation;
   gint available_size;
   gint n_visible_children = 0;
-  gint current_x = 0;
+  gint current_x = allocation->x;
   gint i;
   GtkRequisition minimum_size;
   GtkRequisition natural_size;
@@ -139,12 +141,9 @@ gtk_path_bar_box_size_allocate (GtkWidget     *widget,
       n_visible_children++;
     }
 
- g_print ("child sizing pathbar %d %d\n", sizes[2].minimum_size, sizes[2].natural_size);
   gtk_distribute_natural_allocation (MAX (0, available_size),
                                      n_visible_children, sizes);
 
- g_print ("child sizing pathbar %d %d\n", sizes[2].minimum_size, sizes[2].natural_size);
-
   for (child = children, i = 0; child != NULL; child = g_list_next (child), i++)
     {
       if (!gtk_widget_get_visible (child->data))
@@ -153,7 +152,6 @@ gtk_path_bar_box_size_allocate (GtkWidget     *widget,
       child_available_size.width = sizes[i].minimum_size;
       child_available_size.height = allocation->height;
 
-      g_print ("child sizing 1 %d %d\n", child_available_size.width, sizes[i].minimum_size);
       if (GTK_IS_PATH_BAR_CONTAINER (child->data))
         {
           gtk_path_bar_container_adapt_to_size (GTK_PATH_BAR_CONTAINER (child->data),
@@ -165,10 +163,9 @@ gtk_path_bar_box_size_allocate (GtkWidget     *widget,
 
           sizes[i].minimum_size = MIN (child_available_size.width, natural_size.width);
         }
-      g_print ("child sizing after %d %d\n", child_available_size.width, sizes[i].minimum_size);
 
       child_allocation.x = current_x;
-      child_allocation.y = 0;
+      child_allocation.y = allocation->y;
       child_allocation.width = sizes[i].minimum_size;
       child_allocation.height = allocation->height;
 
@@ -176,8 +173,6 @@ gtk_path_bar_box_size_allocate (GtkWidget     *widget,
 
       current_x += sizes[i].minimum_size;
     }
-
-  g_print ("\n\n\n");
 }
 
 static void
@@ -197,8 +192,8 @@ gtk_path_bar_box_get_preferred_width (GtkWidget *widget,
         continue;
 
       gtk_widget_get_preferred_width (GTK_WIDGET (child->data),
-                                     &child_minimum_width,
-                                     &child_natural_width);
+                                      &child_minimum_width,
+                                      &child_natural_width);
 
       *minimum_width = MAX (*minimum_width, child_minimum_width);
       *natural_width = MAX (*natural_width, child_natural_width);
@@ -241,7 +236,12 @@ gtk_path_bar_box_get_preferred_height (GtkWidget *widget,
 static void
 gtk_path_bar_box_init (GtkPathBarBox *self)
 {
+  GtkPathBarBoxPrivate *priv = gtk_path_bar_box_get_instance_private (self);
+
   gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
+  gtk_widget_set_redraw_on_allocate (GTK_WIDGET (self), TRUE);
+
+  priv->children = NULL;
 }
 
 static void
diff --git a/gtk/gtkpathbarcontainer.c b/gtk/gtkpathbarcontainer.c
index 0de53df..f963379 100644
--- a/gtk/gtkpathbarcontainer.c
+++ b/gtk/gtkpathbarcontainer.c
@@ -34,8 +34,8 @@
 #include "gtkbutton.h"
 
 #define REVEALER_ANIMATION_TIME 2000 //ms
-#define INVERT_ANIMATION_SPEED 1.2 //px/ms
-#define INVERT_ANIMATION_MAX_TIME 750 //px/ms
+#define INVERT_ANIMATION_SPEED 0.1 //px/ms
+#define INVERT_ANIMATION_MAX_TIME 10000 //ms
 
 struct _GtkPathBarContainerPrivate
 {
@@ -61,6 +61,8 @@ struct _GtkPathBarContainerPrivate
   gint allocated_children_width;
   gint total_children_width;
   gint previous_child_width;
+
+  gint invert_animation_initial_width;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkPathBarContainer, gtk_path_bar_container, GTK_TYPE_BIN)
@@ -75,9 +77,9 @@ static GParamSpec *path_bar_container_properties[LAST_PROP] = { NULL, };
 
 static void
 gtk_path_bar_container_set_property (GObject      *object,
-                                    guint         prop_id,
-                                    const GValue *value,
-                                    GParamSpec   *pspec)
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
 {
   GtkPathBarContainer *children_box = GTK_PATH_BAR_CONTAINER (object);
 
@@ -129,9 +131,11 @@ gtk_path_bar_container_add (GtkPathBarContainer *self,
   gtk_container_add (GTK_CONTAINER (revealer), widget);
   gtk_container_add (GTK_CONTAINER (priv->children_box), revealer);
   gtk_revealer_set_transition_duration (GTK_REVEALER (revealer),
-                                            REVEALER_ANIMATION_TIME);
+                                        REVEALER_ANIMATION_TIME);
   priv->children = g_list_append (priv->children, widget);
   gtk_widget_show_all (revealer);
+
+  gtk_widget_queue_allocate (GTK_WIDGET (self));
 }
 
 static void
@@ -241,35 +245,34 @@ get_children_preferred_size_for_requisition (GtkPathBarContainer *self,
                                                  &revealer_width.minimum_size,
                                                  &revealer_width.natural_size);
 
-      /* If we are in the middle of a revealer animation, get the revealer
-       * allocation */
+      /* Minimum size is always the first child whole size */
+      if (i > 0)
+        {
           current_child_min_width = revealer_width.minimum_size;
           current_child_nat_width = revealer_width.natural_size;
+        }
+      else
+        {
+          current_child_min_width = child_width.minimum_size;
+          current_child_nat_width = child_width.natural_size;
+        }
+
+      full_children_current_width += current_child_min_width;
+      if (full_children_current_width > available_size->width)
+        break;
 
       current_children_min_height = MAX (current_children_min_height, child_height.minimum_size);
       current_children_nat_height = MAX (current_children_nat_height, child_height.natural_size);
       current_children_min_width += current_child_min_width;
       current_children_nat_width += current_child_nat_width;
 
-      full_children_current_width += current_child_min_width;
-      g_print ("children container i: %d reversed: %i current width %d available %d\n", i, inverted, 
child_width.natural_size, available_size->width);
-      if (!gtk_revealer_get_reveal_child (revealer))
-        {
-          break;
-        }
     }
 
-  if (minimum_size)
-    {
-      minimum_size->width = current_children_min_width;
-      minimum_size->height = current_children_min_height;
-    }
+  minimum_size->width = current_children_min_width;
+  minimum_size->height = current_children_min_height;
 
-  if (natural_size)
-    {
-      natural_size->width = current_children_nat_width;
-      natural_size->height = current_children_nat_height;
-    }
+  natural_size->width = current_children_nat_width;
+  natural_size->height = current_children_nat_height;
 
   g_list_free (children);
 
@@ -325,7 +328,6 @@ update_children_visibility (GtkPathBarContainer *self,
       if (!g_list_find (priv->widgets_to_remove, child_widget))
         priv->widgets_to_show = g_list_append (priv->widgets_to_show, child_widget);
     }
-g_print ("####### i %d\n", g_list_length (priv->widgets_to_show));
 
   priv->total_children_width = current_children_width;
   g_list_free (children);
@@ -624,8 +626,6 @@ finish_invert_animation (GtkPathBarContainer *self)
        * the scroll is updated
        */
       animation_time =  priv->inverted ? 0 : REVEALER_ANIMATION_TIME;
-      gtk_revealer_set_transition_duration (GTK_REVEALER (revealer),
-                                            animation_time);
       gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
       gtk_revealer_set_transition_duration (GTK_REVEALER (revealer),
                                             REVEALER_ANIMATION_TIME);
@@ -634,6 +634,7 @@ finish_invert_animation (GtkPathBarContainer *self)
   priv->invert_animation = FALSE;
   priv->invert_animation_progress = 0;
   priv->invert_animation_initial_time = 0;
+  priv->invert_animation_initial_width = 0;
   gtk_widget_remove_tick_callback (priv->children_box,
                                    priv->invert_animation_tick_id);
   priv->invert_animation_tick_id = 0;
@@ -662,7 +663,10 @@ invert_animation_on_tick (GtkWidget     *widget,
 
   max_scroll = get_max_scroll (self);
   if (!max_scroll)
-    return TRUE;
+    {
+      g_print ("no max scroll\n");
+      return TRUE;
+    }
 
   /* If there are several items the animation can take some time, so let's limit
    * it to some extend
@@ -684,6 +688,8 @@ invert_animation_on_tick (GtkWidget     *widget,
       return FALSE;
     }
 
+  gtk_widget_queue_allocate (gtk_widget_get_parent (GTK_WIDGET (self)));
+
   return TRUE;
 }
 
@@ -696,6 +702,7 @@ start_invert_animation (GtkPathBarContainer *self)
   if (priv->invert_animation)
     finish_invert_animation (self);
 
+  priv->invert_animation_initial_width = gtk_widget_get_allocated_width (GTK_WIDGET (self));
   priv->invert_animation = TRUE;
   priv->invert_animation_progress = 0;
   priv->invert_animation_initial_children_width = gtk_widget_get_allocated_width (GTK_WIDGET (self));
@@ -712,7 +719,6 @@ start_invert_animation (GtkPathBarContainer *self)
 
       gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 0);
       gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
-      gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), REVEALER_ANIMATION_TIME);
     }
 
   priv->invert_animation_tick_id = gtk_widget_add_tick_callback (priv->children_box,
@@ -917,11 +923,25 @@ real_get_preferred_size_for_requisition (GtkWidget      *widget,
 {
   GtkPathBarContainer *self = GTK_PATH_BAR_CONTAINER (widget);
   GtkPathBarContainerPrivate *priv = gtk_path_bar_container_get_instance_private (self);
+  GtkRequisition animation_opossite_nat_size;
+  GtkRequisition animation_opossite_min_size;
+  gboolean overflows;
+
+   overflows = get_children_preferred_size_for_requisition (self, available_size,
+                                                            priv->inverted,
+                                                            minimum_size,
+                                                            natural_size);
+  g_print ("real for requisition\n");
+  if (priv->invert_animation)
+    {
+      minimum_size->width += (1 - priv->invert_animation_progress) *
+                              (priv->invert_animation_initial_width - minimum_size->width);
+      natural_size->width += (1 - priv->invert_animation_progress) *
+                              (priv->invert_animation_initial_width - natural_size->width);
+      g_print ("after size for requisition %d %d\n", minimum_size->width, natural_size->width);
+    }
 
-  return  get_children_preferred_size_for_requisition (self, available_size,
-                                                       priv->inverted,
-                                                       minimum_size,
-                                                       natural_size);
+  return overflows;
 }
 
 gboolean
diff --git a/gtk/ui/gtkpathbar.ui b/gtk/ui/gtkpathbar.ui
index 679e772..18f10e7 100644
--- a/gtk/ui/gtkpathbar.ui
+++ b/gtk/ui/gtkpathbar.ui
@@ -4,6 +4,7 @@
   <template class="GtkPathBar" parent="GtkStack">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
+    <property name="hexpand">True</property>
     <child>
       <object class="GtkPathBarBox" id="path_bar_1">
         <property name="visible">True</property>
@@ -18,11 +19,6 @@
               <class name="flat"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
         </child>
         <child>
           <object class="GtkButton" id="path_bar_overflow_root_1">
@@ -35,22 +31,12 @@
               <class name="overflow"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
         </child>
         <child>
           <object class="GtkPathBarContainer" id="path_bar_container_1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
-          </packing>
         </child>
         <child>
           <object class="GtkButton" id="path_bar_overflow_tail_1">
@@ -63,11 +49,6 @@
               <class name="overflow"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">3</property>
-          </packing>
         </child>
         <child>
           <object class="GtkButton" id="path_bar_tail_1">
@@ -79,11 +60,6 @@
               <class name="flat"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">4</property>
-          </packing>
         </child>
       </object>
       <packing>
@@ -104,11 +80,6 @@
               <class name="flat"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
         </child>
         <child>
           <object class="GtkButton" id="path_bar_overflow_root_2">
@@ -121,22 +92,12 @@
               <class name="overflow"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
         </child>
         <child>
           <object class="GtkPathBarContainer" id="path_bar_container_2">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
-          </packing>
         </child>
         <child>
           <object class="GtkButton" id="path_bar_overflow_tail_2">
@@ -149,11 +110,6 @@
               <class name="overflow"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">3</property>
-          </packing>
         </child>
         <child>
           <object class="GtkButton" id="path_bar_tail_2">
@@ -165,11 +121,6 @@
               <class name="flat"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">4</property>
-          </packing>
         </child>
       </object>
       <packing>
diff --git a/tests/testpathbarcontainer.c b/tests/testpathbarcontainer.c
index caf9733..1798d4f 100644
--- a/tests/testpathbarcontainer.c
+++ b/tests/testpathbarcontainer.c
@@ -1,10 +1,16 @@
 #include "config.h"
 #include "glib.h"
 #include <gtk/gtk.h>
+#define GTK_COMPILATION
+#include <gtk/gtkpathbarcontainer.h>
+#include <gtk/gtkpathbarcontainer.c>
+#include <gtk/gtkpathbarboxprivate.h>
+#include <gtk/gtkpathbarbox.c>
 
 #define N_BUTTONS 10
 
 static GtkWidget *path_bar_container;
+static GtkWidget *path_bar_box;
 static char *lorem_ipsum = "Loremipsumdolorsitamet, consecteturadipisicingelit,";
 
 static char*
@@ -56,6 +62,7 @@ on_add_button (gint line)
   gtk_widget_show (button);
   g_signal_connect (button, "clicked", (GCallback) on_button_clicked, path_bar_container);
   gtk_path_bar_container_add (GTK_PATH_BAR_CONTAINER (path_bar_container), button);
+  gtk_container_add (GTK_CONTAINER (path_bar_box), gtk_button_new_with_label ("eeeeoo"));
 }
 
 static void
@@ -104,20 +111,23 @@ main (int argc, char *argv[])
 
   grid = gtk_grid_new ();
   g_type_ensure (GTK_TYPE_PATH_BAR_CONTAINER);
+  g_type_ensure (GTK_TYPE_PATH_BAR_BOX);
 
   label = gtk_label_new ("Generic GtkPathBar tests");
   gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 2, 1);
 
   /* ----------------------------------------------------------------------- */
   path_bar_container = gtk_path_bar_container_new ();
-  gtk_grid_attach (GTK_GRID (grid), path_bar_container, 0, 1, 1, 1);
-  gtk_widget_show_all (path_bar_container);
+  path_bar_box = gtk_path_bar_box_new ();
+  gtk_container_add (GTK_CONTAINER (path_bar_box), path_bar_container);
+  gtk_grid_attach (GTK_GRID (grid), path_bar_box, 0, 1, 1, 1);
+  gtk_widget_show_all (path_bar_box);
   /* Add/Remove buttons */
   add_button = gtk_button_new_with_label ("Add");
   gtk_widget_set_halign (add_button, GTK_ALIGN_END);
   remove_button = gtk_button_new_with_label ("Remove");
   gtk_widget_set_halign (remove_button, GTK_ALIGN_END);
-  gtk_grid_attach_next_to (GTK_GRID (grid), add_button, path_bar_container, GTK_POS_RIGHT, 1, 1);
+  gtk_grid_attach_next_to (GTK_GRID (grid), add_button, path_bar_box, GTK_POS_RIGHT, 1, 1);
   g_signal_connect_swapped (add_button, "clicked", (GCallback) on_add_button, GINT_TO_POINTER (0));
   gtk_grid_attach_next_to (GTK_GRID (grid), remove_button, add_button, GTK_POS_RIGHT, 1, 1);
   g_signal_connect_swapped (remove_button, "clicked", (GCallback) on_remove_button, GINT_TO_POINTER (0));


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