[gnome-shell/gbsneto/wiggle: 7/8] util: Add wiggle helper
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/gbsneto/wiggle: 7/8] util: Add wiggle helper
- Date: Fri, 18 Oct 2019 11:26:13 +0000 (UTC)
commit d0690c3952c096011cf74ac63c6bffd1845fd3fa
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Oct 17 12:26:04 2019 +0200
util: Add wiggle helper
Add Util.wiggle(), which accepts the wiggle offset, duration,
and number of times, as parameters.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/768
js/misc/util.js | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/js/misc/util.js b/js/misc/util.js
index db3742eb3d..541f1876bd 100644
--- a/js/misc/util.js
+++ b/js/misc/util.js
@@ -1,7 +1,7 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported findUrls, spawn, spawnCommandLine, spawnApp, trySpawnCommandLine,
formatTime, formatTimeSpan, createTimeLabel, insertSorted,
- makeCloseButton, ensureActorVisibleInScrollView */
+ makeCloseButton, ensureActorVisibleInScrollView, wiggle */
const { Clutter, Gio, GLib, GObject, Shell, St } = imports.gi;
const Gettext = imports.gettext;
@@ -429,3 +429,37 @@ function ensureActorVisibleInScrollView(scrollView, actor) {
duration: SCROLL_TIME
});
}
+
+function wiggle(actor, params) {
+ params = Params.parse(params, {
+ offset: 0,
+ duration: 0,
+ wiggleCount: 0,
+ });
+ actor.translation_x = 0;
+
+ // Accelerate before wiggling
+ actor.ease({
+ translation_x: -params.offset,
+ duration: params.duration,
+ mode: Clutter.AnimationMode.EASE_OUT_QUAD,
+ onComplete: () => {
+ // Wiggle
+ actor.ease({
+ translation_x: params.offset,
+ duration: params.duration,
+ mode: Clutter.AnimationMode.LINEAR,
+ repeatCount: params.wiggleCount,
+ autoReverse: true,
+ onComplete: () => {
+ // Decelerate and return to the original position
+ actor.ease({
+ translation_x: 0,
+ duration: params.duration,
+ mode: Clutter.AnimationMode.EASE_IN_QUAD,
+ });
+ }
+ });
+ }
+ });
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]