From d2d5f8c3ae31395f7668dd5b23f7ecbcd61a731f Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Mon, 25 Aug 2025 14:14:49 +0200 Subject: [PATCH] Added marquee animation --- src/plugins/animation.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/plugins/animation.lua b/src/plugins/animation.lua index 105075b..3030d25 100644 --- a/src/plugins/animation.lua +++ b/src/plugins/animation.lua @@ -470,6 +470,35 @@ Animation.registerAnimation("scrollText", { end }) +Animation.registerAnimation("marquee", { + start = function(anim) + anim.width = anim.element.get("width") + anim.text = tostring(anim.args[2] or "") + anim.speed = tonumber(anim.args[3]) or 0.15 + anim.offset = 0 + anim.lastShift = -1 + anim.padded = anim.text .. string.rep(" ", anim.width) + end, + + update = function(anim, progress) + local elapsed = os.epoch("local") / 1000 - anim.startTime + local step = math.max(0.01, anim.speed) + local shifts = math.floor(elapsed / step) + if shifts ~= anim.lastShift then + anim.lastShift = shifts + local totalLen = #anim.padded + local idx = (shifts % totalLen) + 1 + local doubled = anim.padded .. anim.padded + local visible = doubled:sub(idx, idx + anim.width - 1) + anim.element.set(anim.args[1], visible) + end + return false + end, + + complete = function(anim) + end +}) + --- Adds additional methods for VisualElement when adding animation plugin --- @class VisualElement local VisualElement = {hooks={}}