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

Open-Source GUI API! It has it all! BIG UPDATE!

Started by Parzivail, 04 April 2014 - 11:39 AM
Parzivail #1
Posted 04 April 2014 - 01:39 PM
Ever wanted to make buttons? How about some textboxes? Checkboxes? Labels? Maybe Progress Bars? We have it all!

OPEN SOURCE! EDIT THE CODE! USE IN YOUR PROGRAMS!*

SUGGEST IDEAS! I read all of my comments! If I use your idea, I will be sure to give credit!

Very simple to use!

*giving credit would be nice

Documentation:
SpoilerHow to use:
To add in program:

os.loadAPI("gui")

——————————————————————————————————————————————————–
Functions | Descriptions
Mouse:
gui.getMouse() | Takes args: none. Returns the mouse's click x and y.

Progress Bar:
gui.drawBar(pname) | Takes args: Progress Bar Array Name. Draws the bar.

Labels:
gui.drawLabel(bname) | Takes args: label array name. Draws the given label.
gui.drawAllLabels() | Takes args: none. Draws all labels.
gui.clickedLabel(bname,mousex,mousey) | Takes args: label array name, Mouse X, Mouse Y. Returns true if the specified label was clicked, else false.
gui.getClickedLabel(mousex,mousey) | Takes args: Mouse X, Mouse Y. Returns the label under the mouse's click coords.

Checkbox:
gui.drawCheck(cname) | Takes args: checkbox array name. Draws the given checkbox.
gui.updateChecks(x,y) | Takes args: Mouse X, Mouse Y. Toggles the state of the checkbox at the given coords.
gui.isChecked(cname) | Takes args: checkbox array name. Returns tue if it is checked, false if not.

Textbox:
gui.drawTextBox(tname) | Takes args: textbox array name. Draws the given textbox.
——————————————————————————————————————————————————–
Examples (element array creation)
Checkboxes:
check1 = {} -- initalize "Check1" (array name)
check1.checked = false -- default checked?
check1.yColor = colors.green -- checked color
check1.nColor = colors.red -- uncheced color
check1.x = 4
check1.y = 4

Textboxes:
box1 = {} -- initalize "box1" (array name)
box1.value = "" -- value, to get input later
box1.tColor = colors.black -- text color
box1.bColor = colors.white -- bg color
box1.w = 10 -- width
box1.x = 2
box1.y = 2

Progress Bars:
bar1 = {} -- initalize "bar1" (array name)
bar1.percent = 0 -- precent done
bar1.text = "" -- text to display next to the percent
bar1.pColor = colors.blue -- bar color
bar1.bColor = colors.white -- bg color
bar1.w = 10 -- width
bar1.x = 2
bar1.y = 2

Labels (bases for buttons):
label1 = {} -- initalize "label1" (array name)
label1.name = "my first label" -- "UUID" of the button (this returns if it is clicked and getClickedLabel() is called)
label1.text = "My First Label's Text" -- text to display
label1.tColor = colors.yellow -- text color
label1.bColor = colors.green -- bg color
label1.x=2
label1.y=3
label1.w=12 -- width
label1.h=1 -- height

PICTURES!!!!! (all showing they can be different colors)
SpoilerButtons:

Checkboxes: (same checkbox, one checked and one unchecked)

Textboxes:

Progress Bar:

Changelog:
Spoiler
  • v1.0 Released
  • v1.1 Added Progress Bars; Updated Docs
  • v1.1.1 Updated scripts (now don't flicker if called quickly), updated a typo in the documentation, added some more examples.
  • v1.1.2 Added the ability to add custom text next to the percentage on progress bars

Upcoming:
Spoiler
  • Array Element Groups, so you can have groups of GUI elements (like for menus or tabbed/windowed screens)
  • More options besides color
  • Button outlines?
  • Please! Suggest any ideas you have!

Download!

http://pastebin.com/hT62cqQv

ingame:
pastebin get hT62cqQv gui

Please leave your opinions and ideas!
Edited on 14 April 2014 - 11:36 AM
ByteZz #2
Posted 04 April 2014 - 02:39 PM
Can you please add some sort of documentation please?
Parzivail #3
Posted 06 April 2014 - 04:37 AM
Can you please add some sort of documentation please?

Yeah, im working on it, sorry I've been in exams for a bit now. Should get a doc and some screenshots tomorrow! :D/>
Edited on 06 April 2014 - 06:39 PM
pfgcomputercraft #4
Posted 22 April 2014 - 02:50 PM
Can you change the text in a checkbox when it's checked?
Agoldfish #5
Posted 22 April 2014 - 10:09 PM
It's not open-source until it has a Github Repo. :P/>
Parzivail #6
Posted 24 April 2014 - 01:04 PM
Can you change the text in a checkbox when it's checked?
Checkboxes don't have text :P/> but you could have a conditional and change the text of a label and redraw it
xxslasherrmx #7
Posted 01 January 2015 - 07:48 PM
Apologies on my lack of knowledge, I am still learning lua. For making a button, do I do something similar to this?

label1 = {} -- initalize "label1" (array name)
label1.name = "my first label" -- "UUID" of the button (this returns if it is clicked and getClickedLabel() is called)
label1.text = "My First Label's Text" -- text to display
label1.tColor = colors.yellow -- text color
label1.bColor = colors.green -- bg color
label1.x=2
label1.y=3
label1.w=12 -- width
label1.h=1 -- height
gui.drawLabel(label1)
gui.getClickedLabel(mousex,mousey)
gui.clickedLabel(Label1,mousex,mousey)
And if so, do I need to set an if statement?