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

KaoS' latest menu API

Started by KaoS, 01 September 2012 - 07:49 AM
KaoS #1
Posted 01 September 2012 - 09:49 AM
Hey all, KaoS here. I have developed a new menu generating api for those who grow tired of writing a new function every time they need a menu, you simply construct a table in the correct format of the choices and results and pass it to the generator with your preferences, there is a syntax comment and example of use in the pastebin, give it a try

http://pastebin.com/X9cC2MS3


FEATURES:
- automatic generation in a nested area of the screen
- scrolling if all choices do not fit
- able to call any function as a result of a choice (including shell api because I did not use loadstring)
- customised delimiters to show which choice is currently selected
- the generate function returns the output of the function called

REQUESTED FEATURES
- default full screen menu if co-ordinates are omitted
- catch choices longer than separator and lengthen separator to fix

If you would like me to add anything post here or preferably PM me

Pics
SpoilerThe code used:
Spoiler
--[DIMENSIONS]
local x1=1
local x2=30
local y1=1
local y2=4

--[GENERATE BORDER]
for y=y1,y2 do
if y==y1 or y==y2 then
term.setCursorPos(x1,y)
write('+')
for x=x1+1,x2-1 do
write('-')
end
write('+')
else
term.setCursorPos(x1,y)
write('|')
term.setCursorPos(x2,y)
write('|')
end
end

--[GENERATE MENU]
mymenu={{},{},{}}
mymenu[1][1]={'test01',{print,'first'}}
mymenu[1][2]={'test02',{print,'second'}}
mymenu[1][3]={'temper',{print,'temper1'}}
mymenu[1][4]={'temper2',{print,'temper2'}}
mymenu[2][1]={'test03',{print,'third'}}
mymenu[2][2]={'test04',{print,'fourth'}}
mymenu[3][1]={'test05',{print,'fifth'}}
mymenu[3][2]={'test06',{print,'sixth'}}

menu2.generate(mymenu,15,x1+1,y1+1,x2-1,y2-1,'*','*')

First Generated:
Spoiler

Scrolled Right:
Spoiler

Scrolled Down:
Spoiler

Pressed enter to select (code set to simply print choice number)
Spoiler

Please note that I edited the menu API to update the clearing function and stop the syntax display causing an issue
Edited on 13 September 2012 - 06:08 AM
Shazz #2
Posted 12 September 2012 - 02:45 AM
I suggest adding some screenshots on how the menu actually looks.
KaoS #3
Posted 12 September 2012 - 07:35 AM
Will do, thanks
KaoS #4
Posted 13 September 2012 - 08:09 AM
Pics added, API updated
anonimo182 #5
Posted 06 October 2012 - 03:04 AM
2 things: 1. You should make it so users can customize the "box"

2. Can I use it in my OS once you fix that? http://www.computercraft.info/forums2/index.php?/topic/4748-cc-143-windos-still-in-beta-which-needs-beta-testers-no-download/