LazyShpee

flexibleAPI v2 docs

Mar 28th, 2013
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. /$$$$$$ /$$ by ThePH /$$ /$$ /$$ /$$ /$$ /$$$$$$
  2. /$$__ $$| $$ |__/| $$ | $$ | $$ | $$|_ $$_/
  3. | $$ \__/| $$ /$$$$$$ /$$ /$$ /$$| $$$$$$$ | $$ /$$$$$$ | $$ | $$ | $$
  4. | $$$$ | $$ /$$__ $$| $$ /$$/| $$| $$__ $$| $$ /$$__ $$| $$ | $$ | $$
  5. | $$_/ | $$| $$$$$$$$ \ $$$$/ | $$| $$ \ $$| $$| $$$$$$$$| $$ | $$ | $$
  6. | $$ | $$| $$_____/ >$$ $$ | $$| $$ | $$| $$| $$_____/| $$ | $$ | $$
  7. | $$ | $$| $$$$$$$ /$$/\ $$| $$| $$$$$$$/| $$| $$$$$$$| $$$$$$/ /$$$$$$
  8. |__/ |__/ \_______/|__/ \__/|__/|_______/ |__/ \_______/ \______/ |______/ v2
  9.  
  10.  
  11. N.B.: In this doc, my API is referred to as 'ui'
  12. Before using my API, you must firstly create UI class doing like so:
  13.  
  14. myUI = ui.new()
  15.  
  16. The new() constructor function takes in two optionnal arguments:
  17.  
  18. TAGS : is a table containing the default tags of your UI class
  19. DISPLAY : is a table containing the default peripheral(s) of your UI class
  20.  
  21. Default value of TAGS is {'all'} and DISPLAY is {term} for the terminal
  22.  
  23. Next thing you might want to do is adding elements to your newly created UI.
  24. There are currently 5 types of elements that can be created:
  25.  
  26. POINT : are used as marks, to make other elements relative to it easily
  27. LABEL : are used to display text
  28. BUTTON : are used to diplzy text, when clicked, return a value and run a function if set
  29. RADIO : are used for selection, only one can be selected in a container
  30. CHECKBOX : are used for selection, multiple can be selected in a container
  31.  
  32. Here is how to declare a new element:
  33.  
  34. Note: name is a UNIQUE indentifier
  35.  
  36. For a mark :
  37. elementName = myUI:addPoint('name', x, y)
  38.  
  39. For a label :
  40. elementName = myUI:addLabel('name', x, y, text)
  41.  
  42. For a button :
  43. elementName = myUI:addButton('name', x, y, text)
  44.  
  45. For a radio :
  46. elementName = myUI:addRadio('name', x, y, text)
  47.  
  48. For a checkbox :
  49. elementName = myUI:addCheckbox('name', x, y, text)
  50.  
  51. Common params and functions:
  52.  
  53. NAME : the unique name you give your element, i recomment names like'stuff_mylabel' (cf. setCommonAttribute())
  54.  
  55. X and Y : no need to explain
  56.  
  57. TEXT : string or table; 'text' or {'text','right here'} will auto-adjust to look square
  58.  
  59. TAG : used in draw() and mouse()
  60.  
  61. DISPLAY : where the element is displayed
  62.  
  63. CONT : elementName.cont = existing unique element name, will make X & Y relative
  64.  
  65. COLORS : elementName.colors = {foreground, background} or elementName:setColors(foreground, background)
  66.  
  67. myUI:del('name') : deletes an element
  68.  
  69. myUI:setCommonAttribute({data to match}, {data to change}) : change elements" matching {data to match} (which uses regEx too), values in {data to change}
  70. eg: myUI:setCommonAttribute({name = 'stuff_'}, {text='the stuff here'})
  71.  
  72. 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
  73.  
  74. ENABLED and VISIBLE : boolean, is not enabled, won't display or be clicked, if not visible, won't display, but can be clicked
  75.  
  76. 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)
  77.  
  78. myUI:draw(TAG) : draw the element that have the tags TAG (optionnal, if nil, will take default)
  79.  
  80. 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