ComputerCraft Archive

ProgressBar

computer utility kepler155c github

Description

ComputerCraft OS

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/modules/opus/ui/components/ProgressBar.lua progressbar
Archive:wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-modules-opus-ui-components-progressbar progressbar
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-modules-opus-ui-components-progressbar ProgressBar

Usage

Run: ProgressBar

Tags

none

Source

View Original Source

Code Preview

local class = require('opus.class')
local UI    = require('opus.ui')

UI.ProgressBar = class(UI.Window)
UI.ProgressBar.defaults = {
	UIElement = 'ProgressBar',
	backgroundColor = 'gray',
	height = 1,
	progressColor = 'lime',
	progressChar = UI.extChars and '\153' or ' ',
	fillChar = ' ',
	fillColor = 'gray',
	textColor = 'green',
	value = 0,
}
function UI.ProgressBar:draw()
	local width = math.ceil(self.value / 100 * self.width)

	self:fillArea(width + 1, 1, self.width - width, self.height, self.fillChar, nil, self.fillColor)
	self:fillArea(1, 1, width, self.height, self.progressChar, self.progressColor)
end

function UI.ProgressBar.example()
	return UI.ProgressBar {
		x = 2, ex = -2, y = 2, height = 2,
		focus = function() end,
		enable = function(self)
			require('opus.event').onInterval(.25, function()
				self.value = self.value == 100 and 0 or self.value + 5
				self:draw()
				self:sync()
			end)
			return UI.ProgressBar.enable(self)
		end
	}
end