[gtk+/wip/csoriano/pathbar-prototype] prototyping transitions
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/csoriano/pathbar-prototype] prototyping transitions
- Date: Tue, 10 Nov 2015 08:40:06 +0000 (UTC)
commit fca7ffea1f9b80001b31c02729f6484a8cb1fc06
Author: Carlos Soriano <csoriano gnome org>
Date: Tue Nov 10 09:39:14 2015 +0100
prototyping transitions
gtk/gtkpathbar.c | 121 +++++++++++++++++++++++++++++++++++++-------------
gtk/gtkpathbar.h | 6 +-
gtk/ui/gtkpathbar.ui | 62 ++++++++++++++++++++------
tests/testpathbar.c | 2 +-
4 files changed, 142 insertions(+), 49 deletions(-)
---
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index c92603e..aae7f07 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -25,6 +25,7 @@
#include "gtkbutton.h"
#include "gtktogglebutton.h"
#include "gtklabel.h"
+#include "gtkbox.h"
#include "gtkpopover.h"
#include "gtkbuilder.h"
#include "gtkstylecontext.h"
@@ -36,8 +37,12 @@
struct _GtkPathBarPrivate
{
- GtkWidget *path_box;
- GtkWidget *overflow_button;
+ GtkWidget *path_bar_1;
+ GtkWidget *path_bar_2;
+ GtkWidget *path_box_1;
+ GtkWidget *path_box_2;
+ GtkWidget *overflow_button_1;
+ GtkWidget *overflow_button_2;
GtkWidget *overflow_popover;
GtkWidget *overflow_container;
GtkWidget *path_chunk_popover_container;
@@ -48,7 +53,7 @@ struct _GtkPathBarPrivate
gboolean selecting_path;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GtkPathBar, gtk_path_bar, GTK_TYPE_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkPathBar, gtk_path_bar, GTK_TYPE_STACK)
enum {
POPULATE_POPUP,
@@ -92,6 +97,39 @@ emit_populate_popup (GtkPathBar *self,
}
static void
+get_path_bar_widgets (GtkPathBar *self,
+ GtkWidget **path_bar,
+ GtkWidget **overflow_button,
+ GtkWidget **path_box,
+ gboolean current)
+{
+ GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+ GtkWidget *current_path_bar;
+
+ current_path_bar = gtk_stack_get_visible_child (GTK_STACK (self));
+ if (current_path_bar == NULL ||
+ (current_path_bar == priv->path_bar_1 && current) ||
+ (current_path_bar == priv->path_bar_2 && !current))
+ {
+ if (path_bar)
+ *path_bar = priv->path_bar_1;
+ if (overflow_button)
+ *overflow_button = priv->overflow_button_1;
+ if (path_box)
+ *path_box = priv->path_box_1;
+ }
+ else
+ {
+ if (path_bar)
+ *path_bar = priv->path_bar_2;
+ if (overflow_button)
+ *overflow_button = priv->overflow_button_2;
+ if (path_box)
+ *path_box = priv->path_box_2;
+ }
+}
+
+static void
on_path_chunk_popover_destroyed (GtkPathBar *self)
{
GtkPathBarPrivate *priv;
@@ -247,12 +285,14 @@ populate_overflow_popover (GtkPathBar *self)
GList *l;
PathChunkData *data;
GtkWidget *path_chunk;
+ GtkWidget *path_box;
g_print ("raising overflow menu\n");
gtk_container_foreach (GTK_CONTAINER (priv->overflow_container),
(GtkCallback) gtk_widget_destroy, NULL);
- overflow_children = gtk_hiding_box_get_overflow_children (GTK_HIDING_BOX (priv->path_box));
+ get_path_bar_widgets (self, NULL, NULL, &path_box, TRUE);
+ overflow_children = gtk_hiding_box_get_overflow_children (GTK_HIDING_BOX (path_box));
for (l = overflow_children; l != NULL; l = l->next)
{
data = g_object_get_data (l->data, "data");
@@ -328,7 +368,6 @@ static void
size_allocate (GtkWidget *self,
GtkAllocation *allocation)
{
- GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
gint path_min_width;
gint path_nat_width;
gint overflow_button_min_width;
@@ -338,10 +377,14 @@ size_allocate (GtkWidget *self,
gboolean overflow;
GList *overflow_children;
GList *children;
+ GtkWidget *path_box;
+ GtkWidget *overflow_button;
+ GtkWidget *path_bar;
gtk_widget_set_allocation (self, allocation);
- children = gtk_container_get_children (GTK_CONTAINER (priv->path_box));
+ get_path_bar_widgets (GTK_PATH_BAR (self), &path_bar, &overflow_button, &path_box, TRUE);
+ children = gtk_container_get_children (GTK_CONTAINER (path_box));
if (g_list_length (children) == 0)
return;
@@ -352,14 +395,15 @@ size_allocate (GtkWidget *self,
path_container_allocation.width = allocation->width;
path_container_allocation.y = allocation->y;
path_container_allocation.height = allocation->height;
- gtk_widget_size_allocate (priv->path_box, &path_container_allocation);
- overflow_children = gtk_hiding_box_get_overflow_children (GTK_HIDING_BOX (priv->path_box));
+ gtk_widget_size_allocate (path_bar, &path_container_allocation);
+ //gtk_widget_size_allocate (path_box, &path_container_allocation);
+ overflow_children = gtk_hiding_box_get_overflow_children (GTK_HIDING_BOX (path_box));
overflow = overflow_children != NULL;
g_list_free (overflow_children);
- gtk_widget_set_child_visible (priv->overflow_button, FALSE);
- gtk_widget_get_preferred_width (priv->path_box, &path_min_width, &path_nat_width);
- gtk_widget_get_preferred_width (priv->overflow_button, &overflow_button_min_width, NULL);
+ gtk_widget_set_child_visible (overflow_button, FALSE);
+ gtk_widget_get_preferred_width (path_box, &path_min_width, &path_nat_width);
+ gtk_widget_get_preferred_width (overflow_button, &overflow_button_min_width, NULL);
direction = gtk_widget_get_direction (self);
if (overflow && direction == GTK_TEXT_DIR_LTR)
@@ -368,8 +412,8 @@ size_allocate (GtkWidget *self,
overflow_button_allocation.height = allocation->height;
overflow_button_allocation.width = overflow_button_min_width;
overflow_button_allocation.x = allocation->x;
- gtk_widget_set_child_visible (priv->overflow_button, TRUE);
- gtk_widget_size_allocate (priv->overflow_button, &overflow_button_allocation);
+ gtk_widget_set_child_visible (overflow_button, TRUE);
+ gtk_widget_size_allocate (overflow_button, &overflow_button_allocation);
}
path_container_allocation.x = overflow ? allocation->x + overflow_button_min_width
@@ -378,7 +422,7 @@ size_allocate (GtkWidget *self,
: allocation->width;
path_container_allocation.y = allocation->y;
path_container_allocation.height = allocation->height;
- gtk_widget_size_allocate (priv->path_box, &path_container_allocation);
+ //gtk_widget_size_allocate (path_bar, &path_container_allocation);
if (overflow && direction == GTK_TEXT_DIR_RTL)
{
@@ -388,8 +432,8 @@ size_allocate (GtkWidget *self,
overflow_button_allocation.x = path_container_allocation.x +
path_container_allocation.width -
overflow_button_min_width;
- gtk_widget_set_child_visible (priv->overflow_button, TRUE);
- gtk_widget_size_allocate (priv->overflow_button, &overflow_button_allocation);
+ gtk_widget_set_child_visible (overflow_button, TRUE);
+ gtk_widget_size_allocate (overflow_button, &overflow_button_allocation);
}
g_list_free (children);
@@ -472,18 +516,22 @@ gtk_path_bar_class_init (GtkPathBarClass *klass)
G_PARAM_READWRITE);
path_bar_properties[PROP_HIDE_DIRECTION] =
- g_param_spec_string ("hide-direction",
- P_("Hide direction"),
- P_("From where the container will start hiding widgets when there is not
enough space"),
- NULL,
- G_PARAM_READWRITE);
+ g_param_spec_int ("hide-direction",
+ P_("Hide direction"),
+ P_("From where the container will start hiding widgets when there is not enough
space"),
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE);
g_object_class_install_properties (object_class, LAST_PROP, path_bar_properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkpathbar.ui");
- gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_button);
- gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_box);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_bar_1);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_bar_2);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_button_1);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_button_2);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_box_1);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_box_2);
gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_popover);
gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_container);
@@ -514,6 +562,9 @@ gtk_path_bar_set_path (GtkPathBar *self,
GtkWidget *path_chunk;
PathChunkData *data;
GList *children;
+ GtkWidget *path_box;
+ GtkWidget *overflow_button;
+ GtkWidget *path_bar;
g_return_if_fail (GTK_IS_PATH_BAR (self));
@@ -522,9 +573,12 @@ gtk_path_bar_set_path (GtkPathBar *self,
if (g_strcmp0 (priv->path, path) == 0)
return;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->overflow_button), FALSE);
+ get_path_bar_widgets (GTK_PATH_BAR (self), &path_bar, &overflow_button, &path_box, FALSE);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->overflow_button_1), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->overflow_button_2), FALSE);
- gtk_container_foreach (GTK_CONTAINER (priv->path_box), (GtkCallback) gtk_widget_destroy, NULL);
+ gtk_container_foreach (GTK_CONTAINER (path_box), (GtkCallback) gtk_widget_destroy, NULL);
if (priv->path)
{
@@ -534,6 +588,7 @@ gtk_path_bar_set_path (GtkPathBar *self,
splitted_path = g_strsplit (path, "/", -1);
current_path = g_string_new ("");
+
for (guint i = 0; i < g_strv_length (splitted_path); i++)
{
if (g_strcmp0 (splitted_path[i], "") == 0)
@@ -542,11 +597,11 @@ gtk_path_bar_set_path (GtkPathBar *self,
g_string_append (current_path, "/");
g_string_append (current_path, splitted_path[i]);
path_chunk = create_path_chunk (self, current_path, splitted_path[i], TRUE);
- gtk_container_add (GTK_CONTAINER (priv->path_box), path_chunk);
+ gtk_container_add (GTK_CONTAINER (path_box), path_chunk);
data = g_object_get_data (G_OBJECT (path_chunk), "data");
}
- children = gtk_container_get_children (GTK_CONTAINER (priv->path_box));
+ children = gtk_container_get_children (GTK_CONTAINER (path_box));
if (children != NULL)
{
path_chunk = GTK_WIDGET (g_list_last (children)->data);
@@ -557,6 +612,7 @@ gtk_path_bar_set_path (GtkPathBar *self,
priv->path = g_strdup (data->path->str);
}
+ gtk_stack_set_visible_child (GTK_STACK (self), path_bar);
g_object_notify_by_pspec (G_OBJECT (self), path_bar_properties[PROP_PATH]);
g_strfreev (splitted_path);
@@ -572,6 +628,7 @@ gtk_path_bar_select_path (GtkPathBar *self,
PathChunkData *data;
GList *children;
GList *l;
+ GtkWidget *path_box;
g_return_if_fail (GTK_IS_PATH_BAR (self));
@@ -579,7 +636,8 @@ gtk_path_bar_select_path (GtkPathBar *self,
g_return_if_fail (g_str_has_prefix (priv->path, path));
- children = gtk_container_get_children (GTK_CONTAINER (priv->path_box));
+ get_path_bar_widgets (GTK_PATH_BAR (self), NULL, NULL, &path_box, TRUE);
+ children = gtk_container_get_children (GTK_CONTAINER (path_box));
for (l = children; l != NULL; l = l->next)
{
data = g_object_get_data (G_OBJECT (l->data), "data");
@@ -601,9 +659,10 @@ gtk_path_bar_set_hide_direction (GtkPathBar *self,
priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
- if (gtk_hiding_box_get_hide_direction (GTK_HIDING_BOX (priv->path_box)) != hide_direction)
+ if (gtk_hiding_box_get_hide_direction (GTK_HIDING_BOX (priv->path_box_1)) != hide_direction)
{
- gtk_hiding_box_set_hide_direction (GTK_HIDING_BOX (priv->path_box), hide_direction);
+ gtk_hiding_box_set_hide_direction (GTK_HIDING_BOX (priv->path_box_1), hide_direction);
+ gtk_hiding_box_set_hide_direction (GTK_HIDING_BOX (priv->path_box_2), hide_direction);
g_object_notify (G_OBJECT (self), "hide-direction");
@@ -620,7 +679,7 @@ gtk_path_bar_get_hide_direction (GtkPathBar *self)
priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
- return gtk_hiding_box_get_hide_direction (GTK_HIDING_BOX (priv->path_box));
+ return gtk_hiding_box_get_hide_direction (GTK_HIDING_BOX (priv->path_box_1));
}
GtkWidget *
diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h
index 1f7be88..caee56c 100644
--- a/gtk/gtkpathbar.h
+++ b/gtk/gtkpathbar.h
@@ -25,7 +25,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
-#include <gtk/gtkbox.h>
+#include <gtk/gtkstack.h>
G_BEGIN_DECLS
@@ -42,7 +42,7 @@ typedef struct _GtkPathBarPrivate GtkPathBarPrivate;
struct _GtkPathBarClass
{
- GtkBoxClass parent;
+ GtkStackClass parent;
/*< public >*/
@@ -59,7 +59,7 @@ struct _GtkPathBarClass
struct _GtkPathBar
{
- GtkBox parent_instance;
+ GtkStack parent_instance;
};
GDK_AVAILABLE_IN_3_20
diff --git a/gtk/ui/gtkpathbar.ui b/gtk/ui/gtkpathbar.ui
index c60a941..aba2b23 100644
--- a/gtk/ui/gtkpathbar.ui
+++ b/gtk/ui/gtkpathbar.ui
@@ -12,32 +12,66 @@
<class name="path-bar-overflow-popover"/>
</style>
</object>
- <template class="GtkPathBar" parent="GtkBox">
+ <template class="GtkPathBar" parent="GtkStack">
<property name="visible">true</property>
- <property name="orientation">horizontal</property>
- <property name="vexpand">false</property>
<property name="valign">GTK_ALIGN_START</property>
+ <property name="vexpand">false</property>
<child>
- <object class="GtkMenuButton" id="overflow_button">
+ <object class="GtkBox" id="path_bar_1">
<property name="visible">true</property>
- <property name="no-show-all">true</property>
- <property name="popover">overflow_popover</property>
- <signal name="clicked" handler="populate_overflow_popover" object="GtkPathBar" swapped="yes"/>
+ <property name="orientation">horizontal</property>
<child>
- <object class="GtkImage">
+ <object class="GtkMenuButton" id="overflow_button_1">
+ <property name="visible">true</property>
+ <property name="no-show-all">true</property>
+ <property name="popover">overflow_popover</property>
+ <signal name="clicked" handler="populate_overflow_popover" object="GtkPathBar" swapped="yes"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">true</property>
+ <property name="icon_name">image-loading-symbolic</property>
+ <property name="icon_size">1</property>
+ </object>
+ </child>
+ <style>
+ <class name="flat"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkHidingBox" id="path_box_1">
<property name="visible">true</property>
- <property name="icon_name">image-loading-symbolic</property>
- <property name="icon_size">1</property>
</object>
</child>
- <style>
- <class name="flat"/>
- </style>
</object>
</child>
<child>
- <object class="GtkHidingBox" id="path_box">
+ <object class="GtkBox" id="path_bar_2">
<property name="visible">true</property>
+ <property name="orientation">horizontal</property>
+ <child>
+ <object class="GtkMenuButton" id="overflow_button_2">
+ <property name="visible">true</property>
+ <property name="no-show-all">true</property>
+ <property name="popover">overflow_popover</property>
+ <signal name="clicked" handler="populate_overflow_popover" object="GtkPathBar" swapped="yes"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">true</property>
+ <property name="icon_name">image-loading-symbolic</property>
+ <property name="icon_size">1</property>
+ </object>
+ </child>
+ <style>
+ <class name="flat"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkHidingBox" id="path_box_2">
+ <property name="visible">true</property>
+ </object>
+ </child>
</object>
</child>
<style>
diff --git a/tests/testpathbar.c b/tests/testpathbar.c
index 4ddc3c2..82e0d9d 100644
--- a/tests/testpathbar.c
+++ b/tests/testpathbar.c
@@ -142,7 +142,7 @@ main (int argc, char *argv[])
path_bar = gtk_path_bar_new ();
gtk_container_add (GTK_CONTAINER (box), path_bar);
- gtk_path_bar_set_hide_direction (GTK_PATH_BAR (path_bar), GTK_DIR_LEFT);
+ //gtk_path_bar_set_hide_direction (GTK_PATH_BAR (path_bar), GTK_DIR_LEFT);
gtk_path_bar_set_path (GTK_PATH_BAR (path_bar), original_path);
g_signal_connect (GTK_PATH_BAR (path_bar), "populate-popup",
G_CALLBACK (on_populate_popup), window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]