mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-02 03:28:28 -04:00
media: throttle frame rate of media-related animations
port 1.5 related #2869
This commit is contained in:
@@ -358,38 +358,50 @@ BasePill {
|
||||
onTextChanged: {
|
||||
scrollOffset = 0;
|
||||
textShift = 0;
|
||||
scrollTimer.reset();
|
||||
textChangeAnimation.restart();
|
||||
}
|
||||
|
||||
SequentialAnimation {
|
||||
id: scrollAnimation
|
||||
// Timer stepping, not NumberAnimation — a running animation commits frames every vsync (#2863)
|
||||
Timer {
|
||||
id: scrollTimer
|
||||
readonly property real maxOffset: Math.max(0, mediaText.implicitWidth - textContainer.width + 5)
|
||||
property int direction: 1
|
||||
property int holdTicks: 33
|
||||
|
||||
interval: 60
|
||||
repeat: true
|
||||
running: mediaText.needsScrolling && textContainer.visible && mediaText.onScreen && root._isPlaying
|
||||
loops: Animation.Infinite
|
||||
onStopped: mediaText.scrollOffset = 0
|
||||
|
||||
PauseAnimation {
|
||||
duration: 2000
|
||||
function reset() {
|
||||
mediaText.scrollOffset = 0;
|
||||
direction = 1;
|
||||
holdTicks = 33;
|
||||
}
|
||||
|
||||
NumberAnimation {
|
||||
target: mediaText
|
||||
property: "scrollOffset"
|
||||
from: 0
|
||||
to: mediaText.implicitWidth - textContainer.width + 5
|
||||
duration: Math.max(1000, (mediaText.implicitWidth - textContainer.width + 5) * 60)
|
||||
easing.type: Easing.Linear
|
||||
onRunningChanged: {
|
||||
if (!running)
|
||||
reset();
|
||||
}
|
||||
|
||||
PauseAnimation {
|
||||
duration: 2000
|
||||
}
|
||||
|
||||
NumberAnimation {
|
||||
target: mediaText
|
||||
property: "scrollOffset"
|
||||
to: 0
|
||||
duration: Math.max(1000, (mediaText.implicitWidth - textContainer.width + 5) * 60)
|
||||
easing.type: Easing.Linear
|
||||
onTriggered: {
|
||||
if (holdTicks > 0) {
|
||||
holdTicks--;
|
||||
return;
|
||||
}
|
||||
const next = mediaText.scrollOffset + direction;
|
||||
if (next >= maxOffset) {
|
||||
mediaText.scrollOffset = maxOffset;
|
||||
direction = -1;
|
||||
holdTicks = 33;
|
||||
return;
|
||||
}
|
||||
if (next <= 0) {
|
||||
mediaText.scrollOffset = 0;
|
||||
direction = 1;
|
||||
holdTicks = 33;
|
||||
return;
|
||||
}
|
||||
mediaText.scrollOffset = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user