Add a scroll smooth step function

This commit is contained in:
Cauchy Underground 2024-04-06 11:07:51 +02:00
parent 8b1f8958b4
commit c9a7698677
1 changed files with 11 additions and 0 deletions

View File

@ -561,6 +561,17 @@ function scroll.step_functions.waiting_nonlinear_back_and_forth(elapsed, size, v
return (size - visible_size) * state
end
--- A step function that scrolls the widget to its end and back to its
-- beginning, then back to its end, etc. The speed is null at the ends and
-- maximal in the middle. Its smoothed by the use of a cosine function.
-- @callback scroll.step_functions.smooth_back_and_forth
function scroll.step_functions.smooth_back_and_forth(elapsed, size, visible_size, speed)
local state = ((elapsed * speed) % (size)) / size
-- The cosine function is scaled to map [0,1] to [0,2π] then its output is
-- scaled from [1 -- -1 -- 1] to [0 -- 1 -- 0]
return (size - visible_size) * (0.5 - 0.5*math.cos(state*6.2832))
end
return scroll
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80