[libhandy/wip/haecker-felix/flap-widget] Fixes



commit 4abcfb07ca445faa857f035ddcbed985131301ad
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Nov 18 13:48:48 2020 +0500

    Fixes

 src/hdy-flap.c | 170 +++++++++++++++++++++++++++++++--------------------------
 src/hdy-flap.h |  12 ++--
 2 files changed, 100 insertions(+), 82 deletions(-)
---
diff --git a/src/hdy-flap.c b/src/hdy-flap.c
index ab93b371..aba6a02f 100644
--- a/src/hdy-flap.c
+++ b/src/hdy-flap.c
@@ -47,18 +47,20 @@ struct _HdyFlap
   gboolean locked;
   gboolean folded;
 
-  gint overlay_duration;
+  guint overlay_duration;
   gdouble overlay_progress;
   HdyAnimation *overlay_animation;
 
-  gint reveal_duration;
+  guint reveal_duration;
   gdouble reveal_progress;
   HdyAnimation *reveal_animation;
 
   GtkOrientation orientation;
 
   HdyShadowHelper *shadow_helper;
+
   HdySwipeTracker *tracker;
+  gboolean swipe_active;
 };
 
 static void hdy_flap_buildable_init (GtkBuildableIface *iface);
@@ -119,6 +121,15 @@ set_orientation (HdyFlap        *self,
   g_object_notify (G_OBJECT (self), "orientation");
 }
 
+static void
+set_reveal_progress (HdyFlap *self,
+                     gdouble  progress)
+{
+  self->reveal_progress = progress;
+
+  gtk_widget_queue_allocate (GTK_WIDGET (self));
+}
+
 static void
 overlay_animation_value_cb (gdouble  value,
                             HdyFlap *self)
@@ -157,9 +168,7 @@ static void
 reveal_animation_value_cb (gdouble  value,
                            HdyFlap *self)
 {
-  self->reveal_progress = value;
-
-  gtk_widget_queue_resize (GTK_WIDGET (self));
+  set_reveal_progress (self, value);
 }
 
 static void
@@ -189,43 +198,6 @@ animate_reveal (HdyFlap *self,
   hdy_animation_start (self->reveal_animation);
 }
 
-static gint
-adjust_for_overlay (HdyFlap *self,
-                    gint     value)
-{
-  gdouble progress = MIN (1 - self->overlay_progress, self->reveal_progress);
-
-  return (gint) round (value * progress);
-}
-
-static void
-begin_swipe_cb (HdySwipeTracker        *tracker,
-                HdyNavigationDirection  direction,
-                gboolean                direct,
-                HdyFlap                *self)
-{
-  if (self->reveal_animation)
-    hdy_animation_stop (self->reveal_animation);
-}
-
-static void
-update_swipe_cb (HdySwipeTracker *tracker,
-                 gdouble          progress,
-                 HdyFlap         *self)
-{
-  self->reveal_progress = progress;
-  gtk_widget_queue_allocate (GTK_WIDGET (self));
-}
-
-static void
-end_swipe_cb (HdySwipeTracker *tracker,
-              gint64           duration,
-              gdouble          to,
-              HdyFlap         *self)
-{
-  animate_reveal (self, to, duration);
-}
-
 static void
 set_folded (HdyFlap  *self,
             gboolean  folded)
@@ -258,13 +230,59 @@ set_reveal_flap (HdyFlap  *self,
 
   self->reveal_flap = reveal_flap;
 
-  animate_reveal (self, reveal_flap ? 1 : 0, duration);
+  if (!self->swipe_active) {
+    animate_reveal (self, reveal_flap ? 1 : 0, duration);
 
-  hdy_swipeable_emit_child_switched (HDY_SWIPEABLE (self), reveal_flap ? 1 : 0, duration);
+    if (emit_child_switched)
+      hdy_swipeable_emit_child_switched (HDY_SWIPEABLE (self), reveal_flap ? 1 : 0, duration);
+  }
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_REVEAL_FLAP]);
 }
 
