Commit fda3d6a6 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko
Browse files

swipeable: Use HdyNavigationDirection for begin_swipe() direction



Update HdySwipeTracker, HdySwipeGroup, HdyCarousel and HdyLeaflet to
reflect this change.
Signed-off-by: Alexander Mikhaylenko's avatarAlexander Mikhaylenko <alexm@gnome.org>
parent 5c80f4ba
......@@ -10,6 +10,7 @@
#include "hdy-carousel.h"
#include "hdy-carousel-box-private.h"
#include "hdy-navigation-direction.h"
#include "hdy-swipe-tracker-private.h"
#include "hdy-swipeable-private.h"
......@@ -119,9 +120,9 @@ hdy_carousel_switch_child (HdySwipeable *swipeable,
}
static void
hdy_carousel_begin_swipe (HdySwipeable *swipeable,
gint direction,
gboolean direct)
hdy_carousel_begin_swipe (HdySwipeable *swipeable,
HdyNavigationDirection direction,
gboolean direct)
{
HdyCarousel *self = HDY_CAROUSEL (swipeable);
gdouble distance, position, closest_point;
......
......@@ -3212,8 +3212,8 @@ hdy_leaflet_switch_child (HdySwipeable *swipeable,
}
static HdyLeafletChildInfo *
find_swipeable_child (HdyLeaflet *self,
gint direction)
find_swipeable_child (HdyLeaflet *self,
HdyNavigationDirection direction)
{
HdyLeafletPrivate *priv;
GList *children;
......@@ -3223,7 +3223,7 @@ find_swipeable_child (HdyLeaflet *self,
children = g_list_find (priv->children, priv->visible_child);
do {
children = (direction < 0) ? children->prev : children->next;
children = (direction == HDY_NAVIGATION_DIRECTION_BACK) ? children->prev : children->next;
if (children == NULL)
break;
......@@ -3234,6 +3234,22 @@ find_swipeable_child (HdyLeaflet *self,
return child;
}
static gboolean
can_swipe_in_direction (HdyLeaflet *self,
HdyNavigationDirection direction)
{
HdyLeafletPrivate *priv = hdy_leaflet_get_instance_private (self);
switch (direction) {
case HDY_NAVIGATION_DIRECTION_BACK:
return priv->child_transition.can_swipe_back;
case HDY_NAVIGATION_DIRECTION_FORWARD:
return priv->child_transition.can_swipe_forward;
default:
g_assert_not_reached ();
}
}
static double
get_current_progress (HdyLeaflet *self)
{
......@@ -3259,9 +3275,9 @@ get_current_progress (HdyLeaflet *self)
}
static void
hdy_leaflet_begin_swipe (HdySwipeable *swipeable,
gint direction,
gboolean direct)
hdy_leaflet_begin_swipe (HdySwipeable *swipeable,
HdyNavigationDirection direction,
gboolean direct)
{
HdyLeaflet *self = HDY_LEAFLET (swipeable);
HdyLeafletPrivate *priv = hdy_leaflet_get_instance_private (self);
......@@ -3274,32 +3290,35 @@ hdy_leaflet_begin_swipe (HdySwipeable *swipeable,
distance = gtk_widget_get_allocated_height (GTK_WIDGET (self));
if (priv->child_transition.tick_id > 0) {
gint current_direction;
gboolean is_rtl;
gboolean is_rtl =
(gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL);
is_rtl = (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL);
n = 2;
points = g_new0 (gdouble, n);
switch (priv->child_transition.active_direction) {
case GTK_PAN_DIRECTION_UP:
current_direction = 1;
points[1] = 1;
break;
case GTK_PAN_DIRECTION_DOWN:
current_direction = -1;
points[0] = -1;
break;
case GTK_PAN_DIRECTION_LEFT:
current_direction = is_rtl ? -1 : 1;
if (is_rtl)
points[0] = -1;
else
points[1] = 1;
break;
case GTK_PAN_DIRECTION_RIGHT:
current_direction = is_rtl ? 1 : -1;
if (is_rtl)
points[1] = 1;
else
points[0] = -1;
break;
default:
g_assert_not_reached ();
}
n = 2;
points = g_new0 (gdouble, n);
points[current_direction > 0 ? 1 : 0] = current_direction;
progress = get_current_progress (self);
gtk_widget_remove_tick_callback (GTK_WIDGET (self), priv->child_transition.tick_id);
......@@ -3309,9 +3328,7 @@ hdy_leaflet_begin_swipe (HdySwipeable *swipeable,
} else {
HdyLeafletChildInfo *child;
if (((direction < 0 && priv->child_transition.can_swipe_back) ||
(direction > 0 && priv->child_transition.can_swipe_forward) ||
!direct) && priv->folded)
if ((can_swipe_in_direction (self, direction) || !direct) && priv->folded)
child = find_swipeable_child (self, direction);
else
child = NULL;
......@@ -3329,7 +3346,16 @@ hdy_leaflet_begin_swipe (HdySwipeable *swipeable,
n = child ? 2 : 1;
points = g_new0 (gdouble, n);
if (child)
points[direction > 0 ? 1 : 0] = direction;
switch (direction) {
case HDY_NAVIGATION_DIRECTION_BACK:
points[0] = -1;
break;
case HDY_NAVIGATION_DIRECTION_FORWARD:
points[1] = 1;
break;
default:
g_assert_not_reached ();
}
}
hdy_swipe_tracker_confirm_swipe (priv->tracker, distance, points, n, progress, 0);
......
......@@ -8,6 +8,7 @@
#include "hdy-swipe-group.h"
#include <gtk/gtk.h>
#include "hdy-navigation-direction.h"
#include "hdy-swipeable-private.h"
#define BUILDABLE_TAG_OBJECT "object"
......@@ -117,9 +118,9 @@ switch_child_cb (HdySwipeGroup *self,
}
static void
begin_swipe_cb (HdySwipeGroup *self,
gint direction,
HdySwipeable *swipeable)
begin_swipe_cb (HdySwipeGroup *self,
HdyNavigationDirection direction,
HdySwipeable *swipeable)
{
GSList *swipeables;
......
......@@ -8,6 +8,7 @@
#include <glib/gi18n-lib.h>
#include "hdy-swipe-tracker-private.h"
#include "hdy-navigation-direction.h"
#include <math.h>
......@@ -142,8 +143,8 @@ reset (HdySwipeTracker *self)
}
static void
gesture_prepare (HdySwipeTracker *self,
gint direction)
gesture_prepare (HdySwipeTracker *self,
HdyNavigationDirection direction)
{
if (self->state != HDY_SWIPE_TRACKER_STATE_NONE)
return;
......@@ -319,7 +320,7 @@ drag_update_cb (HdySwipeTracker *self,
if (self->state == HDY_SWIPE_TRACKER_STATE_NONE) {
if (is_vertical == is_offset_vertical)
gesture_prepare (self, offset > 0 ? 1 : -1);
gesture_prepare (self, offset > 0 ? HDY_NAVIGATION_DIRECTION_FORWARD : HDY_NAVIGATION_DIRECTION_BACK);
else
gtk_gesture_set_state (self->touch_gesture, GTK_EVENT_SEQUENCE_DENIED);
return;
......@@ -418,7 +419,7 @@ captured_scroll_event (HdySwipeTracker *self,
return GDK_EVENT_PROPAGATE;
if (is_vertical == is_delta_vertical)
gesture_prepare (self, delta > 0 ? 1 : -1);
gesture_prepare (self, delta > 0 ? HDY_NAVIGATION_DIRECTION_FORWARD : HDY_NAVIGATION_DIRECTION_BACK);
else {
self->is_scrolling = TRUE;
return GDK_EVENT_PROPAGATE;
......
......@@ -14,9 +14,9 @@ G_BEGIN_DECLS
void hdy_swipeable_switch_child (HdySwipeable *self,
guint index,
gint64 duration);
void hdy_swipeable_begin_swipe (HdySwipeable *self,
gint direction,
gboolean direct);
void hdy_swipeable_begin_swipe (HdySwipeable *self,
HdyNavigationDirection direction,
gboolean direct);
void hdy_swipeable_update_swipe (HdySwipeable *self,
gdouble value);
void hdy_swipeable_end_swipe (HdySwipeable *self,
......
......@@ -79,7 +79,7 @@ hdy_swipeable_default_init (HdySwipeableInterface *iface)
NULL, NULL, NULL,
G_TYPE_NONE,
1,
G_TYPE_INT);
HDY_TYPE_NAVIGATION_DIRECTION);
/**
* HdySwipeable::update-swipe:
......@@ -151,7 +151,7 @@ hdy_swipeable_switch_child (HdySwipeable *self,
/**
* hdy_swipeable_begin_swipe:
* @self: a #HdySwipeable
* @direction: The direction of the swipe, can be 1 or -1
* @direction: The direction of the swipe
* @direct: %TRUE if the swipe is directly triggered by a gesture,
* %FALSE if it's triggered via a #HdySwipeGroup
*
......@@ -168,9 +168,9 @@ hdy_swipeable_switch_child (HdySwipeable *self,
* Since: 0.0.12
*/
void
hdy_swipeable_begin_swipe (HdySwipeable *self,
gint direction,
gboolean direct)
hdy_swipeable_begin_swipe (HdySwipeable *self,
HdyNavigationDirection direction,
gboolean direct)
{
HdySwipeableInterface *iface;
......
......@@ -7,6 +7,7 @@
#pragma once
#include <gtk/gtk.h>
#include "hdy-navigation-direction.h"
G_BEGIN_DECLS
......@@ -33,9 +34,9 @@ struct _HdySwipeableInterface
void (*switch_child) (HdySwipeable *self,
guint index,
gint64 duration);
void (*begin_swipe) (HdySwipeable *self,
gint direction,
gboolean direct);
void (*begin_swipe) (HdySwipeable *self,
HdyNavigationDirection direction,
gboolean direct);
void (*update_swipe) (HdySwipeable *self,
gdouble value);
void (*end_swipe) (HdySwipeable *self,
......
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