summaryrefslogtreecommitdiff
path: root/gtk/gtkrevealer.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-03-09 14:44:06 +0100
committerBenjamin Otte <otte@redhat.com>2019-03-19 08:48:06 +0100
commit8f6a48832d1876644b3de4c5ea3b348bb1db77a0 (patch)
treee479cb5c3a4a7a965538c47c8395cce2a9f8b01d /gtk/gtkrevealer.c
parent658588dfe7159f99ede6bfaaa38d7f209d2b5a3f (diff)
downloadgtk+-8f6a48832d1876644b3de4c5ea3b348bb1db77a0.tar.gz
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.
Diffstat (limited to 'gtk/gtkrevealer.c')
-rw-r--r--gtk/gtkrevealer.c153
1 files changed, 79 insertions, 74 deletions
diff --git a/gtk/gtkrevealer.c b/gtk/gtkrevealer.c
index f594b11f63..6dc84603c8 100644
--- a/gtk/gtkrevealer.c
+++ b/gtk/gtkrevealer.c
@@ -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)
+ {
+ 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)
{
- 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);
+ 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