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

Button Grid API

Started by LeonTheMisfit, 26 July 2014 - 03:58 AM
LeonTheMisfit #1
Posted 26 July 2014 - 05:58 AM
Grid Button API v1.0.0


What is this?

This is an API with a single goal in mind. Easy and simple buttons to be used with advanced computers and monitors, while still allowing a good amount of customization.

Who is this for?

In a word, anyone. My hope is that beginners find it simple to use while advanced users find it time saving. If you have the need to create a GUI with buttons then you're in the right place.

What makes this different than the other button APIs?

There are definitely already some great button APIs out there. However, in my experience, the more functionality an API provides, the more difficult it becomes to use. I would like to think that the real difference is that my API provides an easy to use and understand interface without skimping on functionality. The major difference is how buttons are drawn and laid out on the screen. My API uses a customizable grid style layout to make creating and drawing buttons simple. Rather than providing exact X,Y screen coordinates and exact height and widths, you tell the API how many rows and columns you want the grid to have, where on the grid you want your buttons, and the grid takes care of the rest. Finally, the buttons are designed using object oriented style Lua, which only a handful of existing APIs that I've seen implement.

Why make the buttons object oriented?

I asked myself this question many times when debating whether or not to make this API. My first button API (for personal use) did not take this approach. At the end of the day when I looked at code that used the original API it was ugly. Now, there was more than one reason for this, but the main problem was the code didn't feel like I was working with buttons. In my mind, it was easier to think about each button as being it's own object rather than a set of parameters. So, I threw out my old API and started from scratch making this one.

Why isn't the grid object oriented as well?

This is a question that hasn't been asked yet but I suspect may come up if people begin to use the API. The answer to this one is simple. I created an unreleased version of the API that did use object oriented grids, so that a user could swap between screens. The problem was that it made the behind scenes code of the API far more complex without providing any additional benefit. The functions provided with the grid currently already allow you to easily switch "pages" and I will provide an example script that uses multiple pages of buttons.

Why did you write this?

I've made several GUI based programs in my games already and I was getting sick of copy-pasting boiler plate code from project to project. Thus my first button API was born which this grew out of. So, this definitely started as a personal use API, but sharing is caring. :P/>

Can I use this API with my program?

Sure. Feel free to use this API however you wish, just make sure if you release the application to the public with a copy of my API that I'm given credit. I'd also appreciate if you'd post a link to your program here so I can see the API in action. :D/>

Okay, enough rambling, on to the important stuff.

You can find the API on Pastebin.

To download it in ComputerCraft run the following
pastebin get UEeRD10S gridAPI

Here is a crappy YouTube video I made demonstrating one of the applications I wrote to test the API. Video making is not my strong suit, you've been warned.


Here is a link to the documentation. Currently it's just a list of accessible properties/variables and functions and a brief description of how they're used. I'm working on a more in depth version with better explanations, but hopefully this will suffice for now.



Samples

These samples don't represent all of the functions possible but do a good job of testing and doing simple demonstrations.

http://pastebin.com/aih8Q2dQ - This is the app I used to make the video. The video doesn't demonstrate the mouse wheel functionality that it implements.
http://pastebin.com/47RgQ5bQ - This app uses a monitor instead of drawing to the computer screen
http://pastebin.com/zxzhu11j - This app uses functions to draw multiple "pages"

BREAKING CHANGES

For anyone who downloaded the API prior to this edit/update, if you wish to update to the latest version you'll need to make some quick changes to your code. Anywhere that you used the original getMouseClick() or getScreenTouch() functions or their async counterparts you'll now need to use handleEvent() and handleEventAsync() respectively. Sorry for any inconvenience.

Finally, I am working on a tutorial for those who want one, but I'm a programmer not a writer so it's taking some time. I'll update as soon as it's done.
Edited on 02 August 2014 - 03:00 AM
LeonTheMisfit #2
Posted 01 August 2014 - 02:59 AM
I'm giving this a quick bump because I don't know if edited posts show up in the new content list and I just spent 2 hours rewriting and updating the post. Please don't murder me. xD
newcat #3
Posted 03 August 2014 - 07:28 PM
This is an awesome API! I currently have no project in which I can use that, but I am pretty sure that I will use it someday ;)/>
LeonTheMisfit #4
Posted 03 August 2014 - 07:32 PM
This is an awesome API! I currently have no project in which I can use that, but I am pretty sure that I will use it someday ;)/>

Thanks! If you use it and have any problems/suggestions let me know! :D/>

Edit:
I really need to learn to proofread posts BEFORE clicking the submit button.
Edited on 03 August 2014 - 05:35 PM