From c9a7698677c7d1c265187955379c0f619e7ff1aa Mon Sep 17 00:00:00 2001 From: Cauchy Underground Date: Sat, 6 Apr 2024 11:07:51 +0200 Subject: [PATCH 1/2] Add a scroll smooth step function --- lib/wibox/container/scroll.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/wibox/container/scroll.lua b/lib/wibox/container/scroll.lua index 85c706dc63..2bae93d304 100644 --- a/lib/wibox/container/scroll.lua +++ b/lib/wibox/container/scroll.lua @@ -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 + -- 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)) +end + return scroll -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 From a38e31674c0730eba69abbc2634a908811f98a39 Mon Sep 17 00:00:00 2001 From: Cauchy Underground Date: Mon, 8 Apr 2024 15:41:28 +0200 Subject: [PATCH 2/2] Change of magic number to 2 * math.pi --- lib/wibox/container/scroll.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wibox/container/scroll.lua b/lib/wibox/container/scroll.lua index 2bae93d304..87a295cf35 100644 --- a/lib/wibox/container/scroll.lua +++ b/lib/wibox/container/scroll.lua @@ -569,7 +569,7 @@ function scroll.step_functions.smooth_back_and_forth(elapsed, size, visible_size local state = ((elapsed * speed) % (size)) / size -- 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)) + return (size - visible_size) * (0.5 - 0.5*math.cos(state * 2 * math.pi)) end return scroll