fst_api.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. Formspec toolkit api 0.0.3
  2. ==========================
  3. Formspec toolkit is a set of functions to create basic ui elements.
  4. File: fst/ui.lua
  5. ----------------
  6. ui.lua adds base ui interface to add additional components to.
  7. ui.add(component) -> returns name of added component
  8. ^ add component to ui
  9. ^ component: component to add
  10. ui.delete(component) -> true/false if a component was deleted or not
  11. ^ remove a component from ui
  12. ^ component: component to delete
  13. ui.set_default(name)
  14. ^ set component to show if not a single component is set visible
  15. ^ name: name of component to set as default
  16. ui.find_by_name(name) --> returns component or nil
  17. ^ find a component within ui
  18. ^ name: name of component to look for
  19. File: fst/tabview.lua
  20. ---------------------
  21. tabview_create(name, size, tabheaderpos) --> returns tabview component
  22. ^ create a new tabview component
  23. ^ name: name of tabview (has to be unique per ui)
  24. ^ size: size of tabview
  25. {
  26. x,
  27. y
  28. }
  29. ^ tabheaderpos: upper left position of tabheader (relative to upper left fs corner)
  30. {
  31. x,
  32. y
  33. }
  34. Class reference tabview:
  35. methods:
  36. - add_tab(tab)
  37. ^ add a tab to this tabview
  38. ^ tab:
  39. {
  40. name = "tabname", -- name of tab to create
  41. caption = "tab caption", -- text to show for tab header
  42. cbf_button_handler = function(tabview, fields, tabname, tabdata), -- callback for button events
  43. --TODO cbf_events = function(tabview, event, tabname), -- callback for events
  44. cbf_formspec = function(tabview, name, tabdata), -- get formspec
  45. tabsize =
  46. {
  47. x, -- x width
  48. y -- y height
  49. }, -- special size for this tab (only relevant if no parent for tabview set)
  50. on_change = function(type,old_tab,new_tab) -- called on tab chang, type is "ENTER" or "LEAVE"
  51. }
  52. - set_autosave_tab(value)
  53. ^ tell tabview to automaticaly save current tabname as "tabview_name"_LAST
  54. ^ value: true/false
  55. - set_tab(name)
  56. ^ set's tab to tab named "name", returns true/false on success
  57. ^ name: name of tab to set
  58. - set_global_event_handler(handler)
  59. ^ set a handler to be called prior calling tab specific event handler
  60. ^ handler: function(tabview,event) --> returns true to finish event processing false to continue
  61. - set_global_button_handler(handler)
  62. ^ set a handler to be called prior calling tab specific button handler
  63. ^ handler: function(tabview,fields) --> returns true to finish button processing false to continue
  64. - set_parent(parent)
  65. ^ set parent to attach tabview to. TV's with parent are hidden if their parent
  66. is hidden and they don't set their specified size.
  67. ^ parent: component to attach to
  68. - show()
  69. ^ show tabview
  70. - hide()
  71. ^ hide tabview
  72. - delete()
  73. ^ delete tabview
  74. - set_fixed_size(state)
  75. ^ true/false set to fixed size, variable size
  76. File: fst/dialog.lua
  77. ---------------------
  78. Only one dialog can be shown at a time. If a dialog is closed it's parent is
  79. gonna be activated and shown again.
  80. dialog_create(name, cbf_formspec, cbf_button_handler, cbf_events)
  81. ^ create a dialog component
  82. ^ name: name of component (unique per ui)
  83. ^ cbf_formspec: function to be called to get formspec
  84. function(dialogdata)
  85. ^ cbf_button_handler: function to handle buttons
  86. function(dialog, fields)
  87. ^ cbf_events: function to handle events
  88. function(dialog, event)
  89. Class reference dialog:
  90. methods:
  91. - set_parent(parent)
  92. ^ set parent to attach a dialog to
  93. ^ parent: component to attach to
  94. - show()
  95. ^ show dialog
  96. - hide()
  97. ^ hide dialog
  98. - delete()
  99. ^ delete dialog from ui
  100. members:
  101. - data
  102. ^ variable data attached to this dialog
  103. - parent
  104. ^ parent component to return to on exit
  105. File: fst/buttonbar.lua
  106. -----------------------
  107. buttonbar_create(name, cbf_buttonhandler, pos, orientation, size)
  108. ^ create a buttonbar
  109. ^ name: name of component (unique per ui)
  110. ^ cbf_buttonhandler: function to be called on button pressed
  111. function(buttonbar,buttonname,buttondata)
  112. ^ pos: position relative to upper left of current shown formspec
  113. {
  114. x,
  115. y
  116. }
  117. ^ orientation: "vertical" or "horizontal"
  118. ^ size: size of bar
  119. {
  120. width,
  121. height
  122. }
  123. Class reference buttonbar:
  124. methods:
  125. - add_button(btn_id, caption, button_image)
  126. - set_parent(parent)
  127. ^ set parent to attach a buttonbar to
  128. ^ parent: component to attach to
  129. - show()
  130. ^ show buttonbar
  131. - hide()
  132. ^ hide buttonbar
  133. - delete()
  134. ^ delete buttonbar from ui
  135. Developer doc:
  136. ==============
  137. Skeleton for any component:
  138. {
  139. name = "some id", -- unique id
  140. type = "toplevel", -- type of component
  141. -- toplevel: componant can be show without additional components
  142. -- addon: component is an addon to be shown along toplevel component
  143. hide = function(this) end, -- called to hide the component
  144. show = function(this) end, -- called to show the component
  145. delete = function(this) end, -- called to delete component from ui
  146. handle_buttons = function(this,fields) -- called upon button press
  147. handle_events = function(this,event) -- called upon event reception
  148. get_formspec = function(this) -- has to return formspec to be displayed
  149. }