This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Canotsa's profile picture

Sliders - Easy Slider Creation

Started by Canotsa, 07 March 2017 - 10:26 PM
Canotsa #1
Posted 07 March 2017 - 11:26 PM


Sliders

Sliders is an API I wrote to help me keep track of all the liquid in my railcraft tanks through "Progress bars". But it is able to do so much more than that. Anything that you might be able to convert into percentages, you can put in a slider.
Functions
SpoilercreateSlider()
SpoilercreateSlider has 5 required arguments.
  • name: name of the Slider, can be any string
  • x: Starting point of the slider on the x-axis
  • y: Starting point of the slider on the y-axis
  • Length: Length of the slider.
  • Height: Height of the slider.
It also has 2 optional arguments.
  • sliderColor: Color of the actual slider (The parts that's getting filled up) default = colors.gray
  • barColor: Background color. (the whole thing) default = colors.white.
example of a slider:
sliders.createSlider("Slider_1", 2, 2, 49, 3, colors.lime, colors.red)
which creates a slider looking like this:


IMPORTANT: THIS FUNCTION DOESN'T ACTUALLY DRAW THE SLIDER!


updateSlider()
SpoilerupdateSlider() takes 2 arguments.
  • name: name of an existing slider
  • value: the percentage of the bar that should be filled up (has to be between 0 and 100)
example:


sliders.updateSlider("slider_1", 50)
Which updates the slider to 50%


IMPORTANT: THIS FUNCTION DOESN'T ACTUALLY DRAW THE SLIDER

setMonitor()
Spoiler

This function takes a side and wraps to the monitor at that side. This function is very important if you want to draw to a monitor.

example
sliders.setMonitor("right")



draw()
Spoiler

draw() draws the sliders. The function has 2 optional arguments.
  • name(s): can either be a single name of an existing slider or you can pass a table to it and it will draw all the sliders in that table.
  • drawText: boolean; true or false. set this to false if you don't want the % text in the middle of the slider.




Example Program:
Spoiler

os.loadAPI("sliders")

sliders.createSlider("slider_1", 2, 2, 49, 3, colors.lime, colors.red)

while true do
  for i = 0, 100 do
	sliders.updateSlider("slider_1", i)
	sliders.draw()
	sleep(0.1)
  end
end


Output:

Install

pastebin get V22szV0M sliders

From there on just load the api in your own script and use it :)/>
Feel free to post pictures of your usage or ways I could improve the API.
Cross_Sans #2
Posted 09 March 2017 - 05:37 PM
Interresting, but why did you called it Sliders and not Scrollbars ?
TheRockettek #3
Posted 09 March 2017 - 06:54 PM
Well, they aren't scroll bars, they are percentage bars :)/>
Twijn #4
Posted 10 March 2017 - 12:59 AM
Then why did he call them sliders if they're percentage bars. ;)/>
Edited on 10 March 2017 - 12:00 AM
Canotsa #5
Posted 10 March 2017 - 12:55 PM
Then why did he call them sliders if they're percentage bars. ;)/>

I thought Sliders sounded way better than Percentage Bars. I guess i got the idea from Unity3D engine where a slider can be used as a percentage bar.
I also didn't want to limit the use to just percentage display.