Added comments to the horizontal bar.

This commit is contained in:
2025-10-12 12:10:35 -04:00
parent 4ad280a820
commit 4ecaaf1b50

View File

@@ -44,17 +44,25 @@ end
function Bar:draw()
local color = self.callback == nil and self.disbl_col or ((self.pressed and self.press_col) or ((self.selected and self.sel_color) or self.base_col))
-- Convert the variable's value to the [0, 1] space.
local v = (self.val_fn() + math.abs(self.min)) / (self.max + math.abs(self.min))
love.graphics.setColor(color.r, color.g, color.b)
-- Render the bar's outline.
love.graphics.rectangle('line', self.x, self.y, self.w, self.h)
-- Render the bar's content using the [0, 1] value as a proportion of the bar's width.
love.graphics.rectangle('fill', self.x, self.y, self.w * v, self.h)
love.graphics.setColor()
end
function Bar:_mouse2bar(x)
-- Take the x coord to the [0, 1] space, with clamping.
local v = math.max(math.min(((x - self.x) / self.w), 1.0), 0.0)
-- Convert the value to a horizontal bar coordinate and return it.
return (v * (self.max + math.abs(self.min))) - self.min
end