smoother animations
This commit is contained in:
1 parent
bcf70106e2
commit
f67d7f1c55
6 files changed
+357
-156
No files matched your search
@@ -68,7 +68,7 @@ Item {
|
||||
const keys = parsed.keys ?? {};
|
||||
const hints = parsed.hints ?? {};
|
||||
root.renameKey = root.keyOr(keys.rename, "Ctrl+N", "keys.rename");
|
||||
root.windowsKey = root.keyOr(keys.windows, "Ctrl+G", "keys.windows");
|
||||
root.windowsKey = root.keyOr(keys.windows, "Tab", "keys.windows");
|
||||
root.showHints = root.boolOr(hints.show, true, "hints.show");
|
||||
root.renameHint = root.textOr(hints.rename, "{key}: to switch here", "hints.rename");
|
||||
root.windowsHint = root.textOr(hints.windows, "{key}: to see windows", "hints.windows");
|
||||
|
||||
@@ -198,6 +198,7 @@ PanelWindow {
|
||||
const ws = root.selectedWorkspace();
|
||||
if (!ws || ws === before)
|
||||
return;
|
||||
windowLoop.holdLeaving();
|
||||
root.loopWorkspaceId = ws.id;
|
||||
windowLoop.switchIn(delta);
|
||||
}
|
||||
|
||||
@@ -135,8 +135,20 @@ QtObject {
|
||||
|
||||
readonly property int loopTurnDuration: 320
|
||||
|
||||
// When Up/Down switch workspaces inside the loop, the new windows slide
|
||||
// in from this far away and fade up.
|
||||
// When Up/Down switch workspaces inside the loop, the old windows fold
|
||||
// into a small box that slides away, and the new ones slide in as a box
|
||||
// from this far away and open out.
|
||||
readonly property real loopSwitchOffset: 160
|
||||
readonly property int loopSwitchDuration: 260
|
||||
readonly property int loopSwitchDuration: 400
|
||||
readonly property int loopCollapseDuration: 300
|
||||
// Size of that box, next to a full window. It stays at least as big as
|
||||
// the workspace cards right above and below the loop.
|
||||
readonly property real loopBoxScale: {
|
||||
const shrink = 1 - Math.min(carouselScaleStep, carouselMaxScaleReduction);
|
||||
return Math.max(cardWidth * shrink / loopCardWidth, cardHeight * shrink / loopCardHeight);
|
||||
}
|
||||
// The new windows start opening this long after the old ones start folding.
|
||||
readonly property int loopExpandDelay: 150
|
||||
// A window preview grows out from its icon once the picture is ready.
|
||||
readonly property int loopPreviewGrowDuration: 700
|
||||
}
|
||||
@@ -21,10 +21,16 @@ Rectangle {
|
||||
required property string previewFile
|
||||
// Changes whenever the screenshot files are rewritten.
|
||||
required property int previewVersion
|
||||
// Grow the preview out from the icon once it is ready.
|
||||
required property bool growPreview
|
||||
|
||||
signal activated
|
||||
|
||||
readonly property string iconSource: Quickshell.iconPath(root.app, "application-x-executable")
|
||||
readonly property bool hasLive: root.toplevel !== null && liveView.hasContent
|
||||
readonly property bool hasShot: shotView.status === Image.Ready
|
||||
// A picture is showing, live or still.
|
||||
readonly property bool hasPicture: root.hasLive || root.hasShot
|
||||
|
||||
width: root.theme.loopCardWidth
|
||||
height: root.theme.loopCardHeight
|
||||
@@ -45,35 +51,64 @@ Rectangle {
|
||||
color: root.theme.loopPreviewBg
|
||||
clip: true
|
||||
|
||||
ScreencopyView {
|
||||
id: liveView
|
||||
// Holds the live view and the snapshot. Once a picture is ready it
|
||||
// grows out from the icon's size to fill the preview area.
|
||||
Item {
|
||||
id: picture
|
||||
|
||||
// Keeps the window's own shape inside the preview area.
|
||||
readonly property real aspect: liveView.sourceSize.height > 0 ? liveView.sourceSize.width / liveView.sourceSize.height : 16 / 9
|
||||
// Size of the icon next to the full preview area.
|
||||
readonly property real startScale: previewArea.width > 0 ? Math.min(1, root.theme.loopIconSize / previewArea.width) : 1
|
||||
|
||||
anchors.centerIn: parent
|
||||
width: Math.min(parent.width, parent.height * liveView.aspect)
|
||||
height: liveView.width / liveView.aspect
|
||||
captureSource: root.live ? root.toplevel : null
|
||||
live: true
|
||||
visible: root.toplevel !== null && liveView.hasContent
|
||||
}
|
||||
|
||||
Image {
|
||||
id: shotView
|
||||
anchors.fill: parent
|
||||
source: root.previewFile.length > 0 ? "file://" + root.previewFile + "?v=" + root.previewVersion : ""
|
||||
// The file is rewritten in place, so never reuse an old copy.
|
||||
cache: false
|
||||
asynchronous: true
|
||||
sourceSize.width: root.theme.loopCardWidth * 2
|
||||
fillMode: Image.PreserveAspectFit
|
||||
smooth: true
|
||||
mipmap: true
|
||||
visible: shotView.status === Image.Ready
|
||||
scale: root.hasPicture ? 1 : picture.startScale
|
||||
opacity: root.hasPicture ? 1 : 0
|
||||
|
||||
Behavior on scale {
|
||||
enabled: root.growPreview
|
||||
NumberAnimation {
|
||||
duration: root.theme.loopPreviewGrowDuration
|
||||
easing.type: Easing.InOutCubic
|
||||
}
|
||||
}
|
||||
Behavior on opacity {
|
||||
enabled: root.growPreview
|
||||
NumberAnimation {
|
||||
duration: root.theme.loopPreviewGrowDuration
|
||||
easing.type: Easing.InOutCubic
|
||||
}
|
||||
}
|
||||
|
||||
ScreencopyView {
|
||||
id: liveView
|
||||
|
||||
// Keeps the window's own shape inside the preview area.
|
||||
readonly property real aspect: liveView.sourceSize.height > 0 ? liveView.sourceSize.width / liveView.sourceSize.height : 16 / 9
|
||||
|
||||
anchors.centerIn: parent
|
||||
width: Math.min(parent.width, parent.height * liveView.aspect)
|
||||
height: liveView.width / liveView.aspect
|
||||
captureSource: root.live ? root.toplevel : null
|
||||
live: true
|
||||
visible: root.hasLive
|
||||
}
|
||||
|
||||
Image {
|
||||
id: shotView
|
||||
anchors.fill: parent
|
||||
source: root.previewFile.length > 0 ? "file://" + root.previewFile + "?v=" + root.previewVersion : ""
|
||||
// The file is rewritten in place, so never reuse an old copy.
|
||||
cache: false
|
||||
asynchronous: true
|
||||
sourceSize.width: root.theme.loopCardWidth * 2
|
||||
fillMode: Image.PreserveAspectFit
|
||||
smooth: true
|
||||
mipmap: true
|
||||
visible: root.hasShot
|
||||
}
|
||||
}
|
||||
|
||||
Image {
|
||||
id: previewIcon
|
||||
anchors.centerIn: parent
|
||||
width: root.theme.loopIconSize
|
||||
height: root.theme.loopIconSize
|
||||
@@ -83,7 +118,17 @@ Rectangle {
|
||||
fillMode: Image.PreserveAspectFit
|
||||
smooth: true
|
||||
mipmap: true
|
||||
visible: !liveView.visible && !shotView.visible
|
||||
// Fades out as the picture grows in.
|
||||
opacity: root.hasPicture ? 0 : 1
|
||||
visible: previewIcon.opacity > 0
|
||||
|
||||
Behavior on opacity {
|
||||
enabled: root.growPreview
|
||||
NumberAnimation {
|
||||
duration: root.theme.loopPreviewGrowDuration
|
||||
easing.type: Easing.InOutCubic
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+127
-128
@@ -12,7 +12,7 @@ Item {
|
||||
required property int workspaceId
|
||||
// Shown and taking input. Fades and grows in when this turns on.
|
||||
required property bool expanded
|
||||
// Shown on the top edge of the front window, "" for none.
|
||||
// Shown under the front window, "" for none.
|
||||
required property string exitHint
|
||||
|
||||
// A window was focused.
|
||||
@@ -25,56 +25,36 @@ Item {
|
||||
}
|
||||
|
||||
readonly property int count: root.windows.length
|
||||
// Angle between two neighbours on the loop.
|
||||
readonly property real angleStep: root.count > 0 ? 2 * Math.PI / root.count : 0
|
||||
// The loop is as long as the cards side by side, within limits.
|
||||
readonly property real radius: {
|
||||
const natural = root.count * (root.theme.loopCardWidth + root.theme.loopCardGap) / (2 * Math.PI);
|
||||
const widest = root.width * root.theme.loopMaxRadiusShare;
|
||||
return Math.max(root.theme.loopMinRadius, Math.min(natural, widest));
|
||||
}
|
||||
|
||||
// About how far the loop reaches sideways from its center, card edges
|
||||
// included. Sampled over the front half so it stays still while turning.
|
||||
readonly property real reachX: {
|
||||
const half = root.theme.loopCardWidth / 2;
|
||||
if (root.count <= 1)
|
||||
return half;
|
||||
const focal = root.theme.loopFocalLength;
|
||||
let widest = half;
|
||||
for (let i = 1; i <= 16; i++) {
|
||||
const angle = i / 16 * Math.PI / 2;
|
||||
const depthScale = focal / (focal + root.radius * (1 - Math.cos(angle)));
|
||||
const faceWidth = Math.abs(Math.cos(root.faceTurn(angle) * Math.PI / 180));
|
||||
const edge = (root.radius * Math.sin(angle) + half * faceWidth) * depthScale;
|
||||
widest = Math.max(widest, edge);
|
||||
}
|
||||
return widest;
|
||||
}
|
||||
// included.
|
||||
readonly property real reachX: ring.reachX
|
||||
|
||||
// Top and bottom edges of the front window, from the middle of the view.
|
||||
readonly property real frontTop: root.theme.loopBackLift / 2 - root.theme.loopCardHeight / 2
|
||||
readonly property real frontBottom: root.theme.loopBackLift / 2 + root.theme.loopCardHeight / 2
|
||||
|
||||
// Where round the loop, in degrees, cards turn edge-on. Halfway between
|
||||
// two cards, so none rests edge-on.
|
||||
readonly property real flipAngle: {
|
||||
if (root.count <= 1)
|
||||
return 90;
|
||||
const stepDegrees = 360 / root.count;
|
||||
const flip = (Math.floor(root.theme.loopFlipAngle / stepDegrees) + 0.5) * stepDegrees;
|
||||
return Math.min(flip, 180);
|
||||
}
|
||||
|
||||
// Selected step. It is not wrapped, so the loop can keep turning the
|
||||
// same way. Use selectedIndex for the position in the window list.
|
||||
property int targetStep: 0
|
||||
// Follows targetStep smoothly and drives every card position.
|
||||
property real turn: 0
|
||||
property bool animate: false
|
||||
// Offset and fade of the loop while it slides in after a workspace switch.
|
||||
// Offset, fade and fold of the loop while it opens after a workspace switch.
|
||||
property real slideY: 0
|
||||
property real switchFade: 1
|
||||
property real gather: 0
|
||||
|
||||
// The old windows, kept while they fold away after a workspace switch.
|
||||
// From parsed JSON, so this stays untyped.
|
||||
property var leavingWindows: []
|
||||
property real leavingTurn: 0
|
||||
property int leavingIndex: 0
|
||||
property real leavingY: 0
|
||||
property real leavingFade: 0
|
||||
property real leavingGather: 0
|
||||
// Where the old windows slide to as they fold.
|
||||
property real leavingTo: 0
|
||||
|
||||
readonly property int selectedIndex: root.wrapIndex(root.targetStep)
|
||||
|
||||
@@ -105,18 +85,56 @@ Item {
|
||||
ParallelAnimation {
|
||||
id: switchAnim
|
||||
|
||||
// The old windows fold into a box, which slides away and fades.
|
||||
NumberAnimation {
|
||||
target: root
|
||||
property: "slideY"
|
||||
to: 0
|
||||
duration: root.theme.loopSwitchDuration
|
||||
property: "leavingGather"
|
||||
to: 1
|
||||
duration: root.theme.loopCollapseDuration
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
NumberAnimation {
|
||||
target: root
|
||||
property: "switchFade"
|
||||
to: 1
|
||||
duration: root.theme.loopSwitchDuration
|
||||
property: "leavingY"
|
||||
to: root.leavingTo
|
||||
duration: root.theme.loopCollapseDuration
|
||||
easing.type: Easing.InCubic
|
||||
}
|
||||
NumberAnimation {
|
||||
target: root
|
||||
property: "leavingFade"
|
||||
to: 0
|
||||
duration: root.theme.loopCollapseDuration
|
||||
easing.type: Easing.InQuad
|
||||
}
|
||||
|
||||
// A little later, the new windows slide in as a box and open out.
|
||||
SequentialAnimation {
|
||||
PauseAnimation {
|
||||
duration: root.theme.loopExpandDelay
|
||||
}
|
||||
ParallelAnimation {
|
||||
NumberAnimation {
|
||||
target: root
|
||||
property: "slideY"
|
||||
to: 0
|
||||
duration: root.theme.loopSwitchDuration
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
NumberAnimation {
|
||||
target: root
|
||||
property: "switchFade"
|
||||
to: 1
|
||||
duration: root.theme.loopSwitchDuration
|
||||
}
|
||||
NumberAnimation {
|
||||
target: root
|
||||
property: "gather"
|
||||
to: 0
|
||||
duration: root.theme.loopSwitchDuration
|
||||
easing.type: Easing.InOutCubic
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,31 +144,6 @@ Item {
|
||||
return ((step % root.count) + root.count) % root.count;
|
||||
}
|
||||
|
||||
// Angle of a card from the front, in radians, between -pi and pi.
|
||||
function angleOf(index: int): real {
|
||||
if (root.count === 0)
|
||||
return 0;
|
||||
let steps = (index - root.turn) % root.count;
|
||||
if (steps < 0)
|
||||
steps += root.count;
|
||||
if (steps > root.count / 2)
|
||||
steps -= root.count;
|
||||
return steps * root.angleStep;
|
||||
}
|
||||
|
||||
// How far a card at this angle (radians) turns, in degrees. It turns
|
||||
// from facing the viewer at the front to edge-on at flipAngle, then on
|
||||
// round to face the viewer again at the back, showing its inner face.
|
||||
function faceTurn(angle: real): real {
|
||||
const degrees = Math.abs(angle) * 180 / Math.PI;
|
||||
const side = angle < 0 ? -1 : 1;
|
||||
const flip = root.flipAngle;
|
||||
if (degrees <= flip || flip >= 180)
|
||||
return -side * 90 * degrees / flip;
|
||||
const turn = 90 + 90 * (degrees - flip) / (180 - flip);
|
||||
return -side * (turn - 180);
|
||||
}
|
||||
|
||||
// Select the focused window, or the first one, and turn into place.
|
||||
function seed(): void {
|
||||
const list = root.windows;
|
||||
@@ -164,12 +157,27 @@ Item {
|
||||
root.compositor.takeScreenshots(list.map(w => w.key));
|
||||
}
|
||||
|
||||
// Keep the shown windows, as they are now, so they can fold away.
|
||||
// Call just before the workspace changes.
|
||||
function holdLeaving(): void {
|
||||
switchAnim.stop();
|
||||
root.leavingWindows = root.windows;
|
||||
root.leavingTurn = root.turn;
|
||||
root.leavingIndex = root.selectedIndex;
|
||||
root.leavingY = root.slideY;
|
||||
root.leavingFade = root.switchFade;
|
||||
root.leavingGather = root.gather;
|
||||
}
|
||||
|
||||
// Show another workspace. The new windows slide in from below when
|
||||
// direction is positive, from above when negative.
|
||||
// direction is positive, from above when negative, and the old ones
|
||||
// slide out the other way.
|
||||
function switchIn(direction: int): void {
|
||||
switchAnim.stop();
|
||||
root.leavingTo = -direction * root.theme.loopSwitchOffset;
|
||||
root.slideY = direction * root.theme.loopSwitchOffset;
|
||||
root.switchFade = 0;
|
||||
root.gather = 1;
|
||||
root.seed();
|
||||
switchAnim.start();
|
||||
}
|
||||
@@ -209,70 +217,61 @@ Item {
|
||||
Item {
|
||||
id: stage
|
||||
anchors.centerIn: parent
|
||||
anchors.verticalCenterOffset: root.theme.loopBackLift / 2 + root.slideY
|
||||
opacity: root.switchFade
|
||||
anchors.verticalCenterOffset: root.theme.loopBackLift / 2
|
||||
|
||||
Repeater {
|
||||
model: root.windows
|
||||
|
||||
WindowCard {
|
||||
id: card
|
||||
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
readonly property real angle: root.angleOf(card.index)
|
||||
readonly property real cosA: Math.cos(card.angle)
|
||||
// 0 at the front, 1 at the very back.
|
||||
readonly property real back: (1 - card.cosA) / 2
|
||||
// Simple perspective: cards farther away get smaller.
|
||||
readonly property real depthScale: root.theme.loopFocalLength / (root.theme.loopFocalLength + 2 * root.radius * card.back)
|
||||
// Turn so each card roughly lies along the loop, less so
|
||||
// at the sides, so they can still be seen.
|
||||
readonly property real faceAngle: root.faceTurn(card.angle)
|
||||
|
||||
theme: root.theme
|
||||
title: card.modelData.title
|
||||
app: card.modelData.app
|
||||
selected: card.index === root.selectedIndex
|
||||
current: card.modelData.focused === true
|
||||
shade: card.back
|
||||
live: root.expanded
|
||||
toplevel: root.compositor.toplevelFor(card.modelData.key)
|
||||
previewFile: card.modelData.preview
|
||||
previewVersion: root.compositor.previewVersion
|
||||
enabled: root.expanded
|
||||
|
||||
x: root.radius * Math.sin(card.angle) * card.depthScale - card.width / 2
|
||||
y: -root.theme.loopBackLift * card.back - card.height / 2
|
||||
z: card.cosA
|
||||
scale: card.depthScale
|
||||
opacity: 1 - (1 - root.theme.loopBackOpacity) * card.back
|
||||
|
||||
transform: Rotation {
|
||||
origin.x: card.width / 2
|
||||
origin.y: card.height / 2
|
||||
axis {
|
||||
x: 0
|
||||
y: 1
|
||||
z: 0
|
||||
}
|
||||
angle: card.faceAngle
|
||||
}
|
||||
|
||||
onActivated: root.activateAt(card.index)
|
||||
}
|
||||
// The old workspace, folding away.
|
||||
WindowRing {
|
||||
id: leavingRing
|
||||
y: root.leavingY
|
||||
z: 0
|
||||
opacity: root.leavingFade
|
||||
visible: leavingRing.opacity > 0
|
||||
enabled: false
|
||||
compositor: root.compositor
|
||||
theme: root.theme
|
||||
windows: root.leavingWindows
|
||||
maxRadius: root.width * root.theme.loopMaxRadiusShare
|
||||
turn: root.leavingTurn
|
||||
selectedIndex: root.leavingIndex
|
||||
live: root.expanded
|
||||
// Its previews are already out, so they should not grow again.
|
||||
growPreview: false
|
||||
gather: root.leavingGather
|
||||
}
|
||||
|
||||
// Under the front window. Cards stay below z 1.
|
||||
KeyHint {
|
||||
id: exitHintText
|
||||
x: root.theme.loopCardWidth / 2 - exitHintText.width
|
||||
y: root.theme.loopCardHeight / 2 + root.theme.hintGap
|
||||
z: 2
|
||||
WindowRing {
|
||||
id: ring
|
||||
y: root.slideY
|
||||
z: 1
|
||||
opacity: root.switchFade
|
||||
enabled: root.expanded
|
||||
compositor: root.compositor
|
||||
theme: root.theme
|
||||
hint: root.exitHint
|
||||
shown: root.count > 0
|
||||
windows: root.windows
|
||||
maxRadius: root.width * root.theme.loopMaxRadiusShare
|
||||
turn: root.turn
|
||||
selectedIndex: root.selectedIndex
|
||||
live: root.expanded
|
||||
growPreview: true
|
||||
gather: root.gather
|
||||
|
||||
onActivated: index => root.activateAt(index)
|
||||
}
|
||||
|
||||
// Under the front window, above both rings.
|
||||
Item {
|
||||
y: root.slideY
|
||||
z: 2
|
||||
opacity: root.switchFade
|
||||
|
||||
KeyHint {
|
||||
id: exitHintText
|
||||
x: root.theme.loopCardWidth / 2 - exitHintText.width
|
||||
y: root.theme.loopCardHeight / 2 + root.theme.hintGap
|
||||
theme: root.theme
|
||||
hint: root.exitHint
|
||||
shown: root.count > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import QtQuick
|
||||
|
||||
// One set of window cards on the loop. While Up/Down switch workspaces the
|
||||
// loop shows two of these: the old one folding away and the new one opening.
|
||||
// Zero sized, placed at the loop center.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property Compositor compositor
|
||||
required property Theme theme
|
||||
// Windows to show, from parsed JSON, so this stays untyped.
|
||||
required property var windows
|
||||
// Widest the loop may be on each side of its center.
|
||||
required property real maxRadius
|
||||
// Drives every card position. Not wrapped.
|
||||
required property real turn
|
||||
required property int selectedIndex
|
||||
// Stream the Hyprland previews.
|
||||
required property bool live
|
||||
// Previews grow out from the icon once they are ready.
|
||||
required property bool growPreview
|
||||
// 0 for the open loop, 1 with every card folded into one small box.
|
||||
required property real gather
|
||||
|
||||
// A card was clicked.
|
||||
signal activated(int index)
|
||||
|
||||
readonly property int count: root.windows.length
|
||||
// Angle between two neighbours on the loop.
|
||||
readonly property real angleStep: root.count > 0 ? 2 * Math.PI / root.count : 0
|
||||
// The loop is as long as the cards side by side, within limits.
|
||||
readonly property real radius: {
|
||||
const natural = root.count * (root.theme.loopCardWidth + root.theme.loopCardGap) / (2 * Math.PI);
|
||||
return Math.max(root.theme.loopMinRadius, Math.min(natural, root.maxRadius));
|
||||
}
|
||||
|
||||
// About how far the loop reaches sideways from its center, card edges
|
||||
// included. Sampled over the front half so it stays still while turning.
|
||||
readonly property real reachX: {
|
||||
const half = root.theme.loopCardWidth / 2;
|
||||
if (root.count <= 1)
|
||||
return half;
|
||||
const focal = root.theme.loopFocalLength;
|
||||
let widest = half;
|
||||
for (let i = 1; i <= 16; i++) {
|
||||
const angle = i / 16 * Math.PI / 2;
|
||||
const depthScale = focal / (focal + root.radius * (1 - Math.cos(angle)));
|
||||
const faceWidth = Math.abs(Math.cos(root.faceTurn(angle) * Math.PI / 180));
|
||||
const edge = (root.radius * Math.sin(angle) + half * faceWidth) * depthScale;
|
||||
widest = Math.max(widest, edge);
|
||||
}
|
||||
return widest;
|
||||
}
|
||||
|
||||
// Where round the loop, in degrees, cards turn edge-on. Halfway between
|
||||
// two cards, so none rests edge-on.
|
||||
readonly property real flipAngle: {
|
||||
if (root.count <= 1)
|
||||
return 90;
|
||||
const stepDegrees = 360 / root.count;
|
||||
const flip = (Math.floor(root.theme.loopFlipAngle / stepDegrees) + 0.5) * stepDegrees;
|
||||
return Math.min(flip, 180);
|
||||
}
|
||||
|
||||
// Angle of a card from the front, in radians, between -pi and pi.
|
||||
function angleOf(index: int): real {
|
||||
if (root.count === 0)
|
||||
return 0;
|
||||
let steps = (index - root.turn) % root.count;
|
||||
if (steps < 0)
|
||||
steps += root.count;
|
||||
if (steps > root.count / 2)
|
||||
steps -= root.count;
|
||||
return steps * root.angleStep;
|
||||
}
|
||||
|
||||
// How far a card at this angle (radians) turns, in degrees. It turns
|
||||
// from facing the viewer at the front to edge-on at flipAngle, then on
|
||||
// round to face the viewer again at the back, showing its inner face.
|
||||
function faceTurn(angle: real): real {
|
||||
const degrees = Math.abs(angle) * 180 / Math.PI;
|
||||
const side = angle < 0 ? -1 : 1;
|
||||
const flip = root.flipAngle;
|
||||
if (degrees <= flip || flip >= 180)
|
||||
return -side * 90 * degrees / flip;
|
||||
const turn = 90 + 90 * (degrees - flip) / (180 - flip);
|
||||
return -side * (turn - 180);
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: root.windows
|
||||
|
||||
WindowCard {
|
||||
id: card
|
||||
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
readonly property real angle: root.angleOf(card.index)
|
||||
readonly property real cosA: Math.cos(card.angle)
|
||||
// 0 at the front, 1 at the very back.
|
||||
readonly property real back: (1 - card.cosA) / 2
|
||||
// Simple perspective: cards farther away get smaller.
|
||||
readonly property real depthScale: root.theme.loopFocalLength / (root.theme.loopFocalLength + 2 * root.radius * card.back)
|
||||
// Turn so each card roughly lies along the loop, less so
|
||||
// at the sides, so they can still be seen.
|
||||
readonly property real faceAngle: root.faceTurn(card.angle)
|
||||
// 1 when open, 0 when folded into the box.
|
||||
readonly property real open: 1 - root.gather
|
||||
|
||||
theme: root.theme
|
||||
title: card.modelData.title
|
||||
app: card.modelData.app
|
||||
selected: card.index === root.selectedIndex
|
||||
current: card.modelData.focused === true
|
||||
shade: card.back
|
||||
live: root.live
|
||||
growPreview: root.growPreview
|
||||
toplevel: root.compositor.toplevelFor(card.modelData.key)
|
||||
previewFile: card.modelData.preview
|
||||
previewVersion: root.compositor.previewVersion
|
||||
|
||||
// Folding pulls every card into the middle, facing front.
|
||||
x: root.radius * card.open * Math.sin(card.angle) * card.depthScale - card.width / 2
|
||||
y: -root.theme.loopBackLift * card.back * card.open - card.height / 2
|
||||
z: card.cosA
|
||||
scale: card.depthScale + (root.theme.loopBoxScale - card.depthScale) * root.gather
|
||||
opacity: 1 - (1 - root.theme.loopBackOpacity) * card.back
|
||||
|
||||
transform: Rotation {
|
||||
origin.x: card.width / 2
|
||||
origin.y: card.height / 2
|
||||
axis {
|
||||
x: 0
|
||||
y: 1
|
||||
z: 0
|
||||
}
|
||||
angle: card.faceAngle * card.open
|
||||
}
|
||||
|
||||
onActivated: root.activated(card.index)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user