[gtk+/wip/csoriano/pathbar-prototype: 124/124] experiment with revealers



commit 63deb757820e0ebafb52421b0677321e72ea4ae3
Author: Carlos Soriano <csoriano gnome org>
Date:   Wed May 11 17:19:52 2016 +0200

    experiment with revealers

 gtk/Makefile.am                               |    2 +-
 gtk/gtk.h                                     |    1 +
 gtk/gtkbox.c                                  |    5 ++++
 gtk/gtkgrid.c                                 |    8 ++++++
 gtk/gtkhidingbox.c                            |   32 +++++++++++++++---------
 gtk/{gtkhidingboxprivate.h => gtkhidingbox.h} |    6 ++--
 gtk/gtkpathbar.c                              |    2 +-
 gtk/gtkpathbarcontainer.c                     |    2 +-
 gtk/gtkrevealer.c                             |    1 +
 tests/Makefile.am                             |    5 ++++
 tests/testhidingbox.c                         |   26 ++++++++++++++------
 11 files changed, 64 insertions(+), 26 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 5c0ec46..d1f1624 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -488,7 +488,7 @@ gtk_private_h_sources =             \
        gtkgestureswipeprivate.h        \
        gtkgesturezoomprivate.h \
        gtkheaderbarprivate.h   \
-       gtkhidingboxprivate.h   \
+       gtkhidingbox.h  \
        gtkhslaprivate.h        \
        gtkiconcache.h          \
        gtkiconhelperprivate.h  \
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 5e336e7..3fb9c67 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -121,6 +121,7 @@
 #include <gtk/gtkglarea.h>
 #include <gtk/gtkgrid.h>
 #include <gtk/gtkheaderbar.h>
+#include <gtk/gtkhidingbox.h>
 #include <gtk/gtkicontheme.h>
 #include <gtk/gtkiconview.h>
 #include <gtk/gtkimage.h>
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index 93206cf..bcf8220 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -479,7 +479,12 @@ count_expand_children (GtkBox *box,
        {
          *visible_children += 1;
          if (child->expand || gtk_widget_compute_expand (child->widget, private->orientation))
+            {
+
+              if (GTK_IS_REVEALER (child->widget))
+                g_print ("########################## IT IS\n");
            *expand_children += 1;
+            }
        }
     }
 }
diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c
index 5fed33f..a7e2c50 100644
--- a/gtk/gtkgrid.c
+++ b/gtk/gtkgrid.c
@@ -29,6 +29,7 @@
 #include "gtkcontainerprivate.h"
 #include "gtkcsscustomgadgetprivate.h"
 #include "gtkprivate.h"
+#include "gtkrevealer.h"
 #include "gtkintl.h"
 
 
@@ -1000,7 +1001,12 @@ gtk_grid_request_compute_expand (GtkGridRequest *request,
       line = &lines->lines[attach->pos - lines->min];
       line->empty = FALSE;
       if (gtk_widget_compute_expand (child->widget, orientation))
+        {
+
+              if (GTK_IS_REVEALER (child->widget))
+                g_print ("########################## IT IS\n");
         line->expand = TRUE;
+        }
     }
 
   for (list = priv->children; list; list = list->next)
