Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /$$$$$$ /$$ by ThePH /$$ /$$ /$$ /$$ /$$ /$$$$$$
- /$$__ $$| $$ |__/| $$ | $$ | $$ | $$|_ $$_/
- | $$ \__/| $$ /$$$$$$ /$$ /$$ /$$| $$$$$$$ | $$ /$$$$$$ | $$ | $$ | $$
- | $$$$ | $$ /$$__ $$| $$ /$$/| $$| $$__ $$| $$ /$$__ $$| $$ | $$ | $$
- | $$_/ | $$| $$$$$$$$ \ $$$$/ | $$| $$ \ $$| $$| $$$$$$$$| $$ | $$ | $$
- | $$ | $$| $$_____/ >$$ $$ | $$| $$ | $$| $$| $$_____/| $$ | $$ | $$
- | $$ | $$| $$$$$$$ /$$/\ $$| $$| $$$$$$$/| $$| $$$$$$$| $$$$$$/ /$$$$$$
- |__/ |__/ \_______/|__/ \__/|__/|_______/ |__/ \_______/ \______/ |______/ v2
- N.B.: In this doc, my API is referred to as 'ui'
- Before using my API, you must firstly create UI class doing like so:
- myUI = ui.new()
- The new() constructor function takes in two optionnal arguments:
- TAGS : is a table containing the default tags of your UI class
- DISPLAY : is a table containing the default peripheral(s) of your UI class
- Default value of TAGS is {'all'} and DISPLAY is {term} for the terminal
- Next thing you might want to do is adding elements to your newly created UI.
- There are currently 5 types of elements that can be created:
- POINT : are used as marks, to make other elements relative to it easily
- LABEL : are used to display text
- BUTTON : are used to diplzy text, when clicked, return a value and run a function if set
- RADIO : are used for selection, only one can be selected in a container
- CHECKBOX : are used for selection, multiple can be selected in a container
- Here is how to declare a new element:
- Note: name is a UNIQUE indentifier
- For a mark :
- elementName = myUI:addPoint('name', x, y)
- For a label :
- elementName = myUI:addLabel('name', x, y, text)
- For a button :
- elementName = myUI:addButton('name', x, y, text)
- For a radio :
- elementName = myUI:addRadio('name', x, y, text)
- For a checkbox :
- elementName = myUI:addCheckbox('name', x, y, text)
- Common params and functions:
- NAME : the unique name you give your element, i recomment names like'stuff_mylabel' (cf. setCommonAttribute())
- X and Y : no need to explain
- TEXT : string or table; 'text' or {'text','right here'} will auto-adjust to look square
- TAG : used in draw() and mouse()
- DISPLAY : where the element is displayed
- CONT : elementName.cont = existing unique element name, will make X & Y relative
- COLORS : elementName.colors = {foreground, background} or elementName:setColors(foreground, background)
- myUI:del('name') : deletes an element
- myUI:setCommonAttribute({data to match}, {data to change}) : change elements" matching {data to match} (which uses regEx too), values in {data to change}
- eg: myUI:setCommonAttribute({name = 'stuff_'}, {text='the stuff here'})
- RET and EXE: (button, radio and checkboxes only) elementName:setAction(action) if action is a function, it will be run when clicked using params (elementItself, listContainingOtherElements) else, is what will be returned
- ENABLED and VISIBLE : boolean, is not enabled, won't display or be clicked, if not visible, won't display, but can be clicked
- VALUE : (radio and checkboxes) 1 or 0, selected or not, selection can be found with myUI:getRadio(CONT) = single element and myUI:getCheckbox(CONT) = list of element(s)
- myUI:draw(TAG) : draw the element that have the tags TAG (optionnal, if nil, will take default)
- myUI:mouse({x, y}, TAG, DISPLAY) return the list of clicked element in position x, y, with tags TAG and displayed on DISPLAY (TAG and DISPLAY optionnal, if nil, will use default)
Advertisement
Add Comment
Please, Sign In to add comment