revealer: Always use identity transform for revealed child

Refactor the child allocation machinery, so that the complex allocation
paths are only run when the animation is running.

And in particular, ensure that when no animation is running, the
identity transform is allocated.
This commit is contained in:
Benjamin Otte 2019-03-09 14:44:06 +01:00
parent 658588dfe7
commit 8f6a48832d

View File

@ -366,84 +366,89 @@ gtk_revealer_real_size_allocate (GtkWidget *widget,
GtkRevealer *revealer = GTK_REVEALER (widget);
GtkRevealerPrivate *priv = gtk_revealer_get_instance_private (revealer);
GtkWidget *child;
GskTransform *transform;
double hscale, vscale;
int child_width, child_height;
child = gtk_bin_get_child (GTK_BIN (revealer));
if (child != NULL && gtk_widget_get_visible (child))
if (child == NULL || !gtk_widget_get_visible (child))
return;
if (priv->current_pos >= 1.0)
{
GskTransform *transform;
double hscale, vscale;
int child_width, child_height;
child_width = width;
child_height = height;
hscale = get_child_size_scale (revealer, GTK_ORIENTATION_HORIZONTAL);
vscale = get_child_size_scale (revealer, GTK_ORIENTATION_VERTICAL);
if (hscale <= 0 || vscale <= 0)
{
/* don't allocate anything, the child is invisible and the numbers
* don't make sense. */
return;
}
else if (hscale < 1.0)
{
g_assert (vscale == 1.0);
child_width = MIN (G_MAXINT, ceil (width / hscale));
}
else if (vscale < 1.0)
{
child_height = MIN (G_MAXINT, ceil (height / vscale));
}
transform = NULL;
switch (effective_transition (revealer))
{
case GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width - child_width, 0));
break;
case GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (0, height - child_height));
case GTK_REVEALER_TRANSITION_TYPE_SWING_LEFT:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width, height / 2));
transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
transform = gsk_transform_rotate_3d (transform, -90 * (1.0 - priv->current_pos), graphene_vec3_y_axis ());
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (- child_width, - child_height / 2));
break;
case GTK_REVEALER_TRANSITION_TYPE_SWING_RIGHT:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (0, height / 2));
transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
transform = gsk_transform_rotate_3d (transform, 90 * (1.0 - priv->current_pos), graphene_vec3_y_axis ());
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (0, - child_height / 2));
break;
case GTK_REVEALER_TRANSITION_TYPE_SWING_DOWN:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width / 2, 0));
transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
transform = gsk_transform_rotate_3d (transform, -90 * (1.0 - priv->current_pos), graphene_vec3_x_axis ());
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (- child_width / 2, 0));
break;
case GTK_REVEALER_TRANSITION_TYPE_SWING_UP:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width / 2, height));
transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
transform = gsk_transform_rotate_3d (transform, 90 * (1.0 - priv->current_pos), graphene_vec3_x_axis ());
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (- child_width / 2, - child_height));
break;
case GTK_REVEALER_TRANSITION_TYPE_NONE:
case GTK_REVEALER_TRANSITION_TYPE_CROSSFADE:
case GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT:
case GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP:
default:
break;
}
gtk_widget_allocate (child, child_width, child_height, -1, transform);
gsk_transform_unref (transform);
gtk_widget_allocate (child, width, height, baseline, NULL);
return;
}
child_width = width;
child_height = height;
hscale = get_child_size_scale (revealer, GTK_ORIENTATION_HORIZONTAL);
vscale = get_child_size_scale (revealer, GTK_ORIENTATION_VERTICAL);
if (hscale <= 0 || vscale <= 0)
{
/* don't allocate anything, the child is invisible and the numbers
* don't make sense. */
return;
}
if (hscale < 1.0)
{
g_assert (vscale == 1.0);
child_width = MIN (G_MAXINT, ceil (width / hscale));
}
else if (vscale < 1.0)
{
child_height = MIN (G_MAXINT, ceil (height / vscale));
}
transform = NULL;
switch (effective_transition (revealer))
{
case GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width - child_width, 0));
break;
case GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (0, height - child_height));
case GTK_REVEALER_TRANSITION_TYPE_SWING_LEFT:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width, height / 2));
transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
transform = gsk_transform_rotate_3d (transform, -90 * (1.0 - priv->current_pos), graphene_vec3_y_axis ());
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (- child_width, - child_height / 2));
break;
case GTK_REVEALER_TRANSITION_TYPE_SWING_RIGHT:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (0, height / 2));
transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
transform = gsk_transform_rotate_3d (transform, 90 * (1.0 - priv->current_pos), graphene_vec3_y_axis ());
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (0, - child_height / 2));
break;
case GTK_REVEALER_TRANSITION_TYPE_SWING_DOWN:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width / 2, 0));
transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
transform = gsk_transform_rotate_3d (transform, -90 * (1.0 - priv->current_pos), graphene_vec3_x_axis ());
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (- child_width / 2, 0));
break;
case GTK_REVEALER_TRANSITION_TYPE_SWING_UP:
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width / 2, height));
transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
transform = gsk_transform_rotate_3d (transform, 90 * (1.0 - priv->current_pos), graphene_vec3_x_axis ());
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (- child_width / 2, - child_height));
break;
case GTK_REVEALER_TRANSITION_TYPE_NONE:
case GTK_REVEALER_TRANSITION_TYPE_CROSSFADE:
case GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT:
case GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP:
default:
break;
}
gtk_widget_allocate (child, child_width, child_height, -1, transform);
gsk_transform_unref (transform);
}
static void