[gtk+/wip/csoriano/pathbar-prototype: 102/102] experiment with scrolled window



commit e6d3c3cde8338cbfd59fa5bcc0eb7ab10cab7f6d
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri May 13 18:02:19 2016 +0200

    experiment with scrolled window

 gtk/gtkhidingbox.c    |   78 +++++++++++++++++++++++++++++++++++++++----------
 tests/testhidingbox.c |   24 +++++++-------
 2 files changed, 74 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkhidingbox.c b/gtk/gtkhidingbox.c
index 08ea752..0f329bb 100644
--- a/gtk/gtkhidingbox.c
+++ b/gtk/gtkhidingbox.c
@@ -30,6 +30,9 @@
 #include "gtksizerequest.h"
 #include "gtkbuildable.h"
 #include "gtkrevealer.h"
+#include "gtkadjustment.h"
+#include "gtkscrolledwindow.h"
+#include "gtkbox.h"
 
 #include "glib.h"
 
@@ -53,6 +56,10 @@ struct _GtkHidingBoxPrivate
   gint current_width;
   gint current_height;
   guint needs_update :1;
+
+  GtkWidget *scrolled_window;
+  GtkWidget *box;
+  GtkAdjustment *adjustment;
 };
 
 static void
@@ -151,11 +158,16 @@ gtk_hiding_box_add (GtkContainer *container,
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (box);
 
   revealer = gtk_revealer_new ();
+  gtk_revealer_set_transition_type (GTK_REVEALER (revealer),
+                                    GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
   gtk_container_add (GTK_CONTAINER (revealer), widget);
-  gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
-  priv->children = g_list_append (priv->children, revealer);
+  g_print ("box fine? %s \n", G_OBJECT_TYPE_NAME (priv->box));
+  gtk_container_add (GTK_CONTAINER (priv->box), revealer);
+  priv->children = g_list_append (priv->children, widget);
   gtk_widget_show (revealer);
-  gtk_widget_set_parent (revealer, GTK_WIDGET (box));
+
+  gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
+
   g_print ("add\n");
 }
 
@@ -207,16 +219,15 @@ gtk_hiding_box_forall (GtkContainer *container,
 {
   GtkHidingBox *box = GTK_HIDING_BOX (container);
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (box);
-  GtkWidget *child;
-  GList *children;
+  GList *child;
 
-  children = priv->children;
-  while (children)
+  for  (child = priv->children; child != NULL; child = child->next)
     {
-      child = children->data;
-      children = children->next;
-      (* callback) (child, callback_data);
+      (* callback) (child->data, callback_data);
     }
+
+  if (include_internals)
+    (* callback) (priv->scrolled_window, callback_data);
 }
 
 static void
@@ -418,19 +429,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);
+      gtk_revealer_set_reveal_child (GTK_REVEALER (gtk_widget_get_parent (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);
+      gtk_revealer_set_reveal_child (GTK_REVEALER (gtk_widget_get_parent (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);
+      gtk_revealer_set_reveal_child (GTK_REVEALER (gtk_widget_get_parent (l->data)), FALSE);
     }
 }
 
@@ -452,9 +463,28 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
   gint n_visible_children = 0;
   gint n_visible_children_expanding = 0;
   gint children_size = 0;
+  gint minimum_height;
+  gint natural_height;
+
+  gint window_min_width;
+  gint window_nat_width;
+  gint window_min_height;
+  gint window_nat_height;
 
   gtk_widget_set_allocation (widget, allocation);
+
   sizes = g_newa (GtkRequestedSize, g_list_length (priv->children));
+  update_children_visibility (box, allocation, sizes, FALSE, &children_size,
+                                  &n_visible_children_expanding);
+
+  idle_update_revealers (box);
+
+  child_allocation.x = allocation->x;
+  child_allocation.y = allocation->y;
+  child_allocation.width = allocation->width;
+  child_allocation.height = allocation->height;
+  gtk_widget_size_allocate (priv->scrolled_window, &child_allocation);
+#if 0
 
   /*
   if (needs_update (box, allocation))
@@ -511,7 +541,8 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
       else
         child_allocation.width = sizes[i].minimum_size;
 
-      child_allocation.height = allocation->height;
+      gtk_widget_get_preferred_height (child_widget, &minimum_height, &natural_height);
+      child_allocation.height = CLAMP (natural_height, minimum_height, allocation->height);
       if (direction == GTK_TEXT_DIR_RTL)
         child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - 
child_allocation.width;
 
@@ -520,6 +551,7 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
       x += child_allocation.width + spacing;
       ++i;
     }
+#endif
 
   _gtk_widget_set_simple_clip (widget, NULL);
 }
@@ -601,11 +633,25 @@ gtk_hiding_box_get_request_mode (GtkWidget *self)
 }
 
 static void
+on_what (gpointer  data,
+         GObject  *where_the_object_was)
+{
+  G_BREAKPOINT ();
+}
+
+static void
 gtk_hiding_box_init (GtkHidingBox *box)
 {
   GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (box);
 
   gtk_widget_set_has_window (GTK_WIDGET (box), FALSE);
+  priv->adjustment = gtk_adjustment_new (0, 0, 0, 1, 1, 1);
+  priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+  priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  g_object_weak_ref (G_OBJECT (priv->box), on_what, NULL);
+  gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->box);
+  gtk_widget_set_parent (priv->scrolled_window, GTK_WIDGET (box));
+
   priv->spacing = 0;
   priv->inverted = FALSE;
   priv->widgets_to_hide = NULL;
@@ -613,8 +659,8 @@ gtk_hiding_box_init (GtkHidingBox *box)
   priv->widgets_to_remove = NULL;
   priv->widgets_shown = NULL;
   priv->animation_phase = ANIMATION_PHASE_NONE;
-  priv->current_width = 0;
-  priv->current_height = 0;
+
+  gtk_widget_show_all (priv->scrolled_window);
 }
 
 static void
diff --git a/tests/testhidingbox.c b/tests/testhidingbox.c
index 4e87ad8..904f42c 100644
--- a/tests/testhidingbox.c
+++ b/tests/testhidingbox.c
@@ -2,6 +2,8 @@
 #include "glib.h"
 #include <gtk/gtk.h>
 
+#define N_BUTTONS 10
+
 static GtkWidget *hiding_box;
 
 static void
@@ -24,22 +26,20 @@ static void
 on_reset_button_clicked (GtkButton *reset_button)
 {
   GtkWidget *button;
-  GtkWidget *revealer;
 
   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", (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);
+  for (int i = 0; i < N_BUTTONS; i++)
+    {
+      g_autofree gchar *label;
+
+      label = g_strdup_printf ("test%d", i, NULL);
+      button = gtk_button_new_with_label (label);
+      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);
 }


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