Skip to content

Commit

Permalink
src/lua: simplify volume checks using math.min and math.max
Browse files Browse the repository at this point in the history
This is surprisingly a much simpler way of doing what I was doing. I
never knew one could do that.
Lua has some really interesting functions and I am really amazed by how
these small things simplify so many big things.

^.^ +1 for lua
  • Loading branch information
Daru-san committed Oct 31, 2024
1 parent 0437b43 commit b882217
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions lua/bar/audio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ return function()
return string.format("%.0f%%", v * 100)
end),
on_scroll = function(_, event)
if speaker.volume <= 1 and speaker.volume >= 0 then
if event.delta_y < -1 then
speaker.volume = speaker.volume + 0.05
elseif event.delta_y > -1 then
speaker.volume = speaker.volume - 0.05
end
elseif speaker.volume > 1 then
speaker.volume = 1
elseif speaker.volume < 0 then
speaker.volume = 0
if event.delta_y < -1 then
speaker.volume = math.min(speaker.volume + 0.05, 1)
elseif event.delta_y > -1 then
speaker.volume = math.max(speaker.volume - 0.05, 0)
end
end,
Widget.Box({
Expand Down

0 comments on commit b882217

Please sign in to comment.