another meh

parent 973927c2
...@@ -32,6 +32,13 @@ ...@@ -32,6 +32,13 @@
#include "glib.h" #include "glib.h"
typedef enum {
ANIMATION_PHASE_NONE,
ANIMATION_PHASE_OUT,
ANIMATION_PHASE_MOVE,
ANIMATION_PHASE_IN
} HidingBoxAnimationPhase;
struct _GtkHidingBoxPrivate struct _GtkHidingBoxPrivate
{ {
GList *children; GList *children;
...@@ -46,13 +53,6 @@ struct _GtkHidingBoxPrivate ...@@ -46,13 +53,6 @@ struct _GtkHidingBoxPrivate
guint needs_update :1; guint needs_update :1;
}; };
typedef enum {
ANIMATION_PHASE_NONE,
ANIMATION_PHASE_OUT,
ANIMATION_PHASE_MOVE,
ANIMATION_PHASE_IN
} HidingBoxAnimationPhase;
static void update_children_visibility (GtkHidingBox *self); static void update_children_visibility (GtkHidingBox *self);
static void static void
...@@ -204,8 +204,10 @@ clear_animation_state (GtkHidingBox *self) ...@@ -204,8 +204,10 @@ clear_animation_state (GtkHidingBox *self)
GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self); GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
priv->animation_phase = ANIMATION_PHASE_NONE; priv->animation_phase = ANIMATION_PHASE_NONE;
g_list_remove_all (priv->widgets_to_hide); g_list_free (priv->widgets_to_show);
g_list_remove_all (priv->widgets_to_show); priv->widgets_to_show = NULL;
g_list_free (priv->widgets_to_hide);
priv->widgets_to_hide = NULL;
} }
static gboolean static gboolean
...@@ -222,10 +224,13 @@ update_children_visibility (GtkHidingBox *box, ...@@ -222,10 +224,13 @@ update_children_visibility (GtkHidingBox *box,
GtkRequestedSize *sizes_temp; GtkRequestedSize *sizes_temp;
gint i; gint i;
GList *children; GList *children;
GList *temp_widgets_to_show = NULL;
gboolean allocate_more_children = TRUE; gboolean allocate_more_children = TRUE;
gint n_visible_children = 0; gint n_visible_children = 0;
g_list_remove_all (priv->widgets_to_show);
g_list_free (priv->widgets_to_show);
priv->widgets_to_show = NULL;
*n_visible_children_expanding = 0; *n_visible_children_expanding = 0;
*children_size = -priv->spacing; *children_size = -priv->spacing;
children = g_list_copy (priv->children); children = g_list_copy (priv->children);
...@@ -240,7 +245,7 @@ update_children_visibility (GtkHidingBox *box, ...@@ -240,7 +245,7 @@ update_children_visibility (GtkHidingBox *box,
if (!gtk_widget_get_visible (child_widget) || !allocate_more_children) if (!gtk_widget_get_visible (child_widget) || !allocate_more_children)
{ {
if (update) if (update)
g_list_append (priv->widget_to_show, child_widget); priv->widgets_to_show = g_list_append (priv->widgets_to_show, child_widget);
continue; continue;
} }
...@@ -292,7 +297,7 @@ update_children_visibility (GtkHidingBox *box, ...@@ -292,7 +297,7 @@ update_children_visibility (GtkHidingBox *box,
} }
static gboolean static gboolean
update_children_visibility_meh (GtkHidingBox *box, needs_update (GtkHidingBox *box,
GtkAllocation *allocation) GtkAllocation *allocation)
{ {
GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (box); GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (box);
...@@ -301,26 +306,41 @@ update_children_visibility_meh (GtkHidingBox *box, ...@@ -301,26 +306,41 @@ update_children_visibility_meh (GtkHidingBox *box,
GtkRequestedSize *sizes_temp; GtkRequestedSize *sizes_temp;
gint i; gint i;
GList *children; GList *children;
GList *new_to_show = NULL; GList *widget_shown;
GList *widgets_to_show = NULL;
gboolean needs_update = FALSE; gboolean needs_update = FALSE;
gboolean allocate_more_children = TRUE; gboolean allocate_more_children = TRUE;
gint children_size = -priv->spacing; gint children_size = -priv->spacing;
children = g_list_copy (priv->children); children = g_list_copy (priv->children);
g_list_remove_all (priv->widgets_to_show);
sizes_temp = g_newa (GtkRequestedSize, g_list_length (priv->children)); sizes_temp = g_newa (GtkRequestedSize, g_list_length (priv->children));
if (priv->inverted) if (priv->inverted)
children = g_list_reverse (children); children = g_list_reverse (children);
widget_shown = priv->widgets_shown;
/* Retrieve desired size for visible children. */ /* Retrieve desired size for visible children. */
for (i = 0, child = children; child != NULL; i++, child = child->next) for (i = 0, child = children; child != NULL; i++, child = child->next)
{ {
child_widget = GTK_WIDGET (child->data); child_widget = GTK_WIDGET (child->data);
if (!gtk_widget_get_visible (child_widget) || !allocate_more_children) if (!gtk_widget_get_visible (child_widget) || !allocate_more_children)
{ {
g_list_append (priv->widgets_to_show, child_widget); needs_update = child->data != widget_shown->data;
widgets_to_show = g_list_prepend (widgets_to_show, child->data);
widget_shown = widget_shown->next;
if (needs_update)
{
break;
}
continue; continue;
} }
else
{
needs_update = child->data == widget_shown->data;
if (needs_update)
{
break;
}
}
gtk_widget_get_preferred_width_for_height (child_widget, gtk_widget_get_preferred_width_for_height (child_widget,
allocation->height, allocation->height,
...@@ -344,11 +364,14 @@ update_children_visibility_meh (GtkHidingBox *box, ...@@ -344,11 +364,14 @@ update_children_visibility_meh (GtkHidingBox *box,
if (children_size > allocation->width) if (children_size > allocation->width)
{ {
allocate_more_children = FALSE; allocate_more_children = FALSE;
continue;
} }
} }
needs_update = needs_update || widget_shown != NULL;
g_list_free (children); g_list_free (children);
return needs_update;
} }
static void static void
...@@ -378,6 +401,7 @@ gtk_hiding_box_size_allocate (GtkWidget *widget, ...@@ -378,6 +401,7 @@ gtk_hiding_box_size_allocate (GtkWidget *widget,
{ {
clear_animation_state (box); clear_animation_state (box);
} }
if (priv->needs_update) if (priv->needs_update)
{ {
update_children_visibility (box, allocation, sizes, TRUE, &children_size, update_children_visibility (box, allocation, sizes, TRUE, &children_size,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment