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

Text GUI API

Started by tuomas56, 18 February 2014 - 02:27 PM
tuomas56 #1
Posted 18 February 2014 - 03:27 PM
I have created an api that allows you to create interactive text-based guis.

to get it run

pastebin get 1XX41eZ2 textgui

I cannot explain it very well so I will put an example usage:


-- this loads the api from file (change this to where you saved it)
os.loadAPI('textgui')

--this is the function that we pass to the runGui command to execute button actions if they do not take us to another window
function buttonPressed(s)
  if s == "quit" then
	 -- this is the command to quit the gui
	 textgui.endGui()
  end
end

-- this is the table which tells the api how to display the guy
local mopt = {
  -- each window has a separate table with an id
  [0] = {
	-- each item in the window has an id and inside it's table it has the text which is displayed and the y position on the item
	[1] = { "Window 1",3},
	--  and item with a id of ~ fills the line with -
	["~"] = 5,
	-- when an item is clicked it will go to the window with the id of the id of the item unless the item's id is a string in which case
	-- it will be handled by the function at the top which is passed to textgui.runGui
	["quit"] = { "Quit",7}
  },

  -- this is another window that the Window 1 button goes to because the ids are the same
  [1] = {
  -- and this will take you back to the original window
  [0] = {"Back",2}
  },

}
textgui.runGui(mopt,buttonPressed)
Screenshots:

Edited on 03 June 2014 - 07:08 PM
joebodo #2
Posted 19 February 2014 - 07:32 AM

os.loadAPI('textgui')textgui.runGui({[0]={[1]={"W",3},["~"]=5,["q"]={"Q",7} },[1]={[0]={"B",2}},} ,function(s)if s=="q" then textgui.endGui() end end)

A multipage GUI all on 1 line
Edited on 19 February 2014 - 06:33 AM
tuomas56 #3
Posted 28 February 2014 - 05:48 PM

os.loadAPI('textgui')textgui.runGui({[0]={[1]={"W",3},["~"]=5,["q"]={"Q",7} },[1]={[0]={"B",2}},} ,function(s)if s=="q" then textgui.endGui() end end)

A multipage GUI all on 1 line

Cool! I never thought about using it like that…
RoD #4
Posted 30 March 2014 - 09:54 AM
Screenies? I would like to see how the GUI is and how does it look like before testing it myself.
tuomas56 #5
Posted 03 June 2014 - 09:10 PM
Screenies? I would like to see how the GUI is and how does it look like before testing it myself.
Added Screenshots