Skip to content

Commit c9a7698

Browse files
Add a scroll smooth step function
1 parent 8b1f895 commit c9a7698

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/wibox/container/scroll.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,17 @@ function scroll.step_functions.waiting_nonlinear_back_and_forth(elapsed, size, v
561561
return (size - visible_size) * state
562562
end
563563

564+
--- A step function that scrolls the widget to its end and back to its
565+
-- beginning, then back to its end, etc. The speed is null at the ends and
566+
-- maximal in the middle. It’s smoothed by the use of a cosine function.
567+
-- @callback scroll.step_functions.smooth_back_and_forth
568+
function scroll.step_functions.smooth_back_and_forth(elapsed, size, visible_size, speed)
569+
local state = ((elapsed * speed) % (size)) / size
570+
-- The cosine function is scaled to map [0,1] to [0,2π] then it’s output is
571+
-- scaled from [1 -- -1 -- 1] to [0 -- 1 -- 0]
572+
return (size - visible_size) * (0.5 - 0.5*math.cos(state*6.2832))
573+
end
574+
564575
return scroll
565576

566577
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

0 commit comments

Comments
 (0)