@@ -1030,6 +1036,8 @@ gtk_grid_request_compute_expand (GtkGridRequest *request,
 
       if (!has_expand && gtk_widget_compute_expand (child->widget, orientation))
         {
+              if (GTK_IS_REVEALER (child->widget))
+                g_print ("########################## IT IS\n");
           for (i = 0; i < attach->span; i++)
             {
              if (attach->pos + i >= max || attach->pos + 1 < min)
diff --git a/gtk/gtkhidingbox.c b/gtk/gtkhidingbox.c
index ac45efd..08ea752 100644
--- a/gtk/gtkhidingbox.c
+++ b/gtk/gtkhidingbox.c
@@ -24,7 +24,7 @@
 
 #include "config.h"
 
-#include "gtkhidingboxprivate.h"
+#include "gtkhidingbox.h"
 #include "gtkwidgetprivate.h"
 #include "gtkintl.h"
 #include "gtksizerequest.h"
@@ -56,12 +56,20 @@ struct _GtkHidingBoxPrivate
 };
 
 static void
+gtk_hiding_box_buildable_init (GtkBuildableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkHidingBox, gtk_hiding_box, GTK_TYPE_CONTAINER,
+                         G_ADD_PRIVATE (GtkHidingBox)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, gtk_hiding_box_buildable_init))
+
+
+static void
 gtk_hiding_box_buildable_add_child (GtkBuildable *buildable,
                                     GtkBuilder   *builder,
                                     GObject      *child,
                                     const gchar  *type)
 {
-  GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (box);
+  GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (buildable);
 
   if (!type)
     {
@@ -80,10 +88,6 @@ gtk_hiding_box_buildable_init (GtkBuildableIface *iface)
   iface->add_child = gtk_hiding_box_buildable_add_child;
 }
 
-G_DEFINE_TYPE_WITH_CODE (GtkHidingBox, gtk_hiding_box, GTK_TYPE_CONTAINER,
-                         G_ADD_PRIVATE (GtkHidingBox)
-                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, gtk_hiding_box_buildable_init))
-
 enum {
   PROP_0,
   PROP_SPACING,
@@ -150,7 +154,9 @@ gtk_hiding_box_add (GtkContainer *container,
   gtk_container_add (GTK_CONTAINER (revealer), widget);
   gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
   priv->children = g_list_append (priv->children, revealer);
+  gtk_widget_show (revealer);
   gtk_widget_set_parent (revealer, GTK_WIDGET (box));
+  g_print ("add\n");
 }
 
 static void
@@ -294,7 +300,9 @@ update_children_visibility (GtkHidingBox     *box,
       if (gtk_widget_get_hexpand (child_widget))
         (n_visible_children_expanding)++;
       (n_visible_children)++;
-      priv->widgets_to_show = g_list_append (priv->widgets_to_show, child_widget);
+
+      if (!g_list_find (priv->widgets_to_remove, child_widget))
+        priv->widgets_to_show = g_list_append (priv->widgets_to_show, child_widget);
     }
 
   for (i = 0; i < n_visible_children; i++)
@@ -308,6 +316,7 @@ update_children_visibility (GtkHidingBox     *box,
         {
           sizes[i].minimum_size = sizes_temp[i].minimum_size;
           sizes[i].natural_size = sizes_temp[i].natural_size;
+          g_print ("sizes %d \n", sizes[i].natural_size);
         }
     }
 
@@ -408,16 +417,19 @@ idle_update_revealers (GtkHidingBox *box)
 
   for (l = priv->widgets_to_show; l != NULL; l = l->next)
     {
+          g_print ("widget to show %p\n", l->data);
       gtk_revealer_set_reveal_child (GTK_REVEALER (l->data), TRUE);
     }
 
   for (l = priv->widgets_to_hide; l != NULL; l = l->next)
     {
+          g_print ("widget to hide %p\n", l->data);
       gtk_revealer_set_reveal_child (GTK_REVEALER (l->data), FALSE);
     }
 
   for (l = priv->widgets_to_remove; l != NULL; l = l->next)
     {
+          g_print ("widget to remove %p\n", l->data);
       gtk_revealer_set_reveal_child (GTK_REVEALER (l->data), FALSE);
     }
 }
@@ -470,9 +482,6 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
 
 
   /* If there is no visible child, simply return. */
-  if (n_visible_children == 0)
-    return;
-
   direction = gtk_widget_get_direction (widget);
 
   /* Bring children up to allocation width first */
@@ -480,8 +489,7 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
   extra_space = gtk_distribute_natural_allocation (MAX (0, extra_space), n_visible_children, sizes);
 
   /* Distribute extra space on the expanding children */
-  if (n_visible_children > 1)
-    extra_space = extra_space / MAX (1, n_visible_children_expanding);
+  extra_space = extra_space / MAX (1, n_visible_children_expanding);
 
   x = allocation->x;
   for (i = 0, child = priv->children; child != NULL; child = child->next)
diff --git a/gtk/gtkhidingboxprivate.h b/gtk/gtkhidingbox.h
similarity index 96%
rename from gtk/gtkhidingboxprivate.h
rename to gtk/gtkhidingbox.h
index b44dc55..e125495 100644
--- a/gtk/gtkhidingboxprivate.h
+++ b/gtk/gtkhidingbox.h
@@ -18,8 +18,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifndef __GTK_HIDING_BOX_PRIVATE_H__
-#define __GTK_HIDING_BOX_PRIVATE_H__
+#ifndef __GTK_HIDING_BOX_H__
+#define __GTK_HIDING_BOX_H__
 
 #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
 #error "Only <gtk/gtk.h> can be included directly."
@@ -74,4 +74,4 @@ GDK_AVAILABLE_IN_3_20
 GList             *gtk_hiding_box_get_overflow_children  (GtkHidingBox      *box);
 G_END_DECLS
 
-#endif /* GTK_HIDING_BOX_PRIVATE_H_ */
+#endif /* GTK_HIDING_BOX_H_ */
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index b507c63..a983f10 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -37,7 +37,7 @@
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
 #include "gtktypebuiltins.h"
-#include "gtkhidingboxprivate.h"
+#include "gtkhidingbox.h"
 
 /**
  * SECTION:gtkpathbar
diff --git a/gtk/gtkpathbarcontainer.c b/gtk/gtkpathbarcontainer.c
index 876bfbc..f68d9dc 100644
--- a/gtk/gtkpathbarcontainer.c
+++ b/gtk/gtkpathbarcontainer.c
@@ -25,7 +25,7 @@
 #include "gtkwidget.h"
 #include "gtkmenubutton.h"
 #include "gtksizerequest.h"
-#include "gtkhidingboxprivate.h"
+#include "gtkhidingbox.h"
 #include "gtkwidgetprivate.h"
 #include "glib-object.h"
 
diff --git a/gtk/gtkrevealer.c b/gtk/gtkrevealer.c
index b23f66a..45a0bed 100644
--- a/gtk/gtkrevealer.c
+++ b/gtk/gtkrevealer.c
@@ -456,6 +456,7 @@ gtk_revealer_real_size_allocate (GtkWidget     *widget,
 
   g_return_if_fail (allocation != NULL);
 
+  g_print ("revealer allocation %d %d %d %d\n", allocation->height, allocation->width, allocation->x, 
allocation->y);
   gtk_widget_set_allocation (widget, allocation);
   gtk_revealer_get_child_allocation (revealer, allocation, &child_allocation);
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0d9308f..3352d9a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -86,6 +86,7 @@ noinst_PROGRAMS =  $(TEST_PROGS)      \
        testgtk                         \
        testheaderbar                   \
        testheightforwidth              \
+       testhidingbox                   \
        testiconview                    \
        testiconview-keynav             \
        testicontheme                   \
@@ -293,6 +294,7 @@ testpixbuf_save_DEPENDENCIES = $(TEST_DEPS)
 testpixbuf_color_DEPENDENCIES = $(TEST_DEPS)
 testpixbuf_scale_DEPENDENCIES = $(TEST_DEPS)
 testpathbar_DEPENDENCIES = $(TEST_DEPS)
+testhidingbox_DEPENDENCIES = $(TEST_DEPS)
 testgmenu_DEPENDENCIES = $(TEST_DEPS)
 testlogout_DEPENDENCIES = $(TEST_DEPS)
 teststack_DEPENDENCIES = $(TEST_DEPS)
@@ -396,6 +398,9 @@ testmenubutton_SOURCES =    \
 testpathbar_SOURCES =          \
        testpathbar.c
 
+testhidingbox_SOURCES =        \
+       testhidingbox.c
+
 testprint_SOURCES =            \
        testprint.c             \
        testprintfileoperation.h \
diff --git a/tests/testhidingbox.c b/tests/testhidingbox.c
index 7093f53..4e87ad8 100644
--- a/tests/testhidingbox.c
+++ b/tests/testhidingbox.c
@@ -1,7 +1,6 @@
 #include "config.h"
 #include "glib.h"
 #include <gtk/gtk.h>
-#include <gtk/gtkhidingboxprivate.h>
 
 static GtkWidget *hiding_box;
 
@@ -17,6 +16,7 @@ static void
 on_button_clicked (GtkWidget *button,
                    gpointer   user_data)
 {
+  g_print ("button clicked\n");
   gtk_container_remove (GTK_CONTAINER (user_data), button);
 }
 
@@ -24,15 +24,24 @@ static void
 on_reset_button_clicked (GtkButton *reset_button)
 {
   GtkWidget *button;
+  GtkWidget *revealer;
 
-  gtk_container_foreach (GTK_CONTAINER (hiding_box), gtk_widget_destroy);
+  gtk_container_foreach (GTK_CONTAINER (hiding_box), gtk_widget_destroy, NULL);
 
+  g_print ("clicked\n");
   button = gtk_button_new_with_label ("test1");
-  g_signal_connect (button, "clicked", on_button_clicked, hiding_box);
-  gtk_container_add (GTK_CONTAINER (hiding_box), );
-  gtk_container_add (GTK_CONTAINER (hiding_box), gtk_button_new_with_label ("test2"));
-  gtk_container_add (GTK_CONTAINER (hiding_box), gtk_button_new_with_label ("test3"));
-  gtk_container_add (GTK_CONTAINER (hiding_box), gtk_button_new_with_label ("test4"));
+  g_signal_connect (button, "clicked", (GCallback) on_button_clicked, hiding_box);
+  gtk_container_add (GTK_CONTAINER (hiding_box), button);
+  button = gtk_button_new_with_label ("test2");
+  g_signal_connect (button, "clicked", (GCallback) on_button_clicked, hiding_box);
+  revealer = gtk_revealer_new ();
+  gtk_container_add (GTK_CONTAINER (revealer), button);
+  gtk_container_add (GTK_CONTAINER (hiding_box), revealer);
+  button = gtk_button_new_with_label ("test3");
+  g_signal_connect (button, "clicked", (GCallback) on_button_clicked, hiding_box);
+  gtk_container_add (GTK_CONTAINER (hiding_box), button);
+
+  gtk_widget_show_all (hiding_box);
 }
 
 int
@@ -63,8 +72,9 @@ main (int argc, char *argv[])
   gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 2, 1);
 
   /* ----------------------------------------------------------------------- */
-  hiding_box = gtk_hiding_box ();
+  hiding_box = gtk_hiding_box_new ();
   gtk_grid_attach (GTK_GRID (grid), hiding_box, 0, 1, 1, 1);
+  gtk_widget_show_all (hiding_box);
 
   /* Reset button */
   reset_button = gtk_button_new_with_label ("Reset State");


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