From 4ecaaf1b500dab93a8e6b19f91c2956e80cc9acd Mon Sep 17 00:00:00 2001 From: Wally Hackenslacker Date: Sun, 12 Oct 2025 12:10:35 -0400 Subject: [PATCH] Added comments to the horizontal bar. --- src/ui/bar.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ui/bar.lua b/src/ui/bar.lua index c09b43e..310b133 100644 --- a/src/ui/bar.lua +++ b/src/ui/bar.lua @@ -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