Files
dotfiles/quickshell/components/Marquee.qml
T
2026-08-10 23:57:26 +02:00

63 lines
1.9 KiB
QML

import QtQuick
import "root:/config"
// Horizontally scrolling text that only moves when it actually overflows, and
// pauses at each end so titles stay readable.
Item {
id: root
property string text: ""
property int pixelSize: Theme.fsSmall
property string family: Theme.fontDisplay
property int weight: Theme.weightBody
property bool italic: false
property color color: Theme.text
property real speed: 26 // px per second
property int pause: 1400 // ms held at each end
property bool running: true
readonly property bool overflowing: label.implicitWidth > width + 1
clip: true
implicitHeight: label.implicitHeight
implicitWidth: label.implicitWidth
Text {
id: label
y: 0
height: root.height
text: root.text
color: root.color
verticalAlignment: Text.AlignVCenter
font.family: root.family
font.pixelSize: root.pixelSize
font.weight: root.weight
font.italic: root.italic
renderType: Text.NativeRendering
}
SequentialAnimation {
id: scroll
running: root.running && root.overflowing && root.visible
loops: Animation.Infinite
PauseAnimation { duration: root.pause }
NumberAnimation {
target: label; property: "x"
from: 0; to: Math.min(0, root.width - label.implicitWidth)
duration: Math.max(1, Math.abs(root.width - label.implicitWidth) / root.speed * 1000)
easing.type: Easing.Linear
}
PauseAnimation { duration: root.pause }
NumberAnimation {
target: label; property: "x"
to: 0
duration: Theme.durSlow
easing.type: Easing.OutExpo
}
}
onOverflowingChanged: if (!overflowing) label.x = 0
onTextChanged: { label.x = 0; scroll.restart(); }
}