on xenial help sign in
hide tiles when they're either outside the screen on the right

or covered by other tiles on the left edge

commit78289a8af0bdc6c5cb6d05d7d91b26c8c37777e1 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 14 Jul 2014, 10:58 (12 years ago) parenta55b1f1
2 files changed+29−26
qml/Stages/PhoneStage.qml+13−2 qml/Stages/TransformedSpreadDelegate.qml+16−24
qml/Stages/PhoneStage.qml+13−2
@@ -197,7 +197,13 @@ Item {
197197 }
198198 spreadView.selectedIndex = index;
199199 root.fullscreen = ApplicationManager.get(index).fullscreen;
200− snapAnimation.targetContentX = -shift;
200+ // If we're not in full spread mode yet, always unwind to start pos
201+ // otherwise unwind up to progress 0 of the selected index
202+ if (spreadView.phase < 2) {
203+ snapAnimation.targetContentX = -shift;
204+ } else {
205+ snapAnimation.targetContentX = -shift + index * spreadView.tileDistance;
206+ }
201207 snapAnimation.start();
202208 }
203209
@@ -299,6 +305,11 @@ Item {
299305 if (behavioredIndex == 1 && spreadView.phase < 2) {
300306 tileProgress += spreadView.tileDistance / spreadView.width;
301307 }
308+ // Limiting progress to ~0 and 1.7 to avoid binding calculations when tiles are either
309+ // outside the screen on the right (progress < 0) or hidden by other tiles on the left
310+ // (> 1.7). Using 0.0001 to differentiate when a tile should still be visible (==0)
311+ // or we can hide it (< 0)
312+ tileProgress = Math.max(-0.0001, Math.min(1.7, tileProgress));
302313 return tileProgress;
303314 }
304315
@@ -366,7 +377,7 @@ Item {
366377 }
367378 if (dragging && attachedToView) {
368379 // Gesture recognized. Let's move the spreadView with the finger
369− spreadView.contentX = -touchX - spreadView.shift;
380+ spreadView.contentX = -touchX + spreadDragArea.width - spreadView.shift;
370381 }
371382 if (attachedToView && spreadView.shiftedContentX >= spreadView.width * spreadView.positionMarker3) {
372383 // We passed positionMarker3. Detach from spreadView and snap it.
qml/Stages/TransformedSpreadDelegate.qml+16−24
@@ -44,6 +44,9 @@ SpreadDelegate {
4444 property real startDistance: units.gu(5)
4545 property real endDistance: units.gu(.5)
4646
47+ // Hiding tiles when their progress is negative or reached the maximum
48+ visible: progress >= 0 && progress < 1.7
49+
4750 onSelectedChanged: {
4851 if (selected) {
4952 priv.snapshot();
@@ -106,16 +109,6 @@ SpreadDelegate {
106109 selectedTopMarginProgress = topMarginProgress;
107110 }
108111
109− // This calculates how much negative progress there can be if unwinding the spread completely
110− // the progress for each tile starts at 0 when it crosses the right edge, so the later a tile comes in,
111− // the bigger its negativeProgress can be.
112− property real negativeProgress: {
113− if (index == 1 && spreadView.phase < 2) {
114− return 0;
115− }
116− return -index * spreadView.tileDistance / spreadView.width;
117− }
118−
119112 function linearAnimation(startProgress, endProgress, startValue, endValue, progress) {
120113 // progress : progressDiff = value : valueDiff => value = progress * valueDiff / progressDiff
121114 return (progress - startProgress) * (endValue - startValue) / (endProgress - startProgress) + startValue;
@@ -127,22 +120,20 @@ SpreadDelegate {
127120 return helperEasingCurve.value * (endValue - startValue) + startValue;
128121 }
129122
130− property real animatedEndDistance: linearAnimation(0, 2, root.endDistance, 0, root.progress)
131−
132123 // The following blocks handle the animation of the tile in the spread.
133124 // At the beginning, each tile is attached at the right edge, outside the screen.
134125 // The progress for each tile starts at 0 and it reaches its end position at a progress of 1.
135− // The first phases are handled special for the first 2 tiles. as we do the alt-tab and snapping in there
136− // Once we reached phase 3, the animation is the same for all tiles.
137− // When a tile is selected, the animation state is snapshotted, and the spreadView is unwound (progress animates
138− // back to negativeProgress). All tiles are kept in place and faded out to 0 opacity except
126+ // The first phases are handled special for the first 2 tiles. as we do the alt-tab and snapping
127+ // in there. Once we reached phase 3, the animation is the same for all tiles.
128+ // When a tile is selected, the animation state is snapshotted, and the spreadView is unwound.
129+ // All tiles are kept in place and faded out to 0 opacity except
139130 // the selected tile, which is animated from the snapshotted position to be fullscreen.
140131
141132 property real xTranslate: {
142133 if (otherSelected) {
143134 if (spreadView.phase < 2 && index == 0) {
144− return linearAnimation(selectedProgress, negativeProgress,
145− selectedXTranslate, selectedXTranslate - spreadView.tileDistance, root.progress);
135+ return linearAnimation(selectedProgress, 0, selectedXTranslate,
136+ selectedXTranslate - spreadView.tileDistance, root.progress);
146137 }
147138
148139 return selectedXTranslate;
@@ -160,7 +151,7 @@ SpreadDelegate {
160151 // Apply the same animation as with the rest but add spreadView.width to align it with the others.
161152 return -easingCurve.value * spreadView.width + spreadView.width;
162153 } else if (priv.isSelected) {
163− return linearAnimation(selectedProgress, negativeProgress, selectedXTranslate, 0, root.progress);
154+ return linearAnimation(selectedProgress, 0, selectedXTranslate, 0, root.progress);
164155 }
165156
166157 case 1:
@@ -177,13 +168,14 @@ SpreadDelegate {
177168 if (priv.isSelected) {
178169 // Distance to left edge
179170 var targetTranslate = -spreadView.width - ((index - 1) * root.startDistance);
180− return linearAnimation(selectedProgress, negativeProgress,
171+ return linearAnimation(selectedProgress, 0,
181172 selectedXTranslate, targetTranslate, root.progress);
182173 }
183174
184175 // Fix it at the right edge...
185176 var rightEdgeOffset = -((index - 1) * root.startDistance);
186177 // ...and use our easing to move them to the left. Stop a bit earlier for each tile
178+ var animatedEndDistance = linearAnimation(0, 2, root.endDistance, 0, root.progress)
187179 return -easingCurve.value * spreadView.width + (index * animatedEndDistance) + rightEdgeOffset;
188180
189181 }
@@ -197,7 +189,7 @@ SpreadDelegate {
197189 return priv.selectedAngle;
198190 }
199191 if (priv.isSelected) {
200− return linearAnimation(selectedProgress, negativeProgress, selectedAngle, 0, root.progress);
192+ return linearAnimation(selectedProgress, 0, selectedAngle, 0, root.progress);
201193 }
202194 switch (index) {
203195 case 0:
@@ -229,7 +221,7 @@ SpreadDelegate {
229221 return priv.selectedScale;
230222 }
231223 if (priv.isSelected) {
232− return linearAnimation(selectedProgress, negativeProgress, selectedScale, 1, root.progress);
224+ return linearAnimation(selectedProgress, 0, selectedScale, 1, root.progress);
233225 }
234226
235227 switch (index) {
@@ -274,7 +266,7 @@ SpreadDelegate {
274266
275267 property real topMarginProgress: {
276268 if (priv.isSelected) {
277− return linearAnimation(selectedProgress, negativeProgress, selectedTopMarginProgress, 0, root.progress);
269+ return linearAnimation(selectedProgress, 0, selectedTopMarginProgress, 0, root.progress);
278270 }
279271
280272 switch (index) {
@@ -326,7 +318,7 @@ SpreadDelegate {
326318 id: easingCurve
327319 type: EasingCurve.OutSine
328320 period: 1 - spreadView.positionMarker2
329− progress: root.animatedProgress
321+ progress: root.progress
330322 }
331323
332324 // This is used as a calculation helper to figure values for progress other than the current one