local graphics = require("graphics") local Text = require("graphics.text") Bar = {x = 1, y = 1, w = 8, h=1, title="Untitled Bar", bColor=0x00aaaa, fColor=0x000000, pct=0.0, value=0.0, unit=""} Bar.__index = Bar function Bar:new(x,y,w,h,title,bColor,fColor, pct, value, unit) local self = {} setmetatable(self, Bar) self.x = math.floor(x) self.y = math.floor(y) self.w = math.floor(w) self.h = math.floor(h) self.title = title self.bColor = bColor self.fColor = fColor self.pct = pct self.value = value self.unit = unit self._title_obj = Text:new(self.x, self.y, self.title, false ,0x000000, 0x00aaaa) return self end function Bar:setPct(pct) self.pct = math.max(math.min(1, pct), 0) end function Bar:draw() --[[ fColor is used for bar filled bColor is used as background for bar Black is used for text. ]] local gpu = graphics.gpu self._title_obj:draw() gpu.setForeground(0x000000) gpu.setBackground(self.bColor) gpu.setForeground(0xffffff) gpu.set(self.x,self.y," "..self.title.." ") gpu.fill(self.x,self.y+1,self.w,self.h," ") gpu.setBackground(self.fColor) gpu.fill(self.x,self.y+1,math.floor(self.x+self.w-1 * self.pct),self.h," ") end return Bar