Skip to content

Commit bb05871

Browse files
committed
Add documentation and allow intermediate without gesture
1 parent a2ae8a5 commit bb05871

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

src/Gestures/PropertyGestureTransition.vala

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,42 @@
22

33

44
public class Gala.GesturePropertyTransition : Object {
5-
5+
/**
6+
* Emitted when all animations are finished that is when the property has reached the target value
7+
* either via gesture or via easing or combined.
8+
*/
69
public signal void done ();
710

11+
/**
12+
* The actor whose property will be animated.
13+
*/
814
public Clutter.Actor actor { get; construct; }
15+
916
public GestureTracker gesture_tracker { get; construct; }
17+
18+
/**
19+
* The property that will be animated. To be properly animated it has to be marked as
20+
* animatable in the Clutter documentation and should be numeric.
21+
*/
1022
public string property { get; construct; }
23+
24+
/**
25+
* The starting value of the animation or null to use the current value. The value
26+
* has to be of the same type as the property.
27+
*/
1128
public Value? from_value { get; construct set; }
29+
30+
/**
31+
* The value to animate to. It has to be of the same type as the property.
32+
*/
1233
public Value to_value { get; construct set; }
34+
35+
/**
36+
* If not null this can be used to have an intermediate step before animating back to the origin.
37+
* Therefore using this makes mostly sense if {@link to_value} equals {@link from_value}.
38+
* This is mostly used for the nudge animations when trying to switch workspaces where there isn't one anymore.
39+
*/
1340
public Value? intermediate_value { get; construct; }
14-
public bool reversed { get; construct set; default = false; }
1541

1642
public GesturePropertyTransition (
1743
Clutter.Actor actor,
@@ -31,17 +57,31 @@ public class Gala.GesturePropertyTransition : Object {
3157
);
3258
}
3359

60+
/**
61+
* Starts animating the property from {@link from_value} to {@link to_value}. If with_gesture is true
62+
* it will connect to the gesture trackers signals and animate according to the input finishing with an easing
63+
* to the final position. If with_gesture is false it will just ease to the {@link to_value}.
64+
*/
3465
public void start (bool with_gesture) {
66+
Value current_value = {};
67+
actor.get_property (property, ref current_value);
68+
3569
if (from_value == null) {
36-
Value current_value = {};
37-
actor.get_property (property, ref current_value);
3870
from_value = current_value;
3971

4072
ulong done_handler = 0;
4173
done_handler = done.connect (() => {
4274
from_value = null;
4375
disconnect (done_handler);
4476
});
77+
} else if (from_value.type () != current_value.type ()) {
78+
warning ("from_value of type %s is not of the same type as the property %s which is %s. Can't animate.", from_value.type_name (), property, current_value.type_name ());
79+
return;
80+
}
81+
82+
if (current_value.type () != to_value.type ()) {
83+
warning ("to_value of type %s is not of the same type as the property %s which is %s. Can't animate.", to_value.type_name (), property, current_value.type_name ());
84+
return;
4585
}
4686

4787
GestureTracker.OnBegin on_animation_begin = () => {
@@ -81,7 +121,22 @@ public class Gala.GesturePropertyTransition : Object {
81121
gesture_tracker.connect_handlers (on_animation_begin, on_animation_update, on_animation_end);
82122
} else {
83123
on_animation_begin (0);
84-
on_animation_end (1, false, gesture_tracker.min_animation_duration);
124+
if (intermediate_value != null) {
125+
actor.save_easing_state ();
126+
actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
127+
actor.set_easing_duration (gesture_tracker.min_animation_duration / 2);
128+
actor.set_property (property, intermediate_value);
129+
actor.restore_easing_state ();
130+
131+
unowned var transition = actor.get_transition (property);
132+
if (transition == null) {
133+
on_animation_end (1, false, gesture_tracker.min_animation_duration / 2);
134+
} else {
135+
transition.stopped.connect (() => on_animation_end (1, false, gesture_tracker.min_animation_duration / 2));
136+
}
137+
} else {
138+
on_animation_end (1, false, gesture_tracker.min_animation_duration);
139+
}
85140
}
86141
}
87142

@@ -98,6 +153,10 @@ public class Gala.GesturePropertyTransition : Object {
98153
return (float) val.get_uint ();
99154
}
100155

156+
if (val.holds (typeof (int))) {
157+
return (float) val.get_int ();
158+
}
159+
101160
critical ("Non numeric property specified");
102161
return 0;
103162
}

0 commit comments

Comments
 (0)