r/ComputerCraft • u/9551-eletronics Computercraft graphics research • May 08 '22
My new GUI api showcase
So hello, for the past like month i have been working on my newest project GuiH
its an somewhat quirky but working GUI api that you can use to build well.. guis
so first before explaining anything imma show some thing made with it


download: wget run https://github.com/9551-Dev/Gui-h/raw/main/installer.lua
ok i think thats way more then enough :D
so lets talk about the main features that the api provided
- inbuild multitasking
- texture on buttons/switches etc
- automatic updating and event handling
- .nimg image format support
- .ppm image format support (smaller then .nimg)
- provided sets of shape drawing functions
- few provided presets (like brick texture)
- debug logging and custom object support, you can create your own objects
you can also remove objects and api will work just fine
- object loading from optional folders and error handling
- 13 default objects, they can be removed or added as you wish
- uses object. you create a new object and then you can copy/cut/kill it however you want
- object "modding" support, you can provide objects with extra files to configure them (none provided by default, other then embedded replicate,cut,isolate,get_position)
- logic/graphic update ordering, being able to select update order of objects
- reccursive objects/guis being able to have a gui object in an gui object
The objects provided are
- button
- switch (an on/off button)
- ellipse (shape)
- frame (an object that can be moved around the screen by dragging)
- group (object that you can put other objects into to manage your GUI)
- inputbox (an box for inputting text, has autocompletion support)
- progressbar (an bar to show progress. atm it doesnt work very well but it does work ! even with textures)
- rectangle (shape)
- script (you can use this object to run custom code within the object updating process)
- scrollbox (changes its value if you scroll within an specified area)
- text (an object that you can give an gui.text object and it will display it in your gui)
- triangle (shape)
now i will make a better docs but the current ones are outdated. so if you really want to use this api and need help with something i reccomend you to dm me on discord
! 9551Dev#7942
but im going to show some usage here too. the api can do a lot and has a lot of functions and object inputs that you can use that you wont really find anywhere.
after you download the api you will get an new folder called GuiH. dont worry about the fact that its an folder you can require it just finelocal GuiH = require("GuiH")
this object will store some useful things but not your gui it self !
it stores theese values: presets,apis,load_texture (nimg),conver_event (not to worry about)
and mainly the create_gui function. this function takes in just 1 argument and that is your terminal object. this object can be either a window,monitor, or term.current()local gui = GuiH.create_gui(term.current())
once you have that done you have your new gui !, this table will contain all the data about your gui like
elements,general info,functions for object creation,scheduled tasks
what you mainly care about is the create table which allows you to create new objects
the usage is gui.create.<GuiH element type>(data <table>)
what the data table is its an table that will consist all of the info that you want on that object
each object has their unique data they need to be created but most of the values are optional
for example we want to create a 10x3 button at 5,6 that will have "reboot" on it and will reboot the computer when you click itgui.create.button({x=5,y=6,width=10,height=3,background_color=colors.green,text=gui.text{text="reboot",centered=true,transparent=true},on_click=function(object)os.reboot()end})
her we make the text be centered in the middle of the button and we make it transparent so it will be green, you can also provide the gui.text function with an offset_x and offset_y
you can also give it an blit table that consists of 2 strings with the blit data for the text
every object has a few mandatory tags that you can read/set
- visible (should object get drawn)
- reactive (should object react to events)
- logic_order/graphic_order/order (a number that sets the order in which updates happen, the higher number the later will update happen. so if object has graphic_order of math.huge it will always be on top)
- name (even if you dont set it. it gets asigned an random uuid4 tag)
to access and modify the button you can created you can just get what gui.create.button returns
or you can use the gui.gui table which consits all of the created elements sorted bygui.gui.<type>.<name>
by default objects get named with uuid4 but you can provide it with an name on creation. lets say we have a button called bob. how do we get it ? its simplegui.gui.button.bob
every object also has "manipulators" on it so you can do guielement.<thing>()
this thing can be replicate,cut,isolate,get_position but if you have something in the objects manipulators folder those will also get loaded !
but so far we have been just creating objects. and not doing anything this gui doesnt run !
well to run the gui you can do gui.execute()
this function will run the gui until it dies/errors and returns the error
you can also provide it with functions which aregui.execute(main loop function,on event,before draw,after draw)
note that once the main loop function stops so does the gui ! main loop function needs to loop or not be provided for the gui to run. you can also use it to stop the gui, have the main loop end when you want will cause the gui to stop
about loading textures you can do something like this, lets say we have an .ppm texture that we want to put on our previous button bob, thats already been createdgui.gui.button.bob.texture = gui.load_ppm_texture(filename.ppm)
note that texture is called just tex on creation !
if you happen to have an error that doesnt show up anywhere look into the GuiH/a-tools/log.log folder, everything that the api does and errors and stack trace get saved that for the current session
if your texture doesnt work please contact me to fix my shit :D, but from my testing all textures exported by gimp worked very well !

but lets say you want to just draw a texture and not od anything else. well then GuiH has an graphics api for your usage in code that you can require like thislocal graphic = require("GuiH.texture-wrapper").code
once you have that you can use the draw_box_tex function to draw your texturegraphic.draw_box_tex(terminal,texture,x,y,width,height,bg,fg) (bg and fg are optional)
this api has a lot more but this took me like half an hour to write and its almost midnight already !
i hope someone will find this api useful in some way or another. support/feedback in the comments apreciated !
here i will just send some example code you can try to see how the api works !
CC-lock by ascpyal wget run https://github.com/ascpial/cc-lock/raw/main/cc-lock/installer.lua
weird among us thing: https://pastebin.com/XrB5m9Eu
sus.ppm for that example: https://pastebin.com/9D9f5uk9
window program demo: https://github.com/9551-Dev/programs/blob/main/window.lua
seriously if you wanna use this but dont know how dm me im more then glad to help :D
new docs planned btw. ;P
1
u/AngusAU293 Apr 01 '25
I know this comment is 3 years newer than the post, but I'm interested to know of how does this compare to Basalt right now? I'm currently using Basalt and I just want to know the differences between these two libraries.
2
u/9551-eletronics Computercraft graphics research Apr 01 '25
tbh i have no idea ive never used basalt. i feel like basalt is probably gonna be the better choice overall since GuiH tends to be sorta verbose.
if you are interested in specifically image displaying then that capability has been insanely improved upon in a different library of mine
1
u/Advanced-Spite7171 Jan 09 '26
ehm help? i was trying to make a program for a starting up a gui but its the only way it works couldn't get it to work
1
u/9551-eletronics Computercraft graphics research Jan 09 '26
Sure i can if you really wanna use this, but you have to share more detail, ideally message me on discord
1
u/catboybinary Dec 26 '22
holy cow, i know im a bit late, but that's amazing! great job :D
2
u/9551-eletronics Computercraft graphics research Jan 11 '23
ye its kinda crappy now that i look at it with a more experienced eye :P I have got much more amazing stuff going on rn with C3D. Planning to rewrite this sometime this year tho
5
u/NyoriE01 May 09 '22
Hey, i also made an ui framework asap as i come home i will try yours, it looks very interesting. I will also check your code, if i am allowed to, because i am very curious how your solution for some problems i had to face is. Thanks for sharing!