Skip to content

Commit

Permalink
Add a scroll smooth step function
Browse files Browse the repository at this point in the history
  • Loading branch information
CauchyUnderground committed Apr 6, 2024
1 parent 8b1f895 commit c9a7698
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/wibox/container/scroll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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. It’s 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

Check warning on line 569 in lib/wibox/container/scroll.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/container/scroll.lua#L569

Added line #L569 was not covered by tests
-- The cosine function is scaled to map [0,1] to [0,2π] then it’s output is
-- scaled from [1 -- -1 -- 1] to [0 -- 1 -- 0]
return (size - visible_size) * (0.5 - 0.5*math.cos(state*6.2832))

Check warning on line 572 in lib/wibox/container/scroll.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/container/scroll.lua#L572

Added line #L572 was not covered by tests
end

return scroll

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

0 comments on commit c9a7698

Please sign in to comment.