diff --git a/src/hdy-leaflet.c b/src/hdy-leaflet.c index a686f2e27b48e879fae95515f8aac0162fe1a256..644b5964a5658c55e6f36e4c8f982200ddd1ad47 100644 --- a/src/hdy-leaflet.c +++ b/src/hdy-leaflet.c @@ -32,6 +32,21 @@ * sizes of the children. */ +/** + * HdyLeafletTransitionType: + * @HDY_LEAFLET_TRANSITION_TYPE_NONE: No transition + * @HDY_LEAFLET_TRANSITION_TYPE_SLIDE: Slide from left, right, up or down according to the orientation, text direction and the children order + * @HDY_LEAFLET_TRANSITION_TYPE_OVER: Cover the old page or uncover the new page, sliding from or towards the end according to orientation, text direction and children order + * @HDY_LEAFLET_TRANSITION_TYPE_UNDER: Uncover the new page or cover the old page, sliding from or towards the start according to orientation, text direction and children order + * + * This enumeration value describes the possible transitions between modes and + * children in a #HdyLeaflet widget. + * + * New values may be added to this enumeration over time. + * + * Since: 0.0.12 + */ + /** * HdyLeafletModeTransitionType: * @HDY_LEAFLET_MODE_TRANSITION_TYPE_NONE: No transition @@ -42,7 +57,7 @@ * These enumeration values describe the possible transitions between pages in a * #HdyLeaflet widget. * - * New values may be added to this enumeration over time. + * Deprecated: 0.0.12: Use #HdyLeafletTransitionType */ /** @@ -56,7 +71,7 @@ * These enumeration values describe the possible transitions between pages in a * #HdyLeaflet widget. * - * New values may be added to this enumeration over time. + * Deprecated: 0.0.12: Use #HdyLeafletTransitionType */ enum { @@ -69,6 +84,7 @@ enum { PROP_VHOMOGENEOUS_UNFOLDED, PROP_VISIBLE_CHILD, PROP_VISIBLE_CHILD_NAME, + PROP_TRANSITION_TYPE, PROP_MODE_TRANSITION_TYPE, PROP_MODE_TRANSITION_DURATION, PROP_CHILD_TRANSITION_TYPE, @@ -126,6 +142,8 @@ typedef struct gboolean move_bin_window_request; + HdyLeafletTransitionType transition_type; + struct { HdyLeafletModeTransitionType type; guint duration; @@ -679,6 +697,46 @@ hdy_leaflet_set_position (HdyLeaflet *self, /* g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CHILD_REVEALED]); */ } +/* As HdyLeafletModeTransitionType is an ABI compatible subset of + * HdyLeafletTransitionType, we can simply use HdyLeafletTransitionType + * internally for mode transitions. + */ +static HdyLeafletTransitionType +get_mode_transition_type (HdyLeaflet *self) +{ + HdyLeafletPrivate *priv = hdy_leaflet_get_instance_private (self); + + return priv->transition_type != HDY_LEAFLET_TRANSITION_TYPE_NONE ? + priv->transition_type : + (HdyLeafletTransitionType) priv->mode_transition.type; +} + +/* As HdyLeafletChildTransitionType contains more transitions than + * HdyLeafletTransitionType, and they aren't ABI compatible, it's simpler to use + * HdyLeafletChildTransitionType internally for child transition. + */ +static HdyLeafletChildTransitionType +get_old_child_transition_type (HdyLeaflet *self) +{ + HdyLeafletPrivate *priv = hdy_leaflet_get_instance_private (self); + + if (priv->transition_type == HDY_LEAFLET_TRANSITION_TYPE_NONE) + return priv->child_transition.type; + + switch (priv->transition_type) { + case HDY_LEAFLET_TRANSITION_TYPE_NONE: + return HDY_LEAFLET_CHILD_TRANSITION_TYPE_NONE; + case HDY_LEAFLET_TRANSITION_TYPE_SLIDE: + return HDY_LEAFLET_CHILD_TRANSITION_TYPE_SLIDE; + case HDY_LEAFLET_TRANSITION_TYPE_OVER: + return HDY_LEAFLET_CHILD_TRANSITION_TYPE_OVER; + case HDY_LEAFLET_TRANSITION_TYPE_UNDER: + return HDY_LEAFLET_CHILD_TRANSITION_TYPE_UNDER; + default: + g_assert_not_reached (); + } +} + static void hdy_leaflet_mode_progress_updated (HdyLeaflet *self) { @@ -730,7 +788,6 @@ hdy_leaflet_start_mode_transition (HdyLeaflet *self, { HdyLeafletPrivate *priv = hdy_leaflet_get_instance_private (self); GtkWidget *widget = GTK_WIDGET (self); - HdyLeafletModeTransitionType transition; if (priv->mode_transition.target_pos == target) return; @@ -741,10 +798,9 @@ hdy_leaflet_start_mode_transition (HdyLeaflet *self, hdy_leaflet_stop_child_transition (self); - transition = priv->mode_transition.type; if (gtk_widget_get_mapped (widget) && priv->mode_transition.duration != 0 && - transition != HDY_LEAFLET_MODE_TRANSITION_TYPE_NONE && + get_mode_transition_type (self) != HDY_LEAFLET_TRANSITION_TYPE_NONE && hdy_get_enable_animations (widget)) { priv->mode_transition.source_pos = priv->mode_transition.current_pos; if (priv->mode_transition.tick_id == 0) @@ -887,6 +943,61 @@ hdy_leaflet_get_homogeneous (HdyLeaflet *self, return priv->homogeneous[fold][orientation]; } +/** + * hdy_leaflet_get_transition_type: + * @self: a #HdyLeaflet + * + * Gets the type of animation that will be used + * for transitions between modes and children in @self. + * + * Returns: the current transition type of @self + * + * Since: 0.0.12 + */ +HdyLeafletTransitionType +hdy_leaflet_get_transition_type (HdyLeaflet *self) +{ + HdyLeafletPrivate *priv; + + g_return_val_if_fail (HDY_IS_LEAFLET (self), HDY_LEAFLET_TRANSITION_TYPE_NONE); + + priv = hdy_leaflet_get_instance_private (self); + + return priv->transition_type; +} + +/** + * hdy_leaflet_set_transition_type: + * @self: a #HdyLeaflet + * @transition: the new transition type + * + * Sets the type of animation that will be used for transitions between modes + * and children in @self. + * + * The transition type can be changed without problems at runtime, so it is + * possible to change the animation based on the mode or child that is about to + * become current. + * + * Since: 0.0.12 + */ +void +hdy_leaflet_set_transition_type (HdyLeaflet *self, + HdyLeafletTransitionType transition) +{ + HdyLeafletPrivate *priv; + + g_return_if_fail (HDY_IS_LEAFLET (self)); + + priv = hdy_leaflet_get_instance_private (self); + + if (priv->transition_type == transition) + return; + + priv->transition_type = transition; + g_object_notify_by_pspec (G_OBJECT (self), + props[PROP_TRANSITION_TYPE]); +} + /** * hdy_leaflet_get_mode_transition_type: * @self: a #HdyLeaflet @@ -895,6 +1006,8 @@ hdy_leaflet_get_homogeneous (HdyLeaflet *self, * for transitions between modes in @self. * * Returns: the current mode transition type of @self + * + * Deprecated: 0.0.12: Use hdy_leaflet_get_transition_type() */ HdyLeafletModeTransitionType hdy_leaflet_get_mode_transition_type (HdyLeaflet *self) @@ -919,6 +1032,8 @@ hdy_leaflet_get_mode_transition_type (HdyLeaflet *self) * The transition type can be changed without problems * at runtime, so it is possible to change the animation * based on the mode that is about to become current. + * + * Deprecated: 0.0.12: Use hdy_leaflet_set_transition_type() */ void hdy_leaflet_set_mode_transition_type (HdyLeaflet *self, @@ -990,9 +1105,11 @@ hdy_leaflet_set_mode_transition_duration (HdyLeaflet *self, * @self: a #HdyLeaflet * * Gets the type of animation that will be used - * for transitions between modes in @self. + * for transitions between children in @self. * * Returns: the current mode transition type of @self + * + * Deprecated: 0.0.12: Use hdy_leaflet_get_transition_type() */ HdyLeafletChildTransitionType hdy_leaflet_get_child_transition_type (HdyLeaflet *self) @@ -1016,7 +1133,9 @@ hdy_leaflet_get_child_transition_type (HdyLeaflet *self) * * The transition type can be changed without problems * at runtime, so it is possible to change the animation - * based on the mode that is about to become current. + * based on the child that is about to become current. + * + * Deprecated: 0.0.12: Use hdy_leaflet_set_transition_type() */ void hdy_leaflet_set_child_transition_type (HdyLeaflet *self, @@ -1124,7 +1243,7 @@ hdy_leaflet_set_visible_child (HdyLeaflet *self, g_return_if_fail (contains_child); - set_visible_child_info (self, child_info, priv->child_transition.type, priv->child_transition.duration); + set_visible_child_info (self, child_info, get_old_child_transition_type (self), priv->child_transition.duration); } const gchar * @@ -1160,7 +1279,7 @@ hdy_leaflet_set_visible_child_name (HdyLeaflet *self, g_return_if_fail (contains_child); - set_visible_child_info (self, child_info, priv->child_transition.type, priv->child_transition.duration); + set_visible_child_info (self, child_info, get_old_child_transition_type (self), priv->child_transition.duration); } /** @@ -1402,7 +1521,7 @@ hdy_leaflet_size_allocate_folded (GtkWidget *widget, gint current_pad; gint max_child_size = 0; gboolean box_homogeneous; - HdyLeafletModeTransitionType mode_transition_type; + HdyLeafletTransitionType mode_transition_type; GtkTextDirection direction; gboolean under; @@ -1431,14 +1550,14 @@ hdy_leaflet_size_allocate_folded (GtkWidget *widget, gtk_widget_set_child_visible (visible_child->widget, TRUE); - mode_transition_type = priv->mode_transition.type; + mode_transition_type = get_mode_transition_type (self); /* Avoid useless computations and allow visible child transitions. */ if (priv->mode_transition.current_pos <= 0.0) - mode_transition_type = HDY_LEAFLET_MODE_TRANSITION_TYPE_NONE; + mode_transition_type = HDY_LEAFLET_TRANSITION_TYPE_NONE; switch (mode_transition_type) { - case HDY_LEAFLET_MODE_TRANSITION_TYPE_NONE: + case HDY_LEAFLET_TRANSITION_TYPE_NONE: /* Child transitions should be applied only when folded and when no mode * transition is ongoing. */ @@ -1459,9 +1578,9 @@ hdy_leaflet_size_allocate_folded (GtkWidget *widget, } break; - case HDY_LEAFLET_MODE_TRANSITION_TYPE_SLIDE: - case HDY_LEAFLET_MODE_TRANSITION_TYPE_OVER: - case HDY_LEAFLET_MODE_TRANSITION_TYPE_UNDER: + case HDY_LEAFLET_TRANSITION_TYPE_SLIDE: + case HDY_LEAFLET_TRANSITION_TYPE_OVER: + case HDY_LEAFLET_TRANSITION_TYPE_UNDER: /* Compute visible child size. */ visible_size = orientation == GTK_ORIENTATION_HORIZONTAL ? @@ -1518,15 +1637,15 @@ hdy_leaflet_size_allocate_folded (GtkWidget *widget, switch (orientation) { case GTK_ORIENTATION_HORIZONTAL: direction = gtk_widget_get_direction (GTK_WIDGET (self)); - under = (mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_OVER && direction == GTK_TEXT_DIR_LTR) || - (mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_UNDER && direction == GTK_TEXT_DIR_RTL); + under = (mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_OVER && direction == GTK_TEXT_DIR_LTR) || + (mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_UNDER && direction == GTK_TEXT_DIR_RTL); priv->mode_transition.start_surface_allocation.width = under ? remaining_size : start_size; priv->mode_transition.start_surface_allocation.height = allocation->height; priv->mode_transition.start_surface_allocation.x = under ? 0 : remaining_start_size - start_size; priv->mode_transition.start_surface_allocation.y = 0; priv->mode_transition.start_progress = under ? (gdouble) remaining_size / start_size : 1; - under = (mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_UNDER && direction == GTK_TEXT_DIR_LTR) || - (mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_OVER && direction == GTK_TEXT_DIR_RTL); + under = (mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_UNDER && direction == GTK_TEXT_DIR_LTR) || + (mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_OVER && direction == GTK_TEXT_DIR_RTL); priv->mode_transition.end_surface_allocation.width = end_size; priv->mode_transition.end_surface_allocation.height = allocation->height; priv->mode_transition.end_surface_allocation.x = under ? allocation->width - end_size : remaining_start_size + visible_size; @@ -1538,13 +1657,13 @@ hdy_leaflet_size_allocate_folded (GtkWidget *widget, priv->mode_transition.end_progress = under ? (gdouble) remaining_end_size / end_size : 1; break; case GTK_ORIENTATION_VERTICAL: - under = mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_OVER; + under = mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_OVER; priv->mode_transition.start_surface_allocation.width = allocation->width; priv->mode_transition.start_surface_allocation.height = under ? remaining_size : start_size; priv->mode_transition.start_surface_allocation.x = 0; priv->mode_transition.start_surface_allocation.y = under ? 0 : remaining_start_size - start_size; priv->mode_transition.start_progress = under ? (gdouble) remaining_size / start_size : 1; - under = mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_UNDER; + under = mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_UNDER; priv->mode_transition.end_surface_allocation.width = allocation->width; priv->mode_transition.end_surface_allocation.height = end_size; priv->mode_transition.end_surface_allocation.x = 0; @@ -1671,7 +1790,7 @@ hdy_leaflet_size_allocate_unfolded (GtkWidget *widget, gint n_visible_children, n_expand_children; gint start_pad = 0, end_pad = 0; gboolean box_homogeneous; - HdyLeafletModeTransitionType mode_transition_type; + HdyLeafletTransitionType mode_transition_type; GtkTextDirection direction; gboolean under; @@ -1820,14 +1939,14 @@ hdy_leaflet_size_allocate_unfolded (GtkWidget *widget, priv->mode_transition.end_distance = allocation->height - (visible_child->alloc.y + visible_child->alloc.height); } - mode_transition_type = priv->mode_transition.type; + mode_transition_type = get_mode_transition_type (self); direction = gtk_widget_get_direction (GTK_WIDGET (self)); if (orientation == GTK_ORIENTATION_HORIZONTAL) - under = (mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_OVER && direction == GTK_TEXT_DIR_LTR) || - (mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_UNDER && direction == GTK_TEXT_DIR_RTL); + under = (mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_OVER && direction == GTK_TEXT_DIR_LTR) || + (mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_UNDER && direction == GTK_TEXT_DIR_RTL); else - under = mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_OVER; + under = mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_OVER; for (children = directed_children; children; children = children->next) { child_info = children->data; @@ -1849,10 +1968,10 @@ hdy_leaflet_size_allocate_unfolded (GtkWidget *widget, priv->mode_transition.start_progress = under ? priv->mode_transition.current_pos : 1; if (orientation == GTK_ORIENTATION_HORIZONTAL) - under = (mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_UNDER && direction == GTK_TEXT_DIR_LTR) || - (mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_OVER && direction == GTK_TEXT_DIR_RTL); + under = (mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_UNDER && direction == GTK_TEXT_DIR_LTR) || + (mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_OVER && direction == GTK_TEXT_DIR_RTL); else - under = mode_transition_type == HDY_LEAFLET_MODE_TRANSITION_TYPE_UNDER; + under = mode_transition_type == HDY_LEAFLET_TRANSITION_TYPE_UNDER; for (children = g_list_last (directed_children); children; children = children->prev) { child_info = children->data; @@ -2637,9 +2756,9 @@ hdy_leaflet_child_visibility_notify_cb (GObject *obj, child_info = find_child_info_for_widget (self, widget); if (priv->visible_child == NULL && gtk_widget_get_visible (widget)) - set_visible_child_info (self, child_info, priv->child_transition.type, priv->child_transition.duration); + set_visible_child_info (self, child_info, get_old_child_transition_type (self), priv->child_transition.duration); else if (priv->visible_child == child_info && !gtk_widget_get_visible (widget)) - set_visible_child_info (self, NULL, priv->child_transition.type, priv->child_transition.duration); + set_visible_child_info (self, NULL, get_old_child_transition_type (self), priv->child_transition.duration); } static void @@ -2675,7 +2794,7 @@ hdy_leaflet_add (GtkContainer *container, if (hdy_leaflet_get_visible_child (self) == NULL && gtk_widget_get_visible (widget)) - set_visible_child_info (self, child_info, priv->child_transition.type, priv->child_transition.duration); + set_visible_child_info (self, child_info, get_old_child_transition_type (self), priv->child_transition.duration); if (priv->fold == HDY_FOLD_UNFOLDED || (priv->fold == HDY_FOLD_FOLDED && (priv->homogeneous[HDY_FOLD_FOLDED][GTK_ORIENTATION_HORIZONTAL] || @@ -2703,7 +2822,7 @@ hdy_leaflet_remove (GtkContainer *container, free_child_info (child_info); if (hdy_leaflet_get_visible_child (self) == widget) - set_visible_child_info (self, NULL, priv->child_transition.type, priv->child_transition.duration); + set_visible_child_info (self, NULL, get_old_child_transition_type (self), priv->child_transition.duration); if (gtk_widget_get_visible (widget)) gtk_widget_queue_resize (GTK_WIDGET (container)); @@ -2772,6 +2891,9 @@ hdy_leaflet_get_property (GObject *object, case PROP_VISIBLE_CHILD_NAME: g_value_set_string (value, hdy_leaflet_get_visible_child_name (self)); break; + case PROP_TRANSITION_TYPE: + g_value_set_enum (value, hdy_leaflet_get_transition_type (self)); + break; case PROP_MODE_TRANSITION_TYPE: g_value_set_enum (value, hdy_leaflet_get_mode_transition_type (self)); break; @@ -2826,6 +2948,9 @@ hdy_leaflet_set_property (GObject *object, case PROP_VISIBLE_CHILD_NAME: hdy_leaflet_set_visible_child_name (self, g_value_get_string (value)); break; + case PROP_TRANSITION_TYPE: + hdy_leaflet_set_transition_type (self, g_value_get_enum (value)); + break; case PROP_MODE_TRANSITION_TYPE: hdy_leaflet_set_mode_transition_type (self, g_value_get_enum (value)); break; @@ -3185,6 +3310,25 @@ hdy_leaflet_class_init (HdyLeafletClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + /** + * HdyLeaflet:transition-type: + * + * The type of animation that will be used for transitions between modes and + * children. + * + * The transition type can be changed without problems at runtime, so it is + * possible to change the animation based on the mode or child that is about + * to become current. + * + * Since: 0.0.12 + */ + props[PROP_TRANSITION_TYPE] = + g_param_spec_enum ("transition-type", + _("Transition type"), + _("The type of animation used to transition between modes and children"), + HDY_TYPE_LEAFLET_TRANSITION_TYPE, HDY_LEAFLET_TRANSITION_TYPE_NONE, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + props[PROP_MODE_TRANSITION_TYPE] = g_param_spec_enum ("mode-transition-type", _("Mode transition type"), @@ -3262,6 +3406,7 @@ hdy_leaflet_init (HdyLeaflet *self) priv->homogeneous[HDY_FOLD_UNFOLDED][GTK_ORIENTATION_VERTICAL] = FALSE; priv->homogeneous[HDY_FOLD_FOLDED][GTK_ORIENTATION_HORIZONTAL] = TRUE; priv->homogeneous[HDY_FOLD_FOLDED][GTK_ORIENTATION_VERTICAL] = TRUE; + priv->transition_type = HDY_LEAFLET_TRANSITION_TYPE_NONE; priv->mode_transition.type = HDY_LEAFLET_MODE_TRANSITION_TYPE_NONE; priv->mode_transition.duration = 250; priv->child_transition.type = HDY_LEAFLET_CHILD_TRANSITION_TYPE_NONE; diff --git a/src/hdy-leaflet.h b/src/hdy-leaflet.h index 2d8d034584d818d50c0d967bdba3d1bd68dcdb19..a376930ef74e909a0672412b35856ffec8b32b61 100644 --- a/src/hdy-leaflet.h +++ b/src/hdy-leaflet.h @@ -11,6 +11,7 @@ #endif #include <gtk/gtk.h> +#include "hdy-deprecation-macros.h" #include "hdy-fold.h" #include "hdy-enums.h" @@ -20,6 +21,14 @@ G_BEGIN_DECLS G_DECLARE_DERIVABLE_TYPE (HdyLeaflet, hdy_leaflet, HDY, LEAFLET, GtkContainer) +typedef enum { + HDY_LEAFLET_TRANSITION_TYPE_NONE, + HDY_LEAFLET_TRANSITION_TYPE_SLIDE, + HDY_LEAFLET_TRANSITION_TYPE_OVER, + HDY_LEAFLET_TRANSITION_TYPE_UNDER, +} HdyLeafletTransitionType; + +_HDY_DEPRECATED typedef enum { HDY_LEAFLET_MODE_TRANSITION_TYPE_NONE, HDY_LEAFLET_MODE_TRANSITION_TYPE_SLIDE, @@ -27,6 +36,7 @@ typedef enum { HDY_LEAFLET_MODE_TRANSITION_TYPE_UNDER, } HdyLeafletModeTransitionType; +_HDY_DEPRECATED typedef enum { HDY_LEAFLET_CHILD_TRANSITION_TYPE_NONE, HDY_LEAFLET_CHILD_TRANSITION_TYPE_CROSSFADE, @@ -65,13 +75,20 @@ void hdy_leaflet_set_homogeneous (HdyLeaflet *self, HdyFold fold, GtkOrientation orientation, gboolean homogeneous); +HdyLeafletTransitionType hdy_leaflet_get_transition_type (HdyLeaflet *self); +void hdy_leaflet_set_transition_type (HdyLeaflet *self, + HdyLeafletTransitionType transition); +_HDY_DEPRECATED HdyLeafletModeTransitionType hdy_leaflet_get_mode_transition_type (HdyLeaflet *self); +_HDY_DEPRECATED void hdy_leaflet_set_mode_transition_type (HdyLeaflet *self, HdyLeafletModeTransitionType transition); guint hdy_leaflet_get_mode_transition_duration (HdyLeaflet *self); void hdy_leaflet_set_mode_transition_duration (HdyLeaflet *self, guint duration); +_HDY_DEPRECATED HdyLeafletChildTransitionType hdy_leaflet_get_child_transition_type (HdyLeaflet *self); +_HDY_DEPRECATED void hdy_leaflet_set_child_transition_type (HdyLeaflet *self, HdyLeafletChildTransitionType transition); guint hdy_leaflet_get_child_transition_duration (HdyLeaflet *self);