+static gint
+adjust_for_overlay (HdyFlap *self,
+                    gint     value)
+{
+  gdouble progress = MIN (1 - self->overlay_progress, self->reveal_progress);
+
+  return (gint) round (value * progress);
+}
+
+static void
+begin_swipe_cb (HdySwipeTracker        *tracker,
+                HdyNavigationDirection  direction,
+                gboolean                direct,
+                HdyFlap                *self)
+{
+  if (self->reveal_animation)
+    hdy_animation_stop (self->reveal_animation);
+
+  self->swipe_active = TRUE;
+}
+
+static void
+update_swipe_cb (HdySwipeTracker *tracker,
+                 gdouble          progress,
+                 HdyFlap         *self)
+{
+  set_reveal_progress (self, progress);
+}
+
+static void
+end_swipe_cb (HdySwipeTracker *tracker,
+              gint64           duration,
+              gdouble          to,
+              HdyFlap         *self)
+{
+  self->swipe_active = FALSE;
+
+  if ((to > 0) == self->reveal_flap)
+    animate_reveal (self, to, duration);
+  else
+    set_reveal_flap (self, to > 0, duration, FALSE);
+}
+
 static gint
 get_flap_size (HdyFlap        *self,
                GtkAllocation  *widget_alloc,
@@ -531,6 +549,7 @@ hdy_flap_draw (GtkWidget *widget,
   HdyFlap *self = HDY_FLAP (widget);
   gint width, height;
   gint shadow_x = 0, shadow_y = 0;
+  gdouble progress;
   GtkPanDirection shadow_direction;
 
   width = gtk_widget_get_allocated_width (widget);
@@ -569,13 +588,15 @@ hdy_flap_draw (GtkWidget *widget,
                                 self->flap,
                                 cr);
 
-  cairo_save (cr);
-  cairo_translate (cr, shadow_x, shadow_y);
-  hdy_shadow_helper_draw_shadow (self->shadow_helper, cr,
-                                 width, height,
-                                 1 - MIN (self->reveal_progress, self->overlay_progress),
-                                 shadow_direction);
-  cairo_restore (cr);
+  progress = 1 - MIN (self->reveal_progress, self->overlay_progress);
+
+  if (progress < 1) {
+    cairo_save (cr);
+    cairo_translate (cr, shadow_x, shadow_y);
+    hdy_shadow_helper_draw_shadow (self->shadow_helper, cr, width, height,
+                                   progress, shadow_direction);
+    cairo_restore (cr);
+  }
 
   return GDK_EVENT_PROPAGATE;
 }
@@ -709,10 +730,10 @@ hdy_flap_get_property (GObject    *object,
     g_value_set_boolean (value, hdy_flap_get_folded (self));
     break;
   case PROP_OVERLAY_DURATION:
-    g_value_set_int (value, hdy_flap_get_overlay_duration(self));
+    g_value_set_uint (value, hdy_flap_get_overlay_duration (self));
     break;
   case PROP_REVEAL_DURATION:
-    g_value_set_int (value, hdy_flap_get_reveal_duration(self));
+    g_value_set_uint (value, hdy_flap_get_reveal_duration (self));
     break;
   case PROP_ORIENTATION:
     g_value_set_enum (value, self->orientation);
@@ -747,10 +768,10 @@ hdy_flap_set_property (GObject      *object,
     hdy_flap_set_locked (self, g_value_get_boolean (value));
     break;
   case PROP_OVERLAY_DURATION:
-    hdy_flap_set_overlay_duration (self, g_value_get_int (value));
+    hdy_flap_set_overlay_duration (self, g_value_get_uint (value));
     break;
   case PROP_REVEAL_DURATION:
-    hdy_flap_set_reveal_duration (self, g_value_get_int (value));
+    hdy_flap_set_reveal_duration (self, g_value_get_uint (value));
     break;
   case PROP_ORIENTATION:
     set_orientation (self, g_value_get_enum (value));
@@ -875,12 +896,12 @@ hdy_flap_class_init (HdyFlapClass *klass)
    * Since: 1.1
    */
   props[PROP_OVERLAY_DURATION] =
-    g_param_spec_int ("overlay-duration",
-                      _("Overlay Duration"),
-                      _("Overlay Duration"),
-                      0, G_MAXINT,
-                      250,
-                      G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+    g_param_spec_uint ("overlay-duration",
+                       _("Overlay Duration"),
+                       _("Overlay Duration"),
+                       0, G_MAXINT,
+                       250,
+                       G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
   /**
    * HdyFlap:reveal-duration:
@@ -888,12 +909,12 @@ hdy_flap_class_init (HdyFlapClass *klass)
    * Since: 1.1
    */
   props[PROP_REVEAL_DURATION] =
-    g_param_spec_int ("reveal-duration",
-                      _("Reveal Duration"),
-                      _("Reveal Duration"),
-                      0, G_MAXINT,
-                      250,
-                      G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+    g_param_spec_uint ("reveal-duration",
+                       _("Reveal Duration"),
+                       _("Reveal Duration"),
+                       0, G_MAXINT,
+                       250,
+                       G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
   g_object_class_install_properties (object_class, LAST_PROP, props);
 
@@ -1022,10 +1043,9 @@ hdy_flap_get_swipe_area (HdySwipeable           *swipeable,
   GtkAllocation alloc;
   gint width, height;
 
-  rect->x = 0;
-  rect->y = 0;
-
   if (!self->flap) {
+    rect->x = 0;
+    rect->y = 0;
     rect->width = 0;
     rect->height = 0;
 
@@ -1322,7 +1342,7 @@ hdy_flap_get_folded (HdyFlap *self)
  *
  * Since: 1.1
  */
-gint
+guint
 hdy_flap_get_overlay_duration (HdyFlap *self)
 {
   g_return_val_if_fail (HDY_IS_FLAP (self), 0);
@@ -1339,10 +1359,9 @@ hdy_flap_get_overlay_duration (HdyFlap *self)
  */
 void
 hdy_flap_set_overlay_duration (HdyFlap *self,
-                               gint     duration)
+                               guint    duration)
 {
   g_return_if_fail (HDY_IS_FLAP (self));
-  g_return_if_fail (duration >= 0);
 
   if (self->overlay_duration == duration)
     return;
@@ -1360,7 +1379,7 @@ hdy_flap_set_overlay_duration (HdyFlap *self,
  *
  * Since: 1.1
  */
-gint
+guint
 hdy_flap_get_reveal_duration (HdyFlap *self)
 {
   g_return_val_if_fail (HDY_IS_FLAP (self), 0);
@@ -1377,10 +1396,9 @@ hdy_flap_get_reveal_duration (HdyFlap *self)
  */
 void
 hdy_flap_set_reveal_duration (HdyFlap *self,
-                              gint     duration)
+                              guint    duration)
 {
   g_return_if_fail (HDY_IS_FLAP (self));
-  g_return_if_fail (duration >= 0);
 
   if (self->reveal_duration == duration)
     return;
diff --git a/src/hdy-flap.h b/src/hdy-flap.h
index 1a3109c1..6185630b 100644
--- a/src/hdy-flap.h
+++ b/src/hdy-flap.h
@@ -65,15 +65,15 @@ HDY_AVAILABLE_IN_1_1
 gboolean hdy_flap_get_folded (HdyFlap *self);
 
 HDY_AVAILABLE_IN_1_1
-gint hdy_flap_get_overlay_duration (HdyFlap *self);
+guint hdy_flap_get_overlay_duration (HdyFlap *self);
 HDY_AVAILABLE_IN_1_1
-void hdy_flap_set_overlay_duration (HdyFlap *self,
-                                    gint     duration);
+void  hdy_flap_set_overlay_duration (HdyFlap *self,
+                                     guint    duration);
 
 HDY_AVAILABLE_IN_1_1
-gint hdy_flap_get_reveal_duration (HdyFlap *self);
+guint hdy_flap_get_reveal_duration (HdyFlap *self);
 HDY_AVAILABLE_IN_1_1
-void hdy_flap_set_reveal_duration (HdyFlap *self,
-                                   gint     duration);
+void  hdy_flap_set_reveal_duration (HdyFlap *self,
+                                    guint    duration);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]