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

[GUI] Budj - GUI API

Started by Dave-ee Jones, 15 September 2017 - 01:42 AM
Dave-ee Jones #1
Posted 15 September 2017 - 03:42 AM
Budj
Dave-ee's GUI API!

Look! Another GUI API!
Yep. As a not-so-wise-man once said: "anudder one". It's not quite as good as something like Touchpoint, but it's got some different features that might be useful to some.

I despise having to use someone else's GUI APIs, as I always prefer to write my own APIs. It's more interesting, better for the learning experience, and better for your own applications. So, I made Budj. Budj is a top-notch bloke. He can do all kinds of things.

He can have multiple whiteboards for you to slap buttons and checkboxes on, he can draw and undraw objects, he can swap whiteboards when he wants to change whats on the screen. He can do all kinds of cool things.He can even assign functions to objects, handle your events for you and re-align or re-assign labels.

Usage:
Spoiler

It's an API..you just..load it..

os.loadAPI("/budj")



Functions:
Spoiler

General functions:

error(string) -- Returns an error (overrides old 'error', but still uses it)
-- Returns nothing

handleEvent(...)
-- Handles mouse clicks and mouse ups
-- If mouse_click it replies "wait" if user clicked on an object, also returning the object as a second argument
-- If mouse_up on an object it runs the object's function, returning true, the object and the returned from the function as a table

Boards:

budj.BOARD:new(label)
-- Returns board as an object
budj.BOARD:toggleActive(boolean) -- Toggles the board active or not (doesn't need argument)
-- Returns nothing
budj.BOARD:draw() -- Draws all objects that the board has on it
-- Returns nothing
budj.BOARD:undraw() -- Undraws all objects that the board has on it
-- Returns nothing


Buttons:

budj.BUTTON:new(board,label,x,y,w,h,colour_text,colour_button_background,colour_button_background_clicked,button_filled)
-- returns button as an object
budj.BUTTON:draw() -- Draws the button
-- returns nothing
budj.BUTTON:undraw() -- Undraws the button
-- returns nothing
budj.BUTTON:toggleActive(boolean) -- Toggles button inactive or not (doesn't need argument)
-- returns nothing
budj.BUTTON:run() -- Runs the function that is linked to the button
-- returns the function's return
budj.BUTTON:alignLabel(alignment_type_x,alignment_type_y) -- Aligns the label (more doc. in API)
-- returns nothing
budj.BUTTON:assignLabel(label) -- Gives button a new label and automatically re-aligns it to how you had it before
-- returns nothing
budj.BUTTON:assignFunction(function) -- Gives the button a new function
-- returns nothing
budj.BUTTON:assignBoard(board)[/s] -- Assigns the button to another board (WIP atm, don't use)


Checkboxes:

budj.CHECKBOX:new(board,label,x,y,colour_text,colour_text_background,colour_checkbox_text,colour_checkbox_background,colour_checkbox_clicked)
-- returns checkbox as an object
budj.CHECKBOX:draw() -- Draws the checkbox
-- returns nothing
budj.CHECKBOX:undraw() -- Undraws the checkbox
-- returns nothing
budj.CHECKBOX:toggleActive() -- Toggles button inactive or not(doesn't need argument)
-- returns nothing
budj.CHECKBOX:toggleState() -- Toggles on/off
-- returns state (true/false)
budj.CHECKBOX:getState() -- Gets state of checkbox
-- returns state (true/false)
budj.CHECKBOX:run() -- Runs the function that is linked to the checkbox and toggles the state
-- returns the function's return and the state of the checkbox
budj.CHECKBOX:alignLabel(alignment_type_x) -- Aligns the label (more doc. in API)
-- returns nothing
budj.CHECKBOX:assignLabel(label) -- Gives checkbox a new label and automatically re-aligns it to how you had it before
-- returns nothing
budj.CHECKBOX:assignFunction(function) -- Gives the checkbox a new function (doesn't stop it from toggling)
-- returns nothing
budj.CHECKBOX:assignBoard(board)[/s] -- Assigns the checkbox to another board (WIP atm, don't use)



Demo program:
The demo program is pretty cool. Let me explain what it does.
When you click the button, it toggles the checkbox's 'DRAWN' variable. While it's undrawn you cannot interact with it.
When you click the button again, it toggles the checkbox to be drawn again.

When you toggle the checkbox it changes the button's label. You can actually swap the functions between the two objects, or even create more. I built the demo so it was very versatile and shows you what you can do.






Demo program's pastebin:

pastebin get Kte8gY84 demo



API's pastebin:

pastebin get ugKWxVGj budj



PLEASE give suggestions and feedback!
Edited on 17 September 2017 - 10:56 PM
Lupus590 #2
Posted 15 September 2017 - 10:30 AM
You functions section has a lot of noise from the formatting thing.
Edited on 15 September 2017 - 08:32 AM
Dave-ee Jones #3
Posted 18 September 2017 - 12:52 AM
You functions section has a lot of noise from the formatting thing.

Yeah, I don't know why that is :/
Bomb Bloke #4
Posted 18 September 2017 - 08:16 AM
The code tags used by the forum aren't really aimed at Lua. You'll get better results if you use –# to mark out your comments.
Smallfrypound #5
Posted 20 November 2017 - 07:10 PM
Suggestion(s):
* Add more features, like labels, input boxes, etc.

Other than that it looks like a promising api.