fix: ensure that bar width can't be negative

This commit is contained in:
Kazhnuz 2019-08-15 14:06:20 +02:00
parent 8787eb99e6
commit b58f3d262a

View file

@ -41,12 +41,15 @@ function gui.newBorder(width, height, middlePosition)
end end
function gui.drawBar(x, y, width, height) function gui.drawBar(x, y, width, height)
if (width > 0) then
local height = height or 7 local height = height or 7
love.graphics.setScissor(x, y, width, height) love.graphics.setScissor(x, y, width, height)
love.graphics.draw(barborder, x, y) love.graphics.draw(barborder, x, y)
love.graphics.rectangle("fill", x+7, y, width-14, height) local barwidth = math.max(width-14, 0)
love.graphics.rectangle("fill", x+7, y, barwidth, height)
love.graphics.draw(barborder, x+width-7, y, 0, -1, -1, 7, 7) love.graphics.draw(barborder, x+width-7, y, 0, -1, -1, 7, 7)
love.graphics.setScissor( ) love.graphics.setScissor( )
end
end end
return gui return gui