Advertisement
TechTycho

animations/fade.lua

Dec 29th, 2022
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. local gears = require("gears")
  2. local animations = require("animations")
  3.  
  4. local timeout = gears.timer.start_new
  5.  
  6. local function hide(w)
  7.   w.visible = false
  8.   w.opacity = 0
  9. end
  10.  
  11. local function show(w)
  12.   w.visible = true
  13.   w.opacity = 1
  14. end
  15.  
  16. return function (widget, speed, delay)
  17.   if animations.busy then
  18.     for _, v in ipairs(animations.timers) do
  19.       v:stop()
  20.     end
  21.   end
  22.  
  23.   show(widget)
  24.  
  25.   table.insert(animations.timers, timeout(delay, function ()
  26.     animations.busy = true
  27.     local max = 50
  28.  
  29.     for f = 1, max do
  30.       table.insert(animations.timers, timeout((f / speed), function ()
  31.         f = f + 1
  32.         widget.opacity = widget.opacity - 0.02
  33.  
  34.         if f == max then
  35.           animations.busy = false
  36.           hide(widget)
  37.         end
  38.       end))
  39.     end
  40.   end))
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement