Main Menu

Barebones Menu API

Started by ComputerCrafter, May 09, 2024, 01:48 PM

Previous topic - Next topic
I know there are many people much better than me at coding, but I decided to give it a shot.
I present: ComputerCrafter's Menu API also known as MenuAPI

Other APIs usually have a LOT of complicated features, but mine is very bare-bones, so don't expect much. :P
Here are all the functions and features:

-menu.indented: Selected items are indented+highlighted and the title has its own bar

-menu.notIndented: Selected items are not indented, but still highlighted. Title still has a bar

-menu.basic: Selected items not highlighted or indented, title has no bar and pointer is ">"

-menu.altPointers: Like notIndented() but with ">" as pointer, still highlights selected items

-menu.stallAny/menu.stallEnter: Press any key/enter to continue.

Functions in this API can be taken out and individually used in different files!

Screenshots:



Usage:
os.loadAPI("menu.lua")
choices = {"This is a test of the API", "This API is made by ComputerCrafter", "Fun Fact: This API is over 100 lines long!", "Please use this in your projects to support it! :D"}
title = "menu.indented()"
actions = {}
actions[1] = function()
    print("") --Your function
end
actions[2] = function()
    print("") --Your function
end
actions[3] = function()
    print("") --Your function
end
actions[4] = function()
    print("") --Your function
end
menu.indented(title, choices, actions)

Your choices and actions are in tables with arrays going from [1] up.
Choice table array corresponds to actions table (eg. choices[1] executes actions[1])
Title is always written starting from 1, 1. (Bar or no bar depends on function)
Press any key/enter note is always written at last line.

Pastebin codes are here:
-MenuAPI: dv2mwm3V
-Demo: bAg3mDUM

Please leave feedback!
This is my first 'real' project that's longer than 200 lines.
I hope you all enjoy it! :D

PS. If you need help using it reply in the comments, it may be a bug because of my bad code.

QuickMuffin8782

Your code is great, however a few indentations might be done so you can better understand the code and how it works.

Overall, this is a great starter for people who want to make their own menu systems! Great work!
"The Blue Blur" - Working on Net Star OS, a new frontier for Red Star OS 3.0
linktr.ee/quickmuffin8782